in reply to Re^2: Cont:match failing
in thread Cont:match failing

anyone has any clue ?

Replies are listed 'Best First'.
Re^4: Cont:match failing
by Anonymous Monk on Mar 22, 2011 at 08:03 UTC

    Finally,I think I know why ,am pushing $_\n to array,a new line,that is the reason it's not matching

    But I have one question,in the below code which ever is present first push or print is working,the second line is not coming into picture,is there a way I can push to array and print to a file at the same time?

    open(my $FOLDERS, '+>', "dirs.log") or die $!; find(sub { push @folders, "$_" if -d $File::Find::name && !$seen{$_}++; print $FOLDERS "$_\n" if -d $File::Find::name && !$seen{$_}++; }, $cwd);

      Just use the block form of if otherwise the %seen hash is being checked twice, and only the first statement would pass.

      find(sub { if (-d $File::Find::name && !$seen{$_}++) { push @folders, "$_" ; print $FOLDERS "$_\n"; } }, $cwd);