Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Good story, we've all been thru this once. =)

Just a hint

> (And yes, I do use the the duo on most every script I write-just not always on "one-liners".)

well you could set up an alias psw=perl -Mstrict -Mwarnings if you think that you'd really go to declare variables.

IIRC there was also a possibility to globally require a a piece of Perl code whenever your installation runs.

update

> where "-Mstrict -Mwarnings" would have added a mere 19 characters in length

or see perlrun#PERL5OPT: "Switches in this variable are treated as if they were on every Perl command line."

C:\>set PERL5OPT=-w -Mstrict C:\>perl -e"print $x" Global symbol "$x" requires explicit package name (did you forget to d +eclare "my $x"?) at -e line 1. Execution of -e aborted due to compilation errors.

though you might prefer to avoid strict vars in one-liners

C:\>set PERL5OPT=-w -Mstrict=refs,subs C:\>perl -e"print $x" Name "main::x" used only once: possible typo at -e line 1. Use of uninitialized value $x in print at -e line 1.

comming back to your original case

C:\>perl -le "my $str = q{zxcv}; if ( $str -~ m/some pattern/i ) { pri +nt $str; }" Use of uninitialized value $_ in pattern match (m//) at -e line 1. Argument "zxcv" isn't numeric in subtraction (-) at -e line 1. zxcv

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


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") by LanX
in thread Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners") by atcroft

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (6)
    As of 2019-12-12 19:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?