Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Command Switch -i prints to screen not file

by LanX (Saint)
on Dec 29, 2020 at 22:36 UTC ( [id://11125953]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Command Switch -i prints to screen not file
in thread Command Switch -i prints to screen not file

Allow me some comments ...

I think putting command-line switches into the she-bang is not one of the better ideas, I doubt it's portable.

HaukeX just offered an alternative special variable, which even has a full English name $INPLACE_EDIT which is also self documenting.

And you've rather got bitten here by the effects of slurping the whole file into an array which is often a dangerous idea, because the size might be huge. I prefer lazy iteration by working line by line, whenever possible.

And making a full copy in RAM first is rather the strategy when you intend to directly replace the content in the filesystem, so you somehow doubled the efforts to a paradox effect.

Just my 2 cents ... :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^3: Command Switch -i prints to screen not file

Replies are listed 'Best First'.
Re^4: Command Switch -i prints to screen not file
by hippo (Bishop) on Dec 29, 2020 at 23:19 UTC
    I think putting command-line switches into the she-bang is not one of the better ideas, I doubt it's portable.

    I respectfully disagree. How else would you expect to enforce taint mode, for example?


    🦛

      My points were readability, maintainability and portability.

      While Windows seem to ignore the path to the executable, Perl itself is indeed parsing the flags (though taint is special here - later more)

      There is a fuzzy line were a short script is still in a league with one-liner from the command line where terseness pays off and a "real" program which needs at least mid-term maintenance.

      "Hiding" important side-effects of in short flags is not a good idea in my book, they need to be explicitly shown!

      And those provisory "scripts" tend to live longer than expected.

      So whenever possible avoid shebang flags for code which needs to be maintained.

      > How else would you expect to enforce taint mode, for example?

      Granted, it's in the nature of taint that it's hard to manipulate.

      But when I test -T or -t on the shebang on Win, it's not activated but only checked.

      d:\tmp\pm>perl tst_taint.pl "-T" is on the #! line, it must also be used on the command line at ts +t_taint.pl line 1. d:\tmp\pm>

      The same effect of exiting the current process can also be achieved by checking the read-only flag ${^TAINT}.

      Putting this check into a pragma called use taint; (which I couldn't find yet) would be even better.

      And this pragma could even go further, and re-exec the current script, with the -T flag set.

      THOUGH ... the code for this pragma would need to be secured with special privileges, to avoid a backdoor for attackers...

      I can't tell if this is bulletproof, but security is always relative anyway.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found