I appreciate the explanation.  It does exactly what I figured but the
explanation helps especially with the "magic" $_ variable.  This is
without a doubt the most readable perl code I have ever seen, but
remember I am not even a newbie when it comes to perl.

I also agree with Dave that the cryptic "clever" way of donng things at
the expense of readability is something to avoid.  Good comments in the
code help but hey, for the most part we are not working with machines
that have < 64K ram anymore.  Performance is obviously one issue that
needs to be considered.

I suspect that my primary problem with most of these scripts I don't
understand is due to my ignorance of the finer arts of regular
expressions.  BTW I don't expect you guys that do help by posting pearls
of perl to spend too much time explaining what something does but it
does steepen the learning curve for me because I don't often have the
time to dig out the book and figure out what something is doing even
though my curiousity my be tweeked.

That said,  Thanks again.

Bret


Bret

rpjday wrote:
> 
> 
> On Mon, 21 Feb 2000, Bret Hughes wrote:
> 
> > Got to something worng with this code.  Are you sure it's perl?  I mean,
> > I can understand it.  too easy.  I wrote a perl script to parse a bunch
> > of stuff from debug logs in a long running program about a year ago
> > (thanks to O'riley and this list) and when I went back a couple of weeks
> > ago I had no @&* idea what I had done.  Really powerful really cryptic.
> > Like I said earlier are you sure this is perl?
> >
> > :)
> > > ================
> > >
> > > open(IN, logfile) ;
> > >
> > > while(<IN>) {
> > >         foreach (split) {
> > >                 ($key, $value) = split("=") ;
> > >                 print "$key, $value\n" ;
> > >         }
> > > }
> > > close IN ;
> > >
> > > ================
> > >
> > >   once you get the values in $key and $value, do with them whatever
> > > you wish.
> 
> perhaps i wasn't solving the problem as it was asked, but what the above
> does is read a file of lines, each line of the format
> 
>         key=value  key=value ....
> 
> and an arbitrary number of those lines.  a running commentary:
> 
> while (<IN>) {
> 
>         read the next line into the magic variable $_, no need to chomp,
>         since we're going to deal with whitespace shortly anyway
> 
> foreach (split) {
> 
>         split the (default) magic variable $_, based on (default)
>         multiple whitespace (a great trick).  putting this into a
>         foreach loop places each "key=value" string into (tada!)
>         the (local to this foreach loop) $_ magic variable again.
> 
> ($key, $value) = split("=") ;
> 
>         split the "key=value" string in (default) $_ based on the
>         delimiter being an equal sign, place in scalar variables
>         $key and $value.  you can then print out these two values,
>         put them in a hash, whatever.
> 
> any questions?
> 
> rday
> 
> p.s.  yeah, it's perl. :-)
> 
> --
> To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
> as the Subject.
begin:vcard 
n:Hughes;Bret 
tel;fax:918.587.0131
tel;work:918.587.0131
x-mozilla-html:FALSE
url:www.elevating.com
org:Elevating Communications Inc
adr:;;PO Box 1323;Tulsa;OK;74101-1323;USA
version:2.1
email;internet:[EMAIL PROTECTED]
title:Chief Solutionist/President
x-mozilla-cpt:;19888
fn:Bret  Hughes
end:vcard

Reply via email to