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

Re^3: small steps toward Perl literacy, temp vars and parentheses

by Jenda (Abbot)
on Jun 16, 2004 at 22:18 UTC ( [id://367458]=note: print w/replies, xml ) Need Help??


in reply to Re^2: small steps toward Perl literacy, temp vars and parentheses
in thread small steps toward Perl literacy, temp vars and parentheses

If we wanted a statement that could be read from right to left completely we could use

%h = ( $_, $h{$_}) for ($_) = sort {$a <=> $b} keys %h;
"Take the keys of %h, sort them numericaly, take the first one and set the %h hash to the key and its value."

But I think this one is even more confusing. Maybe this

%h = ( $_, $h{$_}) for ($_,) = sort {$a <=> $b} keys %h;
would be better, the comma giving a hint that we do expect the sort to return several values, but we use just the first one.

Anyway in this case I would use some temp variable. Even though I did work with some functional languages and liked it :-)

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature

Replies are listed 'Best First'.
Re^4: small steps toward Perl literacy, temp vars and parentheses
by ysth (Canon) on Jun 23, 2004 at 08:14 UTC
    I would definitely use for my ($min_key) = there; using a for that modifies $_ beyond the scope of the for itself is just begging to mess someone else up.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-28 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found