Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

one liner error

by toohoo (Beadle)
on May 27, 2020 at 05:57 UTC ( [id://11117317]=perlquestion: print w/replies, xml ) Need Help??

toohoo has asked for the wisdom of the Perl Monks concerning the following question:

Hello everybody

I just tried to test an one liner.

perl -e use Cwd; print getcwd();

In this I get an error
If I put this in a perl script file and run then all is fine.
What I'm doing wrong?

I'm under Windows 10 perl 5, version 26, subversion 2 (v5.26.2) built for x86_64-msys-thread-multi

Thanks in advance, best regards

Replies are listed 'Best First'.
Re: one liner error
by Athanasius (Archbishop) on May 27, 2020 at 06:21 UTC

      Hello Athanasius

      Thank you very much, this solved my issue.

      Have a nice day

Re: one liner error
by AnomalousMonk (Archbishop) on May 27, 2020 at 11:02 UTC

    Further to Athanasius's reply:   If you don't like using quotes on your command line (and who does?), you can, in certain limited cases, avoid them:

    c:\@Work\Perl\monks>perl -wMstrict -MCwd -le my$str=getcwd;print(qq{it +\x20is\x20now\x20$str}) it is now c:/@Work/Perl/monks
    The trick is that the command(s) must not contain whitespace. Time and effort spent golfing is never wasted!


    Give a man a fish:  <%-{-{-{-<

      Just to expand for *NIX shells, you need to avoid whitespace and other characters the shell is going to interpret specially: e.g. parens, curlies, braces, splats, dolar signs, ampersands, semicolons, and backslashes (and that's in no ways an exhaustive list). Usually you can backslash them to escape them, but you're going to wind up with leaning toothpick syndrome. It'll be much simpler (to say nothing of fewer characters) if you just break down and (single) quote things and be done with it.

      $ uptime | perl -nE m\{\(load\ averages:.\*\)\}\&\&say\$1 load averages: 1.12 1.02 0.95 $ uptime | perl -nE 'm{(load averages:.*)}&&say$1' load averages: 0.84 0.96 0.93

      (Insert Jurasic Park quote about could versus should)

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Simpler? Simpler? I don' need no stinkin' simpler! I've got Windose!


        Give a man a fish:  <%-{-{-{-<

        >Jurasic Park

        It's a UNIX system. You know this. xD

        Also the source of the "hold your butts" meme for when you're deploying something tricky or not well tested...talk about bout an effect on nerd culture.

      Hi AnomalousMonk,

      ARGH! The Windows space problem. You are right. Sometimes I have known things already that sometimes I forget :-/

      Many thanks to you, you are great.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11117317]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-18 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found