Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: the variable is lost

by cruise (Acolyte)
on Mar 09, 2012 at 08:19 UTC ( [id://958646]=note: print w/replies, xml ) Need Help??


in reply to Re: the variable is lost
in thread the variable is lost

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.

Replies are listed 'Best First'.
Re^3: the variable is lost
by davido (Cardinal) on Mar 09, 2012 at 08:21 UTC

    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

        See my update above, and implement the advice by applying the following change:

        foreach my $filename ( $a, $b ) { open my $fh, '<', $filename or die $!;

        Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://958646]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found