At 1:06 PM +0200 5/26/10, HACKER Nora wrote:
Hi,
I am having troubles with a variable that should not be defined but
seems to be somehow. In the following code, the variable $localdir is
declared, then I am doing a find, and in case I get a result the
returned path is assigned as a value to $localdir. But somehow the
latter IF results to TRUE (=$localdir is defined) although the find does
not return a path (which is ok for my current test). Please could tell
me what I do not understand? I thought this was the proper way to check
whether a variable has a value or not (or at least my Perl book says
so)!?
*** snip ***
my $localdir;
if (defined $localdir) { print "defined 1: $localdir\n"; } #
undefined = ok for this test
my $find = File::Finder->type('d')->name("$sdir")->print;
$localdir = find ( $find, "$dbpath/dumps");
if (defined $localdir) { print "defined 2: $localdir\n"; } #
DEFINED although no directory :-(
Please consult the documentation for the File::Finder module
('perldoc File::Finder'). Nowhere there does it mention what the find
function returns. You should not be depending upon anything returned
from a function if that return value is not documented.
The purpose of the File::Finder class is to generate 'wanted'
functions for the File::Find class. Please refer to 'perldoc
File::Find'.
If you want a list of files that match your criteria, then please
refer to the description of the 'in' method of File::Finder.
I have not used this module, so I can't give you any examples of what
you seem to want.
--
Jim Gibson
jimsgib...@gmail.com
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/