in reply to Passing value outside of loop

You're declaring the variable within the lexical scope of the while block, so it goes out of scope by the time you reach the conditional.

Try this instead:

my $found; while ( my $file = readdir(DIR) ){ $found = $file, last if $file=~/^myname\.doc$/i; } closedir(DIR); print "Found: $found" if $found;

Replies are listed 'Best First'.
Re: Re: Passing value outside of loop
by Anonymous Monk on Jan 07, 2003 at 17:52 UTC
    Thank you to all.