Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Cheap idioms

by Aristotle (Chancellor)
on Oct 14, 2002 at 11:04 UTC ( #205030=note: print w/ replies, xml ) Need Help??


in reply to Re: Cheap idioms
in thread Cheap idioms

It looks very neat indeed, but it loads over 1,000 lines of Perl code and an XS module in dependencies.. in a short(!) CGI script I wouldn't want that - but that's always a difficult environment. It's too much to type in a oneliner also, but that too is a special case.

For a large, "proper" script it is too brief - you run the risk of bombing out with a Can't call method "getcontents" on an undefined value since you don't check whether new() succeeded.. it would have to look maybe like this:

my $contents = do { my $fh = IO::File->new($filename) or die "Failed to open $filename +: $!"; $fh->getcontents(); }
And now it doesn't look so neat anymore. :-( Juerd's idiom on the other hand has builtin error reporting.

Makeshifts last the longest.


Comment on Re^2: Cheap idioms
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2015-07-04 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls