map evaluates the block in list context. Whatever the code inside the block returns in list context is what map will see.

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:

my @delete_list = map {s/^delete_check_//; $_} (grep /^delete_check_/, + keys %session);
Now the block returns $_ after doing the substitution, so it should map correctly.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.