Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^5: magic-diamond <> behavior -- WHAT?! (sanity)

by Anonymous Monk
on Oct 30, 2008 at 11:41 UTC ( #720445=note: print w/replies, xml ) Need Help??

in reply to Re^4: magic-diamond <> behavior -- WHAT?! (sanity)
in thread magic-diamond <> behavior -- WHAT?!

Its more like pulling over when you get nailed, then you get out, fix your tire.
  • Comment on Re^5: magic-diamond <> behavior -- WHAT?! (sanity)

Replies are listed 'Best First'.
Re^6: magic-diamond <> behavior -- WHAT?! (sanity)
by ikegami (Pope) on Oct 30, 2008 at 19:17 UTC

    The program won't run with certain file names. <> just won't work with them. Are you suggesting that all scripts should reimplement <> to use 3-arg open? You're talking about extremely tricky code if you don't want to break -i.

      Well, what most people ranting about magic open say is that files ending in '|' get created either by accident, or they are there to try to exploit something. In such cases, I would like to see the files removed; I rather have my filter stop and complain in stead of silently processing the file and leaving the potential exploit there.

      Now, if you actually want to have files that start with '<', '>', '|' or whitespace, or end with '|' or whitespace, then you are in for a lot of suffering - not just from Perl, but from the shell as well. But still, Perl has a documented solution (see for instance, 'perlopentut'):

      BEGIN {s!^(\s)!./$1!,s/^/</,s/$/\0/ for @ARGV}
      Yes, and that works with -i as well.
        Yes, and that works with -i as well.

        Doesn't seem to:

        > perl -i.bak -pe "BEGIN{s!^(\s)!./$1!,s/^/</,s/$/\0/ for @ARGV} s/fo +o/bar/" bar Can't open <bar: No such file or directory. > perl -v This is perl, v5.10.0 built for cygwin-thread-multi-64int (with 6 registered patches, see perl -V for more detail)

        Putting '<' on the front breaks -i. Putting "\0" on the end breaks -i.bak. Prepending "./" (at least on platforms that support that directory syntax) doesn't break either use of -i, but that still leaves files that end with space or '|' out.

        But I still boggle that you think it is better to make the 99% case this much harder while refusing to make the "cute hack" magical case any harder at all. So much for proper Huffman coding (much less defaulting to 'safe' behavior and requiring a slight acknowledgement for something dangerous).

        echo > '"Reason for this Perl insanity?" || rm -rf .. |'

        - tye        

        not just from Perl, but from the shell as well.

        What shell are you using? Besides, most people have never seen a shell. They don't know about such oddities. They don't care about such oddities. They create all sort of weird file names.

        Now, if you actually want to have files that start with '<', '>', '|' or whitespace, or end with '|' or whitespace...
        ...then you are a masochist, and deserve every bit of your self-inflicted pain. Why make your life harder than it has to be?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://720445]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-06-24 02:05 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.