http://qs321.pair.com?node_id=11102973


in reply to Re: Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners")
in thread Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners")

though you might prefer to avoid strict vars in one-liners
I like to pretend that I don't use strict and warnings on oneliner because it lets me use the full power of unconstrained perl, but trully 95% of the time I just want to be able to use variables without declaring them (4.999% are for being able to leave a word unquoted. The rest is for shooting myself in the foot)

But this is where Windows is clearly superior to Linux, because you can use ' to be able to use undeclared variables where Linux would require the twice boringer ::

perl -Mstrict -E "$'x = 2; say $'x" 2
Or if you're a true smartass, you can just limit yourself to using only _, a and b as variable names :P

Replies are listed 'Best First'.
Re^3: Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners")
by LanX (Saint) on Jul 18, 2019 at 21:02 UTC
    > Windows is clearly superior to Linux,

    You mean because on Windows you need to put the code in double quotes which don't collide with single quotes?

    The best thing would be a Perl shell without the need to quote at all and calling OS commands inside out.

    update

    the second best thing is perl <RET>

    Perl reads from STDIN then, Ctrl-d or __END__ ends it. Works on both plattforms.

    C:\>perl -w print $x ^D Name "main::x" used only once: possible typo at - line 2. Use of uninitialized value $x in print at - line 1. C:\>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re^3: Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners")
by choroba (Cardinal) on Jul 19, 2019 at 08:20 UTC
    > this is where Windows is clearly superior to Linux

    Let me correct you. I'm getting 2 as the output on Linux, too. That's because `$'` is not a valid variable name in the shell (at least in bash which I use).

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]