Joseph Paish wrote:
> just a short followup to my earlier message about the $. line number
> variable.  when i enter a print statement as shown below, it prints
> the correct line number (starting at 1), but still never enters the
> if() structure.
> 
> for the sake of understanding how to correctly use this variable, i
> would really like to get this code working.  if i can't, then i will
> use one of the workarounds that others on this list have suggested to
> me. 
> 
> is there something special about the way the if() structure has to be
> phrased, other than the way i have it?
> 
> thanks
> 
> joe
> 
> 
> 
> > while (<fh1>) {
> >     chomp ;
> 
>        print $. ;  # prints correct line numbers starting at 1
>        print "\n" ;
>        print $_ ; # prints each line of input file, starting at 1
>        print "\n" ;
> 
> >     if ($. == 1 ) { # is this phrased correctly???
> >         my @initial_values = split / /, $_ ;
> >         # process intial values here
> >     }
> > 
> >     if ($. > 1) {
> >         #process subsequent values here
> >     }
> > 
> > } # end of while loop

I don't see any problem with the code as you've posted it. Here's a
self-contained example using the same tests you're using. Does this example
produce the same output for you as for me?

Script:

================CUT==================
#!/usr/bin/perl

while (<DATA>) {
    print "Line $. is $_";
    if ($. == 1) {
        print "First if() block entered\n";
    }
    if ($. > 1) {
        print "Second if() block entered\n";
    }
}

__DATA__
First
Second
Third
================CUT==================

Output:

Line 1 is First
First if() block entered
Line 2 is Second
Second if() block entered
Line 3 is Third
Second if() block entered

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


Reply via email to