On Jul 1, 2014, at 1:26 AM, Uday Vernekar <vernekaru...@gmail.com> wrote:

> The script works fine without 
> next if $line =~ /^-/;
> 
> How it helps.

It skips the line containing all dashes which separate the data lines. The 
script works without it because that line will fail the next test: ‘next unless 
scalar @f == 8’. However, checking the line for a single dash character at the 
beginning will be faster than trying to split the line with a regular 
expression and testing the number of fields that result. If you are only 
looking at a small number of lines, it probably doesn’t matter. In a large 
number of larger files, it might.

In general, when trying to parse complex files, it is best to identify and 
eliminate unwanted lines before trying to extract data from those that are 
relevant. Not doing so can lead to unwanted errors or program crashes in the 
future.


> On Mon, Jun 30, 2014 at 9:06 PM, Jim Gibson <jimsgib...@gmail.com> wrote:
> 
> On Jun 30, 2014, at 2:44 AM, Uday Vernekar <vernekaru...@gmail.com> wrote:
> 
> > please Explain
> >
> > next if $line =~ /^-/;
> 
> “Skip this input line if it starts with a dash ‘-‘ character.”
> 
> >   my @f = split('\s*\|\s*',$line);
> 
> "Break the input line into files separated by the vertical pipe character ‘|’ 
> and any whitespace before or after the pipe character, i.e., don’t include 
> the whitespace in the extracted fields."
> 
> >   next unless scalar @f == 8;
> 
> “Skip this input line unless it consists of exactly 8 fields.”


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to