my @plf_files = {"files.plf","orphans.plf"};creates a single element array containing a reference to a hash, because you used { } (called a 'composer'). You probably meant:
my @plf_files = ('files.plf','orphans.plf');
Your subroutine tests the same thing several times, try this:
sub recursion
{
my $plf = shift;
open my $fh, '<', $plf or die "could not open '$plf' $!";
foreach (my $line = <$fh>){
if($line =~ /(\w+\.plf)$/)
{
$match_plf_name = $1;
next if $match_plf_name eq $plf;
push @recursive_plfs ,$match_plf_name;
recursion($match_plf_name);
}
}
}
You will notice that I don't use $DATA for filehandle name. This is because there is a reserved filehandle called DATA, so $DATA would be confusing. You will also notice that there is not a
grep in sight. The capturing parentheses group is saved into $1.
Finally, notice also the 'next' statement as an insurance against infinite recursion.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.