Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: perl -s is evil?

by grinder (Bishop)
on Nov 15, 2001 at 13:58 UTC ( #125537=note: print w/replies, xml ) Need Help??

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:

  • 5.005_03 built for i386-freebsd
  • 5.005_03 built for i386-linux
  • v5.6.0 built for i386-openbsd
  • v5.6.0 built for sun4-solaris
  • v5.6.1 built for i386-linux
  • v5.6.1 built for MSWin32-x86-multi-thread

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?


      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.


        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
    Just cut and pasted the exact same fragment onto a different linux box and got the exact same results when using "./ -1=foo". Also tested on 5.005_03 built for sun4-solaris. Same thing! What is the disconnect i wonder?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-10-19 21:03 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (206 votes). Check out past polls.