note
kyle
<p>I think the problem is that what you have still reads everything into <c>@subfolders</c>. Here's the snippet I'm talking about.
<c>
open(FFINFO,"$folderfolder_file") or die "Can't open $folderfolder_file: $!\n";
# This reads in every line from FFINFO
my @subfolders = <FFINFO>;
my %parents_of;
my $parentid;
# This loop also wants to read every line,
# but the handle is already at EOF,
# so it gets nothing.
while ( my $line = <FFINFO> ) {
</c>
<p>If you need <c>@subfolders</c> for some purpose outside the code we're talking about, you could still have it. Just declare <c>my @subfolders;</c> at the same scope as <c>$parentid</c> and <c>%parents_of</c>, without initializing it. Then, right inside the <c>FFINFO</c> read loop, [doc://push] every <c>$line</c> in. It winds up looking like this:
<c>
open(FFINFO,"$folderfolder_file") or die "Can't open $folderfolder_file: $!\n";
my @subfolders;
my %parents_of;
my $parentid;
while ( my $line = <FFINFO> ) {
push @subfolders, $line;
</c>
<p>You also had a question about this:
<c>
return @parents ? [ map {
map { "$_/$folderid" } @{ build_path( $_ ) }
} @parents ]
: [ $folderid ];
</c>
<p>What this means is, "if <c>@parents</c> is non-empty, return first expression (with nested maps), else return the second expression (<c>$folderid</c> alone in an array reference)." Your description leads me to believe that you have the precedence mixed up. What you describe is this:
<c>
( return @parents ) ? [ X ] : [ Y ];
</c>
<p>What's happening is this:
<c>
return ( @parents ? [ X ] : [ Y ] );
</c>
<p>You can see this kind of thing yourself using [mod://B::Deparse]. I ran this command line:
<c>
perl -MO=Deparse,-p input-file.pl
</c>
<p>With the <c>-p</c>, it puts parentheses in to clarify how expressions are interpreted. As a result, it showed me this (along with all the other code):
<c>
return((@parents ? [map({map({"$_/$folderid";} @{build_path($_);});} @parents)] : [$folderid]));
</c>
<p>That's not pretty, but it does show that the <c>return</c> is "outside" the whole rest of the line.
<p>I hope this helps. I feel I've written in some haste, so I wouldn't be surprised if I've been unclear. If I have left you with any other questions, feel free to ask.
809192
810040