Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Wrong idioms

by BrowserUk (Pope)
on Mar 29, 2013 at 23:39 UTC ( #1026207=note: print w/ replies, xml ) Need Help??


in reply to Wrong idioms

You've noticed a problem, but are proposing the wrong solution.

The author wasn't being lazy, but overzealous.

The better solution is to simply skip the check of the filename completely.

Pass the filename supplied to the open function and let it detect and report the error.

This approach is portable because it lets the OS decide whether the string passed is valid.

The alternative is for every file handling routine to detect the current OS and then replicate all of the complex rules for filenames and paths for all systems; and that is a nonsense.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Wrong idioms
Re^2: Wrong idioms (open $fh, '<', undef)
by Anonymous Monk on Mar 29, 2013 at 23:59 UTC

    the problem with that is undef opens a temporary file

    :) its http://search.cpan.org/perldoc/Dancer::FileUtils#read_file_content

    sub open_file { my ( $mode, $filename ) = @_; open my $fh, $mode, $filename or raise core_fileutils => "$! while opening '$filename' using m +ode '$mode'"; return set_file_mode($fh); } sub read_file_content { my $file = shift or return; my $fh = open_file( '<', $file ); return wantarray ? read_glob_content($fh) : scalar read_glob_content($fh); }

      This will also "open" file without error, if it's not a file, but a directory. Also, does this have any sense?
      return wantarray ? read_glob_content($fh) : scalar read_glob_content($fh);
      In case we don't want an array, it will be converted to 'scalar' anyway.
        What are you talking about?
      the problem with that is undef opens a temporary file

      And what is to say that is not both a useful feature and exactly what the user intends?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        And what is to say that is not both a useful feature and exactly what the user intends?

        Hmm, open a file for reading, not append, can't read from it, can't write to it -- makes perfect sense, very useful

Re^2: Wrong idioms
by vsespb (Hermit) on Mar 30, 2013 at 00:16 UTC
    Maybe in TS example, readfile should return undef/empty list in case called without arguments ?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-12 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (239 votes), past polls