Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Eily (Monsignor)
on Jul 18, 2019 at 13:20 UTC ( #11102973=note: print w/replies, xml ) Need Help??


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

  • Comment on Re^2: Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners")
  • Download Code

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 (Archbishop) 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 (Archbishop) 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]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2019-12-14 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?