Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Re: map it back jack

by redcloud (Parson)
on Dec 16, 2000 at 02:59 UTC ( #46961=note: print w/replies, xml ) Need Help??

in reply to Re: map it back jack
in thread map it back jack

Seems like you can save a couple of keystrokes if you're not particular about what ends up in $v, since s/// operates on $_:

my $v; my %myhash = map { $v = $_; s/_/ /g; $v, $_ } @elements;
Is there a way to pare it down more? (The Monastery needs a golf course!)

Update: As I0 points out, this also modifies @elements, which may not be what you want.

johannz's for construct is looking the most elegant to me now.

Replies are listed 'Best First'.
Re: Re: Re: map it back jack
by turnstep (Parson) on Dec 16, 2000 at 03:11 UTC
    In the quest for Shorter and More Efficient:
    my %myhash = map { $v=$_; y/_/ /; $_,$v } @elements;
Re: Re: Re: map it back jack
by I0 (Priest) on Dec 16, 2000 at 03:18 UTC
    You may not be particular about what ends up in $v, but if you're particular about what ends up in @elements you won't want to modify $_ ($v=$_)=~tr/_/ /;$_,$v

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://46961]
[Corion]: 1nickt: On Sunday maybe 10cm of snow fell, and the airport closed, and the trains stopped running etc :) It always comes as a surprise that snow falls here during the winter...
[marto]: 1nickt, no snow, just some ice on the roads and the usual idiocy associated with humans and driving in less than ideal conditions
[1nickt]: Corion I am trying to keep an open mind :-) Or at least, go with the flow. marto yes I saw som photos of lorries overturned on country roads, and wondered why they would have been driving fast enough to have that happen!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-12-11 11:54 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (289 votes). Check out past polls.