On Tuesday 09 November 2004 08:41, Bob Showalter wrote:
> 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


unfortunately(?), yes, it does give me the same output.

BTW, i think i may have found out what is giving me the strange line numbers 
in the debugger under emacs.  it seems that when i enter "p $." at the 
debugger prompt, it displays whatever line number the debugger just printed 
out.  for example, if i have 17 debugger prompts before i issue the "p $." 
command, it will display 17 instead of the line number of the file i am 
reading at the time (which should be 1 if i just started reading the file).

ok, now this is getting strange.  i inserted some print statements in my 
large script, and they showed that in fact, i had been entering the first 
if() structure all along.  the debugger was showing me bypassing it and going 
straight to the second one.  maybe based on the bogus $. values that the 
debugger thought were accurate? (see previous paragraph)

anyway, except for the debugger not working properly under emacs, i guess 
there is no problem with the "if ($. == 1) structure .  unfortunately, i have 
grown to depend on the debugger to help me spot logic errors in my code.  i 
guess i am going to have to go back to simple print statements or run it from 
the commandline where i *just* found out that it gives me the correct output.

--------

i just ran the debugger under emacs against your script above and got the 
following output :

Line 2 is First
Second if() block entered
Line7 is Second
Second if() block entered
Line12 is Third
Second if() block entered

i didn't bother typing all the "DB<1> s" prompts that i used to single step 
my way through the code, but they do exist on the actual emacs screen.

---------------------

sorry for the length of this post, but i have been trying things out and 
describing the results as i get them.  maybe this will help someone else 
using the emacs/debugger combination and not getting the results that they 
know(?) they should get.

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