Michalis has asked for the wisdom of the Perl Monks concerning the following question:
Later, when I iterrate the @folderlist, I notice that all the count, new and unread values are set to zero (0) but the numbers are not correct... If, though, I skip the stage where I recursively call the sub in order to get the subfolders, it works like a charm (but I don't have the subfolder info which I need). I also tried modifying the sub as follows (only appropriate part provided):sub foldertree($$) { my ($imap,$fname) = @_; my $count=0; my $new=0; my $unread=0; my @folders=(); set_callback( list => sub { my @tmp = split ('}',$_[2]); push (@folders, $tmp[1]); }, status => sub { $count = $_[3]; $new = $_[5]; $unread = $_[7]; } ); $imap->list("{hostname:143/imap}$fname",'%'); my @topfolders = @folders; my @folderlist; foreach my $f (sort @topfolders) { $imap->status("{hostname:143/imap}$f", "messages","recent","unseen"); my %foldhash= ( 'name' => $f, 'count' => $count, 'new' => $new, 'unread' => $unread ); my @subfolders=&foldertree($imap,$f); my $fc=@subfolders; $foldhash{'fc'} = $fc; $foldhash{'subfolders'} = @subfolders; @folderlist = (@folderlist, \%foldhash); } return @folderlist; }
but it didn't make any difference. Any good ideas? I think something is wrong with the scope of the variables, but if that's the case, then why does the second example have problem as well? Thanks in advanceforeach my $f (sort @topfolders) { $imap->status("{hostname:143/imap}$f", "messages","recent","unseen"); my $new_count=$count; my $new_new=$new; my $new_unread=$unread; my %foldhash= ( 'name' => $f, 'count' => $new_count, 'new' => $new_new, 'unread' => $new_unread ); my @subfolders=&foldertree($imap,$f); my $fc=@subfolders; $foldhash{'fc'} = $fc; $foldhash{'subfolders'} = @subfolders;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subroutine variables problem
by dws (Chancellor) on Oct 15, 2002 at 08:50 UTC | |
by Michalis (Pilgrim) on Oct 15, 2002 at 09:33 UTC |