http://www.perlmonks.org?node_id=125537


in reply to perl -s is evil?

Unfortunately, I can't reproduce your results. I get 'password = hello' no matter what, for the following platforms:

update: regarding blakem's one-liner, I see "foo" outputted on all the above platforms. So it looks like a bug. I shall have to revise my opinion regarding -s.

Are you sure that code fragment is what you ran locally? -s isn't that bad. I use it on rare occasions, usually for a short while when a script evolves from needing no command-line switches at all before needing the full-blown mechanism that Getopt::* brings you.

Others may be interested in a tutorial I wrote on the subject a while back: Parsing your script's command line. (Now revised to point to this thread).

--
g r i n d e r

Replies are listed 'Best First'.
Re: Re: perl -s is evil?
by blakem (Monsignor) on Nov 15, 2001 at 14:50 UTC
    Here's a one liner that exhibits this oddity... 5.6.1 and 5.00503 on linux:
    perl -sle 'print $1' -- -1=foo foo /usr/local/bin/perl5.6.1 -sle 'print $1' -- -1=foo foo /usr/local/bin/perl5.00503 -sle 'print $1' -- -1=foo foo
    Can you replicate this?

    -Blake

      I can replicate that. But more to the point, I also get the following result which is closer to the original post:

      (using both Perl 5.6.0 on Win95 and Perl 5.005_02 on Solaris)

      % perl -sle '"Hello" =~ /(\w+)/; print $1' -- -1=foo foo
      It's just plain wrong. Not only can $1 be assigned to, but afterward it refuses to take the pattern from the regex.

      buckaduck

        Well, just some fooling around with the last statement Re: Re: Re: perl -s is evil? on my linux box runing Perl 5.005_03, I decided to see what taint checking would do to this example. Wwll here's the results:
        $ perl -sleT 'use diagnostics; use strict; "Hello" =~ /(\w+)/; print $ +1' -- -1=foo $
        While T in any other position returns
        $ perl -sleT 'use diagnostics; use strict; "Hello" =~ /(\w+)/; print $ +1' -- -1=foo foo $
        Clovs aka jclovs
Re: Re: perl -s is evil?
by malloc (Pilgrim) on Nov 15, 2001 at 21:30 UTC
    Grinder,
    Just cut and pasted the exact same fragment onto a different linux box and got the exact same results when using "./test.pl -1=foo". Also tested on 5.005_03 built for sun4-solaris. Same thing! What is the disconnect i wonder?
    -malloc