Skip to Main Content
Perl in a Nutshell, 2nd Edition
book

Perl in a Nutshell, 2nd Edition

by Nathan Patwardhan, Ellen Siever, Stephen Spainhour
June 2002
Beginner content levelBeginner
759 pages
80h 42m
English
O'Reilly Media, Inc.
Content preview from Perl in a Nutshell, 2nd Edition

Command Processing

In addition to specifying a #! line, you can specify a short script directly on the command line. Here are some of the possible ways to run Perl:

  • Issue the perl command, writing your script line by line via -e switches on the command line:

    perl -e 'print "Hello, world\n"'    # Unix
    perl -e "print \"Hello, world\n\""  # Win32 or Unix
    perl -e "print qq[Hello, world\n]"  # Also Win32
  • Issue the perl command, passing Perl the name of your script as the first parameter (after any switches):

    perl testpgm
  • On Unix systems that support the #! notation, specify the Perl command on the #! line, make your script executable, and invoke it from the shell (as described above).

  • Pass your script to Perl via standard input. For example, under Unix:

    echo "print 'Hello, world'" | perl -
    % perl
    print "Hello, world\n";
    ^D
  • On Win32 systems, you can associate an extension (e.g., .plx) with a file type and double-click on the icon for a Perl script with that file type. Or, as mentioned earlier, do this:

    (open a "DOS" window)
    C:\> (edit your Perl program in your favorite editor)
    C:\> pl2bat yourprog.plx
    C:\> .\yourprog.bat
    (program output here)

    If you are using the ActiveState version of Win32 Perl, the installer normally prompts you to create the association.

  • On Win32 systems, if you double-click on the icon for the Perl executable, you’ll find yourself in a command-prompt window with a blinking cursor. You can enter your Perl commands, indicating the end of your input with Ctrl-Z, and Perl will compile ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl by Example, Fourth Edition

Perl by Example, Fourth Edition

Ellie Quigley
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington
Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 0596002416Errata Page