Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: looking for a good idiom: return this if this is true

by mr_mischief (Monsignor)
on Mar 11, 2005 at 07:41 UTC ( [id://438561]=note: print w/replies, xml ) Need Help??


in reply to looking for a good idiom: return this if this is true

Probably not the "best", but I have one that make somewhat clever use of its placement in a subroutine to work in one line without creating a lexical. I'll put here the whole test program.
#!/usr/bin/perl -w use strict; my $foo = shift; sub one { return shift; } sub two { push @_, one( $foo ) and $_[0] ? return pop : pop; return "No arg"; } print two() . "\n";;
Maybe useful if you're looking for some obfuscation. It works with unshift/shift as well, of course.


Christopher E. Stith

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found