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";

In reply to Re: Help using Find::File::name by pobocks
in thread Help using Find::File::name by mikelupo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.