Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Cheap idioms

by Aragorn (Curate)
on Oct 13, 2002 at 17:35 UTC ( #204924=note: print w/ replies, xml ) Need Help??


in reply to Cheap idioms

Nicely small and concise. I'd only use this in stand-alone scripts, because there aren't any checks on file existence, etc. Burying this kind of code inside libraries is asking for trouble... :-)


Comment on Re: Cheap idioms
(tye)Re2: Cheap idioms
by tye (Cardinal) on Oct 13, 2002 at 17:49 UTC

    Actually, part of the beauty of this idiom is that you get Perl itself to check for file existence and to report better than average error messages.

                    - tye
      Oh, I like this idiom, but strictly in stand-alone scripts. Bombing out of a program deep inside some library doesn't sit well with me.

      And Perl exits with the following error message if the file doesn't exist using this idiom:
      Can't open /does/not/exist: No such file or directory.
      Uhm. I can do that :-)

        Yes, it doesn't seem hard at all does it? (:

        It includes a description of what was being attempted ("open", though I'd probably opt for metioning that "read" access is what was required -- though I can understand not wanting to confuse people into thinking it was a read operation that failed while keeping the message short), the input data to the operation (the name of the file), and the correct error code indicating why it failed ($! in this case).

        Unfortunately, that still makes it above average in my experience. ):

                - tye (who doesn't like error messages a la mode)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2015-07-04 05:20 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 (57 votes), past polls