The substititution operator s/// returns the number of substitutions made (in this case 1). So map will get a list of 1s. You could still use the substitution operator if you can force the code inside the block to return the string you want, like this:
Now the block returns $_ after doing the substitution, so it should map correctly.my @delete_list = map {s/^delete_check_//; $_} (grep /^delete_check_/, + keys %session);
When you use the match operator m// in list context without the /g modifier and with capturing parentheses, it returns a list of the matches. That's why your second example works, because in list context the code block returns the text you're looking for. Here's another simple example of m// returning a list of matches in list context:
my $str = "Helloooo, nurse!" my ($greeting, $recipient) = $str =~ m/^(\w+),\s+(\w+)/; print "Greeting: '$greeting', Recipient: '$recipient'\n";
In reply to Re: How to express myself
by thelenm
in thread help with s/// inside map
by blackjudas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |