Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Help using Find::File::name

by pobocks (Chaplain)
on Nov 28, 2010 at 07:39 UTC ( [id://874079]=note: print w/replies, xml ) Need Help??


in reply to Help using Find::File::name

It's almost certainly a scoping problem, as others have said.

Additionally, I'm not sure what you're trying to do in this Wanted. Even if you had proper scoping, you'd still be re-assigning the variable each time you went over it - in the end, you'd just have whatever the last value that matched the test.

Here's a try at something more reasonable:

my @foundfiles; sub Wanted { return unless (-f $_); # only operate on compiled widgets /\.wgt$/ or return; my $file = $_; chomp ($file); chomp ($line); #print $file ." \n" if $file eq $line; if (lc($line) eq lc($file)){ # Adds the files to the array push @foundFiles, $File::Find::name; } return; }

Alternately, you could keep foundfile as a scalar, and append to it thusly:

$foundfile .= "$File::Find::name\n";

Either way, the important thing is that your variable needs to be in a scope where it won't go away before you use it.

These are pretty common errors, and Perl can catch a lot of them. If you aren't already, start putting this code at the top of every Perl program you write:

use strict; use warnings;

This will catch a LOT of problems before they turn into headaches. For even more detail (at some performance cost, you can use diagnostics;

for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-18 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found