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

Re^2: Is this the most elegant way to code directory lookup?

by davorg (Chancellor)
on Sep 29, 2006 at 15:20 UTC ( [id://575549]=note: print w/replies, xml ) Need Help??


in reply to Re: Is this the most elegant way to code directory lookup?
in thread Is this the most elegant way to code directory lookup?

die "Error:$!" unless (-d $srcdir && -d $destdir );

As I mentioned before, $! won't have anything useful in it at this point, so there's no reason to include it in the error message.

Why not make the error messages a little clearer.

die "$srcdir is not a valid directory\n" unless -d $srcdir; die "$destdir is not a valid directory\n" unless -d $destdir;

Update: Looks like I'm wrong.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^3: Is this the most elegant way to code directory lookup?
by hv (Prior) on Oct 02, 2006 at 10:18 UTC

    Update: Looks like I'm wrong.

    I disagree: just because someone tried it once and got a useful error message doesn't change the fact that $! is not documented to be defined at this point.

    $! may well get set differently (or not at all) in different circumstances, when testing different files, or on a different O/S, or depending on phase of the moon for all we know.

    Your suggested clearer error messages are definitively more correct; the only change I might make (at the risk of getting too clever) is to avoid the duplication with something like:

    die "$_ is not a valid directory\n" for grep !-d, $srcdir, $destdir;

    Hugo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://575549]
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: (4)
As of 2024-04-19 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found