Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by BillKSmith (Prior)
on Dec 29, 2020 at 21:38 UTC ( #11125952=note: print w/replies, xml ) Need Help??


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

Thanks to all for the explanation. I thought that this switch would add a useful, if not required, function with almost no code. Clearly this is not the case. If backup is desired, I would now recommend explicitly coding the steps described in the documentation of -i. Take care to put the close in the proper place.
Bill
  • Comment on Re^2: Command Switch -i prints to screen not file

Replies are listed 'Best First'.
Re^3: Command Switch -i prints to screen not file
by LanX (Cardinal) on Dec 29, 2020 at 22:36 UTC
    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

      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
Node Status?
node history
Node Type: note [id://11125952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2021-04-18 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?