Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: map it back jack

by I0 (Priest)
on Dec 16, 2000 at 02:46 UTC ( [id://46955]=note: print w/replies, xml ) Need Help??


in reply to map it back jack

%myhash = map{ $v = $_; $v =~ s/_/ /g; $_,$v } @elements;

Replies are listed 'Best First'.
Re: Re: map it back jack
by redcloud (Parson) on Dec 16, 2000 at 02:59 UTC
    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.

      In the quest for Shorter and More Efficient:
      my %myhash = map { $v=$_; y/_/ /; $_,$v } @elements;
      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-29 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found