Skip to Main Content
Learning Perl, 5th Edition
book

Learning Perl, 5th Edition

by Randal L. Schwartz, Tom Phoenix, brian d foy
June 2008
Beginner content levelBeginner
352 pages
11h 16m
English
O'Reilly Media, Inc.
Content preview from Learning Perl, 5th Edition

The %ENV hash

Your Perl program, like any other program, runs in a certain environment, and your program can look at the environment to get information about its surroundings. Perl stores this information in the %ENV hash. For instance, you’ll probably see a PATH key in %ENV:

print "PATH is $ENV{PATH}\n";

Depending on your particular setup and operating system, you’ll see something like this:

PATH is /usr/local/bin:/usr/bin:/sbin:/usr/sbin

Most of these are set for you automatically, but you can add to the environment yourself. How you do this depends on your operating system and shell:

Bourne shell

  $ CHARACTER=Fred; export CHARACTER
  $ export CHARACTER=Fred

csh

  % setenv CHARACTER Fred

DOS or Windows command

  C:> set CHARACTER=Fred

Once you set these environment variables outside of your Perl program, you can access them inside your Perl program:

print "CHARACTER is $ENV{CHARACTER}\n";
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

Learning Perl, 6th Edition

Learning Perl, 6th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Beginning Perl

Beginning Perl

Curtis Ovid Poe
Learning Perl 6

Learning Perl 6

brian d foy
Mastering Perl

Mastering Perl

brian d foy

Publisher Resources

ISBN: 9780596520106Supplemental ContentErrata Page