From: ciwei <[EMAIL PROTECTED]>
> On Jan 10, 9:41 am, [EMAIL PROTECTED] (Chas. Owens) wrote:
> > > __DATA__
> > >              DEV01-HBA0_DMX1-13CA  <-- begin of record
> > >               WWN: 10000000C934A35B
> > >               WWN: 5006048ACAFE1E4C <-- end of record
> > >               EST01_HBA1_STK_TAPES1 <-- begin of record
> > >               WWN: 100000E002239270
> > >               WWN: 500104F000619193
> > >               WWN: 500104F00061918D
> > >               WWN: 500104F000619190
> > >               WWN: 500104F00061919D <-- end of record.
> >
> > snip
> >
> > my $record = <>; #prime the pump
>
> this suck in the whole input file into $record. a scaler.
> Is that what you really mean?  or how do you read in
> just the first line within  the file?

No. It reads the first line. At least if you do not change the $/
variable.

my @records = <>;

would read the whole file, split it into lines and put the lines into
the array. In Perl there is a concept called "context". Some
operators and functions behave differently if called in scalar, list
or void context.

> > while (my $line = <>) {
> >     if ($line =~ /^\s*WWN/) {
> >         $record .= $line;
>
> this append the $line to $record, which contain the whole file
> earlier ?
> what we want to achive here?
>
> >         next;
> >     }
>
> so we exit the loop unless if match WWN.

"next" doesn't exit the loop! It skips the rest of the loop's body
and starts a new iteration. In this case

   if ($line starts with some whitespace followed by "WWN") {
      append that $line to $record
      and go read the next line
   }

> and we start porceesing the record for lines that don't matched
> above?
>
> >     process_record($record);
> >     $record = $line; #start a new record}
>
> I didn't see how this start a record record, $line contain
> the

The records consist of one line that doesn't start with WWN followed
by several that do. What we need to do is to accumulate the whole
record before we process it, but we only know the record ended after
we read the first line of the next one. So every time we read a line
that does not start with WWN we process the previously accumulated
lines and start accumulating the next record.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to