On Tuesday 09 November 2004 10:20, Christopher Maujean wrote:
> On Tue, 2004-11-09 at 07:24, 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
>
> I ran the code you sent, with a couple of small debugging modifications
> (marked by #cpdm comments), and i can say that yes, it is entering the
> if structure just fine, why do you think its not?.
>
> code:
>
> use strict;
> use warnings;
>
> #cpdm changed <fh1> to <> (process file(s) named on command line)
>  while (<>) {
>      chomp ;
>
>        print $. ;  # prints correct line numbers starting at 1
>        #cpdm changed the \n to a space (so it numbers the lines)
>       print " " ;
>        print $_ ; # prints each line of input file, starting at 1
>        print "\n" ;
>
>      if ($. == 1 ) {   # is this phrased correctly???
>        #cpdm commented this out
>          #my @initial_values = split / /, $_ ;
>          # process initial values here
>
>       #cpdm this prints for me when I run the program
>       print "IN THE IF STATEMENT NOW\n";
>      }
>
>      if ($. > 1) {
>          #process subsequent values here
>      }
>
>  } # end of while loop

see my reply to Bob Showalter.  

i was depending on what the debugger under emacs was showing me  (bypassing 
the "if ($. == 1) " structure and going straight into "if($. > 1)" ), whereas 
in  fact that is not what was happening.  my code had been running correctly 
all along.

joe

-- 
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