Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Using for instead of map:

use strict; use warnings; use Data::Dumper; my @a = ("M94202", "M94150", "M94297", "M94150", "M94161", "M94161", " +M94162"); my ( $n, %h ) = -1; $_ = $h{$_} //= $n+=2 for @a; print Dumper \@a;

I suppose if you were playing golf, without use strict, you might write:

my ( $n, %h ) = -1; $_ = $h{$_} //= $n+=2 for @a;
in one-line as:
$_=$h{$_}//=$}+=2-!$}for@a;
(/me ducks)


In reply to Re^2: Replacing values in an array by eyepopslikeamosquito
in thread Replacing values in an array by tonto

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Tux]: C99 is not supported on HP-UX before 11.31
    [Tux]: at least not reliable. And perl itself requires C89 (but probes if it can safely use some C99 features)
    Eily takes a peek in the last hour of CB to discover that LanX woke up is boobs with some Queen :P
    [Eily]: s/\K\bis\b/h/
    [Tux]: you left the space in
    [Tux]: and that \K is not required
    [Tanktalus]: 11.31 is already 10 years old... you still need to support versions older than that? My condolences :)
    [Eily]: meh, got confused. s/(?=\bis\b)/h/ will work better :)
    [Eily]: \K keeps the thing on the left, not the right (IE, it's like look behind, not look ahead)

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (11)
    As of 2017-09-20 16:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      During the recent solar eclipse, I:









      Results (237 votes). Check out past polls.

      Notices?