[23424] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5641 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 10 00:05:56 2003

Date: Thu, 9 Oct 2003 21:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 9 Oct 2003     Volume: 10 Number: 5641

Today's topics:
    Re: CPAN seems to be broken on my system (James Willmore)
    Re: data manipulation <bNOoONb@not.pilbara.net.au>
    Re: Debug Messages <cwilbur@mithril.chromatico.net>
    Re: NEWBIE!  Please help! (Tad McClellan)
    Re: Opinions on "new SomeObject" vs. "SomeObject->new() <ict@eh.org>
    Re: Question about comparing Remote image with Local on <asu1@c-o-r-n-e-l-l.edu>
    Re: Search-replace in multiple files? <invalid-email@rochester.rr.com>
    Re: strip text up to a keyword? <mbudash@sonic.net>
    Re: strip text up to a keyword? (Tad McClellan)
    Re: trying to understand a hash - understanding has occ <michael.p.broida@boeing_oops.com>
    Re: trying to understand a hash - understanding has occ (Jay Tilton)
    Re: trying to understand a hash - understanding has occ (Tad McClellan)
    Re: trying to understand a hash <noreply@gunnar.cc>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 9 Oct 2003 16:35:34 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: CPAN seems to be broken on my system
Message-Id: <e0160815.0310091535.235ee950@posting.google.com>

"Christian Caron" <nospam@nospam.org> wrote in message news:<bm46fj$hl934@nrn2.NRCan.gc.ca>...
> "James Willmore" <jwillmore@remove.adelphia.net> wrote in message
> news:20031009132216.24800f58.jwillmore@remove.adelphia.net...
> > On Thu, 9 Oct 2003 09:44:40 -0400
> > "Christian Caron" <nospam@nospam.org> wrote:

<snip>
> Ok, I forgot to say "perl -MCPAN -eshell" is giving me the same results.
> Seems like CPAN is complaining about some misconfiguration and because of
> that, it asks to be configured again (everytime I invoke it). But when I do
> try to configure it, I get the question where I can't input an answer
> (continent). Chicken and egg. That's why I was wondering if there is a
> possibility to remove and reinstall CPAN from scratch.

1) Get the source from http://search.cpan.org
2) tar xzvvf <name of source file> (if you're using the GNU version of
tar)
3) perl Makefile.PL
4) make
5) make test
6) make install UNINST=1 (as root - and yes, UNINST=1)

This will overwrite the files from the previous version.  I'm thinking
this will also expunge the former configuration file and allow you to
create a new one.

HTH

Jim


------------------------------

Date: Fri, 10 Oct 2003 13:10:37 +0930
From: "Bob" <bNOoONb@not.pilbara.net.au>
Subject: Re: data manipulation
Message-Id: <bm59oi$cd0$1@mws-stat-syd.cdn.telstra.com.au>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bm3848$i2lpa$1@ID-184292.news.uni-berlin.de...
> Bob wrote:
> > I have a log file i want to further manipulate, and be able to
> > extract info from.
> >
> > (the actual output data is from qmail-qread command )
> >
> > the format of the file is as below
> >
> > 6 Oct 2003 14:01:12 GMT #23456 12345 <email@fake.com>
> > remote somone@fake.com
> >  done      someonelse@fake.com
> > 6 Oct .....
> >
> > the format is always date, line, followed by 1 or more info lines,
> > that are either \t or "  " indented.
> >
> > I want to grap each of these "chunks" and then run a regex and
> > output them when I get a match.
> >
> > So, using the data I have, I want to read in the (3 lines in this
> > case, but can 2 to ???? lines) and then output the whole block if I
> > match a regex.
> >
> > If anyone can recommend some place to start reading It would be
> > appreciated.
>
>      http://learn.perl.org/
>
> I'm quite sure that you were able to figure that out yourself, though,
> and that you actually wanted somebody to write some code, without
> having given it a try yourself first. :(  I'd be surprised if there
> weren't better ways, but this is one possible approach:
>
>      #!/usr/bin/perl
>      use strict;
>      use warnings;
>
>      my ($chunk, @chunks);
>      open FH, 'logfile' or die $!;
>      while (<FH>) {
>          if (/^\S/) {
>              push @chunks, $chunk if $chunk;
>              $chunk = '';
>          }
>          $chunk .= $_;
>      }
>      close FH;
>      push @chunks, $chunk;
>
>      # print chunks that include the domain fake.com
>      print grep { /\@fake\.com/ } @chunks;
>
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>

Thanks for the assistance, I was able to use most of what you offered with
what I already had.

I am new to Perl, and after reading, there are only 2 lines I don't clearly
understand

->              push @chunks, $chunk if $chunk;
->              $chunk = '';

After reading the push function description from "learning Perl" I am
failing to understand exactly what is happening here.


B




------------------------------

Date: Thu, 09 Oct 2003 22:15:05 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Debug Messages
Message-Id: <87oewqukmg.fsf@mithril.chromatico.net>

>>>>> "MrI" ==   <konny@waitrose.com> writes:

    MrI> But I think we (if you agree with me) are in the minority :)

Principally because it's not an especially useful thing to do.

    MrI> Oh b4 I forget. To the best of my knowledge Perl DOES NOT
    MrI> provide this functionality and I've yet to find a tool that
    MrI> does this (perl -d does not meet the requirement. great for
    MrI> me, not so great for non perl user).

What sense is a 'non perl user' going to make out of your proposed
tool that spits out something every time a variable is changed?

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


------------------------------

Date: Thu, 9 Oct 2003 19:23:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: NEWBIE!  Please help!
Message-Id: <slrnbobuvr.3i5.tadmc@magna.augustmail.com>

BDK <bdknoll@runbox.com> wrote:

> I couldn't wait for my original email to be posted,


This is not email (SMTP), this is Usenet (NNTP).


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 10 Oct 2003 11:35:11 +1000
From: Iain Truskett <ict@eh.org>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <slrnboc3na.mco.ict@dellah.org>

* Matija Papec <perl@my-header.org>:

[...]
> There is a difference between enforced standards and
> guidelines which you use willingly. Also, freedom is a
> great thing but first you have to //understand//
> implications of your programming decisions.

Perhaps you could draw up a list of guidelines, where for
every guideline you also have a counter-guideline or three.

Let people see what other people consider good practice and
pick and mix between them =)


cheers,
-- 
Iain.


------------------------------

Date: 10 Oct 2003 01:11:03 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Question about comparing Remote image with Local one
Message-Id: <Xns940FD77F929F1asu1cornelledu@132.236.56.8>

viijv@thedifferenZ.com (Vijoy Varghese) wrote in 
news:4c08aaff.0310082226.547ec7d6@posting.google.com:

> Hello Group,
> 
> My final goal is to show a green/red gif image on my webpage when I am
> available on yahoo chat. Yes for this I could have used the url
> provided by yahoo
> http://opi.yahoo.com/online?u=xxxx&m=g&t=2, where xxxx is my yahoo
> userid.

How about using the information on http://profiles.yahoo.com/user_id ?

There, your online status is indicated by an embedded image: online.gif or 
offline.gif depending on your status. The image's alt text is IM. So your 
script can just check the name of the image file to determine your online 
status. Just an idea.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


------------------------------

Date: Fri, 10 Oct 2003 00:04:58 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Search-replace in multiple files?
Message-Id: <3F85F5DA.10400@rochester.rr.com>

Roger Johansson wrote:

> ko <kuujinbo@hotmail.com> wrote:
> 
 ...
> I had some practical problems because a DOS Prompt window does not
> allow copy and paste from the windows clipboard, so I would have to


<offtopic>
Sure it does.  Right-click the DOS window's title bar and select edit, 
then paste.  To go the other way easily, modify the properties of the 
DOS window, checking the box "quick edit" on the "misc" tab.  Then 
highlight a rectangular region with your mouse and push the enter key. 
Some of that might be dependent upon what version of Windoze you have -- 
that stuff works for Windoze 98SE and NT 4 sp 6A at least; I don't know 
about the rest.

</offtopic>


> write everything manually in the DOS window.
> I had to change autoexec.bat to get my swedish keyboard to work in DOS
> windows.


-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



------------------------------

Date: Thu, 09 Oct 2003 22:50:13 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: strip text up to a keyword?
Message-Id: <mbudash-F38CCB.15501209102003@typhoon.sonic.net>

In article <b7675d5e.0310091252.14d92f05@posting.google.com>,
 anon002001@yahoo.com (kw) wrote:

> Is there a relatively simple way to strip/delete all text from a file,
> up to a keyword?  It has to work around linefeeds.  I have the webpage
> stored in a text variable.  Basically I want to remove a bunch of
> useless text, ads, scripts, etc from webpage html, and have the
> important text content as the result...
> 
> $webpage=get_webpage("http://news.yahoo.com/news?tmpl=index&cid=716");
> #done
> $webpage=strip_html($webpage); #done
> $webpage=strip_text_up_to("Top Stories",$webpage);

sub strip_text_up_to {
  my ($string, $webpage) = @_;
  $webpage =~ s/^.*$string//s; #
  return $webpage;
}

> $webpage=strip_text_after("Top Stories Section",$webpage);

sub strip_text_after {
  my ($string, $webpage) = @_;
  $webpage =~ s/$string.*$//s;
  return $webpage;
}

in order to understand this, type at the command line:

perldoc perlre

there you'll see that, in both cases, .* matches as much as possible 
("greedy"), while .*? will match as little as possible ("non-greedy"). 
make your choice for your particular needs.

note also that, in your specific case, there is no way for the script to 
know _which_ occurance of 'Top Stories' it's supposed to stop at, and 
there are several, including the one in 'Top Stories Section' !! so my 
example may not help you much. though if you reverse the two subroutine 
calls, the resulr smay be closer to desired...

you might wanna read up on 'lookahead' and 'negative lookahead' in the 
docs ref above. could help you.

> -note, my perl skills are pretty limited so a more simplistic approach
> would help me
> -note, I've searched and can't find anything to do this, if it exists
> already please point me to it

welcome to perl regular expressions!

-- 
Michael Budash


------------------------------

Date: Thu, 9 Oct 2003 19:22:22 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: strip text up to a keyword?
Message-Id: <slrnbobutu.3i5.tadmc@magna.augustmail.com>

kw <anon002001@yahoo.com> wrote:

> Is there a relatively simple way to strip/delete all text from a file,
> up to a keyword? 


No. There is a relatively simple way to strip/delete all text from a 
string, up to a keyword though.

You did not say what to do when the keyword occurs more than once...


   $string =~ s/.*keyword//s;    # up to last keyword

   $string =~ s/.*?keyword//s;   # up to first keyword


> $webpage=get_webpage("http://news.yahoo.com/news?tmpl=index&cid=716");


How is get_webpage() different from LWP::Simple::get() ?


> $webpage=strip_html($webpage); #done


I'd be willing to bet a dollar that strip_html() has bugs in it.

If you show it to us, we can show you some of its bugs.

In the meantime, you can try it with data like is shown for
the corresponding Frequently Asked Question:

   How do I remove HTML from a string?


> $webpage=strip_text_up_to("Top Stories",$webpage);


You can write strip_text_up_to() so that it will modify its
argument, then you wouldn't need to assign it back to itself:

   strip_text_up_to("Top Stories",$webpage);

   sub strip_text_up_to {              # untested
      my $keyword = quotemeta shift;
      $_[0] =~ s/.*$keyword//s;    # up to last keyword
   }


> -note, my perl skills are pretty limited so a more simplistic approach
> would help me


Processing HTML is not simple, that is the nature of that beast.

Consider doing simple tasks before moving on to complex tasks.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 9 Oct 2003 22:04:32 GMT
From: "Michael P. Broida" <michael.p.broida@boeing_oops.com>
Subject: Re: trying to understand a hash - understanding has occured
Message-Id: <3F85DB70.BD96FF5C@boeing_oops.com>

John wrote:
> So ... to summarize, the structure
> 
>         %hashname{$key}{$other} = value;
> 
> represents a 'hash of hashes' where the hash defined as
> "%hashname{$key}" dereferences to another hashname which is then
> referenced by key "$other" to get (or set) the value "value".

	Hmm.   I missed the original post, but I don't think that:
		%hashname{$key}
	is valid anywhere.  I've been doing a LOT of hash-of-
	hash-of-hash-of-hash-of-hash-etc stuff these past few
	months, and in NO case did it work with a leading
	percent-sign.  Perhaps there's some case where the
	above syntax works, but I haven't seen it yet.

	However,
			$hashname{$key}
	is valid.  And:
			$hashname{$key}{$other} = value;
	can work as "hash of hashes".  In both cases, the
	declaration of the hash is:
			%hashname

	My point is that the "%" is used to declare the hash
	or when referring to the -entire- hash.  To look at any
	part of the hash, you have to use the "$" and a key
	in curlies.

		Mike


------------------------------

Date: Thu, 09 Oct 2003 22:13:28 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: trying to understand a hash - understanding has occured
Message-Id: <3f85d9a8.81267675@news.erols.com>

jguad98@hotmail.com (John) wrote:

: tadmc@augustmail.com (Tad McClellan) wrote in message 
: news:<slrnbo73cg.k9o.tadmc@magna.augustmail.com>...
: 
: > > or
: > > 	%hashname(key => value);
: > > or
: > > 	%hashname("key","value");
: > > but not
: > > 	%hashname{$key}{$other} = value;
: > 
: > None of those are Perl (5).
: 
: What do you mean? The first two structures above are shown in my perl
: book

If the syntax errors are not simple transcription typos, then you have a
truly abysmal book.  Please share its title with us so it may be placed
on the "trees killed for no reason" list.

The first two are hopeless.  They resemble subroutine calls more than
they resemble any kind of hash usage.

The only one of those that comes close to being syntactically correct is
the third--replace the '%' sigil with a '$'.

: I seem to recall being told that the "=>" (arrow)
: sign within a hash structure was a perl v5 feature not found in
: previous versions.

The use of the "fat comma" arrow in the example above is not any kind of
mistake.

: So ... to summarize, the structure 
: 
:  	%hashname{$key}{$other} = value;
: 
: represents a 'hash of hashes' where the hash defined as
: "%hashname{$key}" dereferences to another hashname which is then
: referenced by key "$other" to get (or set) the value "value".

Wrong sigils again.  Change all those '%' to '$' .

Be cautious of thinking "dereferences to another hashname."  That path
can lead to using symbolic references.  See perlfaq7, "How can I use a
variable as a variable name?"

A hash does not need to have a name.  The point of having a reference
(hash or otherwise) is that you don't care what its name is, or if it
has one at all.

: It makes sense now that I look at it in that light, but my initial
: confusion was probably caused a bit by not understanding the the order
: of operation ... to use the HoH as above, the hash has to dereference
: from left to right (first complete legal term dereferences before any
: further terms are analyzed?) whereas I'm used to reading these things
: from right to left

You might appreciate the dereferencing arrow operator.

    $hashname{$key}->{$other} = 'value';

The arrow can be eliminated in that example without affecting anything,
but it nicely emphasizes that $hashname{$key} is a reference while
pointing your eyeballs in the right...er...the correct direction.

: Holy
: cr@p, batman!  Now all of a sudden all kinds of funky hashes I've seen
: are starting to make sense!!!!! Whoa ... my head is spinning ...

Far out.  Isn't it nice when code stops looking like Greek?
(Or Hebrew, considering your peculiar reading style. :)



------------------------------

Date: Thu, 9 Oct 2003 19:07:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: trying to understand a hash - understanding has occured
Message-Id: <slrnbobu2l.3i5.tadmc@magna.augustmail.com>

I myself <tadmc@augustmail.com> wrote:


> The "fat comma" ( => ) has nothing to do with a hash structure,
> it just happens that that is where most people choose to use it.

> It is just another way of writing a comma (with a little extra
> treatment for the left-hand operand).
> 
>    print 'hi' ,  ' ' ,  'there';
> 
>    print 'hi' => ' ' => 'there';
> 
>    print  hi  => ' ' =>  there;
> 
> all make the same output.


Errr, _maybe_ that last one makes the same output. It depends
on whether a there() function has been defined at this point
in the code.

I should have quoted the fat comma's right operand:

   print  hi  => ' ' =>  'there';


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 10 Oct 2003 00:08:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: trying to understand a hash
Message-Id: <bm4mcq$ieuuh$1@ID-184292.news.uni-berlin.de>

Tad McClellan wrote:
> A hash used in a scalar context is not useful to a Perl
> programmer, it is only useful to a perl programmer.
> 
> (it returns 2 numbers with a slash between, try it:
> 
>    print scalar(%hashname);
> )

To me it may be useful to check whether the hash is empty:

     if (%hash) {
         do this;
     } else {
         do that;
     }

And I can assure you that I'm not a perl programmer. :)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5641
***************************************


home help back first fref pref prev next nref lref last post