Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Perl Style: About error messges opening files

by flyingmoose (Priest)
on Apr 27, 2004 at 14:06 UTC ( [id://348485]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Style: About error messges opening files
in thread Perl Style: About error messges opening files

OT, but yet another style question for Abigail, since '=>' was like crazy again...

I've noticed you use => in place of commas .. a lot. <seinfeld>not that there is anything wrong with that</seinfeld>. I'm still one that uses => only for hash construction, when I need to imply a key-value pair, or maybe in a map, but anyway, when I need the implicit LHS quoting and a comma.

In one of your examples, you gave something like

system mkdir => -p => $foo;

while most would do something closer to:

system("mkdir -p $foo");

Care to explain why this is syllistically more interesting to you? My guess is no, but we're on a style thread and this just looks odd to me. I'm thinking you were nearly eaten by a pack of rabid commas when you were a child or something :) Ok, so I'm not going to use '=>' any more because of what you might say, I'm just curious ... sort of like a 'where did that accent come from' type of question.

(commence with the moose stoning)

Replies are listed 'Best First'.
Re: Perl Style: About error messges opening files
by Abigail-II (Bishop) on Apr 27, 2004 at 14:19 UTC
    The difference between system("mkdir -p $foo") and system mkdir => -p => $foo; is more than just the style of commas. Single argument system is subject to shell interpretation, while multi argument system is not.

    Having said that, I tend to use => to separate arguments which have totally different roles - most often to separate the first argument from the rest:

    push @array => 1, 2, 3, 4; printf "%s %6d %s" => $foo, $bar, $baz; pack "C" => $var; splice @array => 0, 3 => "foo", "bar", "baz";
    Etc. I've used that long before people started preaching that => was some kind of pair creator. It never was, and still isn't. And I'm not the only one using this style, Larry Rosler (of GRT fame) was a vivid user of this style as well.

    Abigail

      A'ight, thanks! ... that explains a lot!
Re^3: Perl Style: About error messges opening files
by adrianh (Chancellor) on Apr 27, 2004 at 14:18 UTC

    I would imagine that Abigail avoided:

    system("mkdir -p $foo");

    because that would be interpreted by the shell, and would foul up if (for example) $foo contained a filename with spaces. The advantage of using the arrow instead of the comma is that you can get away with less quoting, compare:

    system mkdir => -p => $foo; system 'mkdir', '-p', $foo;

    Same number of chars, arguably more readable.

      To safe another char, one could write

      system qw(mkdir -p), $foo;

      But best would be if perl had a backtick operator like lisp (that is elisp, don't know about other lisp implementations):

      system `(mkdir -p ,$foo);

Re: Re: Re: Perl Style: About error messges opening files
by eserte (Deacon) on Apr 27, 2004 at 14:13 UTC
    You surely mean the list variant of system: system "mkdir", "-p", $foo
      Eh. $foo did not come from untrusted user input in my example.

      Fair point, but it depends on what domain you work in. In fact, none of my programs take any user input :)

        It hasn't to be user input. It could be the result of a File::Find::find run in a directory where some malicious Windows user created a directory name with whitespace in it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found