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

Hello Monks,

This is my first post. I started reading the Programming Perl Book, the one with the Camel. And it tells me to say "Howdy World" by coding this:

print "Howdy, World\n";

Instead I found a website that suggested I use this and it worked:

perl -e "print 'Howdy World'"

So what is going on? Is this an update since the book was written or is this just something Strawberry Perl uses

Replies are listed 'Best First'.
Re: why does -e work and not \n on strawberry perl
by wjw (Priest) on Jun 05, 2014 at 04:09 UTC

    Perhaps the confusion lies in the fact that the first example is intended to be in a script file, while the second is intended to run from the command line?

    Full code for the first one would be something like

    #!(path/to/perl.exe) use strict; use warnings; print "Howdy, World\n";
    Obviously your second one is working, so there is not much question about that...

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

    A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct

      Thank you all. I am so grateful that there is this resource here to help people like me learn.

Re: why does -e work and not \n on strawberry perl
by no_slogan (Deacon) on Jun 05, 2014 at 03:31 UTC

    Double quotes usually work better for enclosing command-line scripts in windows shells. Also, windows shells typically add a newline, so you can leave off printing one at the end of your script. If you need \n to work, try using a qq string, like this:

    perl -e "print qq[Howdy\nWorld\n]"
A reply falls below the community's threshold of quality. You may see it by logging in.