dark314 has asked for the wisdom of the Perl Monks concerning the following question:
and here is the foreach that does what I want, I want to do a map instead of this foreach.$MAIL_ROOT = '/var/mail'; my @users = (map s/$MAIL_ROOT// , `find $MAIL_ROOT -type d -maxdepth +1`);
is there some reason map is not working correctly?my @users = `find $MAIL_ROOT -type d -maxdepth 1`; foreach (@users) { chomp; s/$MAIL_ROOT//; print $_ . "\n" unless $_ eq ''; }
Ah, I see, I was assigning the value to s/// and mapping incorrectly: correct way:from jwkrahn is prob the least effort for a fix and the one i went with :)chomp( my @users = map { s/$MAIL_ROOT//; $_ } `find $MAIL_ROOT -type d + -maxdepth 1` );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using map to replace text without using a foreach....
by ikegami (Patriarch) on Aug 17, 2006 at 19:57 UTC | |
|
Re: using map to replace text without using a foreach....
by jwkrahn (Abbot) on Aug 17, 2006 at 20:25 UTC |