in reply to the variable is lost

So what output did you get?

It might help to verify the return value of open, as in, "open $fh, '<', $_ or die $!;" so you'll know if the open is failing.


Dave

Replies are listed 'Best First'.
Re^2: the variable is lost
by cruise (Acolyte) on Mar 09, 2012 at 08:19 UTC
    when i run code i get two warning
    Use of uninitialized value $a in print at D:\test.pl line 38.
    Use of uninitialized value $b in print at D:\test.pl line 38.

      I only see 19 lines of code. Which line is #38?

      Update: Thanks for clarifying your code now.

      Your while loop is reading <$fh> into $_, which is clobbering your foreach loop's version of $_. Since the topic variable in a foreach loop aliases the elements you're iterating over (ie, $a and $b), clobbering $_ clobbers $a and $b.

      Use an explicitly named topic variable for your foreach loop.


      Dave

        thanks for your help~~~~
        i have already know what's wrong with me
        i have update my full code ^_^
        it is only comment