Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^4: Hash assignments using map

by chargrill (Parson)
on Feb 24, 2007 at 16:47 UTC ( #601893=note: print w/replies, xml ) Need Help??

in reply to Re^3: Hash assignments using map
in thread Hash assignments using map

first point is, you only have letters, no numbers, so Perl won't "increment" them


$ perl -le '$c = "a"; print ++$c' b

Check perlop:

The auto-increment operator has a little extra builtin magic to it. ... If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern "/^[a-zA-Z]*[0-9]*\z/", the increment is done as a string, preserving each character within its range, with carry ...

Update: Though you're actually right, but only by coincidence. Using the postfix autoincrement won't make the hash elements incremented.

$ perl -Mstrict -MData::Dumper -we 'my @a = qw(a b c d); \ my %h = map { $_++ } @a; print Dumper \%h' $VAR1 = { 'c' => 'd', 'a' => 'b' };

s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Replies are listed 'Best First'.
Re^5: Hash assignments using map
by mk. (Friar) on Feb 24, 2007 at 16:56 UTC
    my bad!
    it actually increments the elements of the array, but adds them unchanged to the hash.
    thanks for pointing that out, chargrill++! :)


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://601893]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2023-12-07 22:58 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (33 votes). Check out past polls.