in reply to same script acts differently when run as a file vs one-liner

cmd as in cmd.exe windows like me? See Re: 'perl -le' not working on the command line

$ perl -MO=Deparse -p -w -e 's/(\w+)/\u\L$1/' Useless use of a constant (s/(\w+)/\u\L$1/) in void context at -e line + 1. BEGIN { $^W = 1; } LINE: while (defined($_ = <ARGV>)) { '???'; } continue { die "-p destination: $!\n" unless print $_; } -e syntax OK $ perl -MData::Dump -e " dd\@ARGV " 's/(\w+)/\u\L$1/' ["'s/(\\w+)/\\u\\L\$1/'"]

See also perlrun, Behind the GUI lives the Shell and How Command Line Parameters Are Parsed

Replies are listed 'Best First'.
Re^2: same script acts differently when run as a file vs one-liner
by mavili (Initiate) on Jul 25, 2012 at 10:58 UTC
    thanks for the quick reply. however, I didn't really get much use from your code. I read the thread about cmd.exe turning  'print $something;' into "'print" "$something;'" but what's your code supposed to do?
      perl -p -w -e 's/(\w+)/\u\L$1/'

      mavili: What Anonymonk (and, in particular, the given link – did you take a look at it?) wanted to point out is that you are not using the proper command line argument quoting for the Windows command line processor (single-quotes would be appropriate for *nix). Try either
          perl -p -w -e "s/(\w+)/\u\L$1/"
      (using double-quotes) or, because there are no embedded spaces in the CLI argument and thus no need for quotation, simply
          perl -p -w -e s/(\w+)/\u\L$1/
      instead.

      thanks for the quick reply. however, I didn't really get much use from your code. I read ... but what's your code supposed to do?

      Well, its supposed to show you the same thing the other thread showed, what reaches perl and how -- that's of no use?

        well, by that I meant I didn't understand it well. thanks for your replies.