Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
"be consistent."
 
PerlMonks

Perl Special Variables Quick Reference

by davido (Chancellor)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on May 14, 2004 at 03:20 UTC ( #353259=perltutorial: print w/ replies, xml ) Need Help??

Special Vars Quick Reference

$_The default or implicit variable.
@_Subroutine parameters.
$a
$b
sort comparison routine variables.
Regular Expressions
$<digit>Regexp parenthetical capture holders.
$&Last successful match (degrades performance).
$`Prematch for last successful match string (degrades performance).
$'Postmatch for last successful match string (degrades performance).
$+Last paren match.
$^NLast closed paren match.
@+Offsets of ends of successful submatches in scope.
@-Offsets of starts of successful submatches in scope.
$*Boolean for multi-line matching. Deprecated. Use /s and /m.
$^RLast regexp (?{code}) result.
IO and Separators
$.Current line number (or record number) of most recent filehandle.
$/Input record separator.
$|Output autoflush. 1=autoflush, 0=default
$,Output field separator (lists)
$\Output record separator.
$"Output list separator. (interpolated lists)
$;Subscript separator. (Use a real multidimensional array instead.)
Formats
$#Output format for printed numbers (deprecated).
$%Page number for currently selected output channel.
$=Current page length.
$-Number of lines left on page.
$~Format name.
$^Name of top-of-page format.
$:Format line break characters
$^LForm feed (default "\f").
$^AFormat Accumulator
Status Reporting
$?Child error. Status code of most recent system call or pipe.
$!Operating System Error. (What just went 'bang'?)
%!Error number hash
$^EExtended Operating System Error (Extra error explanation).
$@Eval error.
ID's and Process Information
$$Process ID
$<Real user id of process.
$>Effective user id of process.
$(Real group id of process.
$)Effective group id of process.
$0Program name.
$^OOperating System name.
Perl Status Info
$]Version and patch number of perl interpreter.
$^CCurrent value of flag associated with -c switch.
$^DCurrent value of debugging flags
$^FMaximum file descriptor.
$^IValue of the -i (inplace edit) switch.
$^MEmergency Memory pool.
$^PInternal variable for debugging support.
$^RLast regexp (?{code}) result.
$^SExceptions being caught. (eval)
$^TBase time of program start.
$^VPerl version.
$^WStatus of -w switch
$^XPerl executable name.
Command Line Args
ARGVFilehandle iterates over files from command line (see also <>).
$ARGVName of current file when reading <>
@ARGVList of command line args.
ARGVOUTOutput filehandle for -i switch
Miscellaneous
@FAutosplit (-a mode) recipient.
@INCList of library paths.
%INCKeys are filenames, values are paths to modules included via use, require, or do.
%ENVHash containing current environment variables
%SIGSignal handlers.
$[Array and substr first element (Deprecated!).

See perlvar for detailed descriptions of each of these (and a few more) special variables.

When modifiying special variables, it is often a good practice to localize the effects of the change. ie,

my @array = ( 1, 2, 3, 4, 5 ); print "@array\n"; { local $" = "\t"; print "@array\n"; } print "@array\n";

And the output.....

1 2 3 4 5 1 2 3 4 5 1 2 3 4 5

The purpose of this node is to provide a super-concise categorized quick crossreference to Perl's special variables. perlvar provides a list in asciibetical order but doesn't really put the variables into easy to find categories.

Comment on Perl Special Variables Quick Reference
Select or Download Code
Re: Perl Special Variables Quick Reference
by ysth (Canon) on May 14, 2004 at 03:48 UTC
    For extra credit, document which ones are newer than 5.005_03, and when they were added :)

      @+, @- somewhere near 5.6. Are there more?

      Update: maybe $0 too.

Re: Perl Special Variables Quick Reference
by Anonymous Monk on May 14, 2004 at 05:06 UTC

    While I realize that this is a 'quick reference', you can get a lot more -- and also quick info -- by typing 'perldoc perlvar' at the command line. For example, while $^V does indeed hold the perl version, to get the string representation of it, you need to use sprintf('%vd, $^V);. So yes, this is useful, but perlvar really isn't that difficult to pull up and it holds a little more info.

      I understand what you're saying, and I do believe that the POD is the authority on most things Perlish.

      The problem with perlvar is that it is not all that friendly when the goal is to refresh ones memory on which special var it is that does XXX. It's just not categorized very well ...or if it is, I just didn't see it. True, it is not a terribly long document, but by way of example, there are special variables that deal with regexps scattered in at least three different places in the doc. The primary reason I put this node together was simply to provide a quick, categorized crossreference.

      Frankly, I'm not sure which is more valuable; this parent node (the Perl Special Variables Quick Reference), or the refresher course I got by putting it together. Maybe the node itself fills a need that isn't really there, but it did give me an excuse for diving back into the docs again.

      While on the topic of the POD, I wanted to speculate for a moment what it is that causes so many to avoid it in the first place. I myself read all of the Llama book and most of the Camel book before finally getting comfortable with the idea of using the perldocs. And from the looks of many of the questions that get asked in Seekers of Perl Wisdom, I'm not alone in having had an early-on aversion to the POD.

      For me, discovering it and getting comfortable with it was a significant step toward gaining a more comprehensive understanding of Perl. I feel that others will have that lightbulb flick on in their minds if they too get comfortable with reading Perl's POD.

      That is the other reason I created this parent node. I thought that perhaps it could whet someones' apetite for more, and that by linking to perlvar at the end of the list someone might follow the link and take the first step into Perl's POD.

      Cheers!


      Dave

Re: Perl Special Variables Quick Reference
by itub (Priest) on May 14, 2004 at 13:37 UTC

    Thanks, I like it. While it is true that the POD is the definitive reference for the details of the meaning of each variable, this is better for refreshing your memory when you already know the variables but don't remember their symbols.

Re: Perl Special Variables Quick Reference
by pmonk4ever (Friar) on Dec 17, 2008 at 21:38 UTC
    Thanks for the Quick Reference, I have copied it to a text file and stuck it into a clear page protector sitting in my document holder right next to my monitor!

    Great Job! :)

    ki6jux

    "No trees were harmed in the creation of this node. However, a rather large number of electrons were somewhat inconvenienced."

Re: Perl Special Variables Quick Reference
by wazoox (Parson) on Dec 18, 2008 at 17:43 UTC
Re: Perl Special Variables Quick Reference
by planetscape (Abbot) on Apr 01, 2009 at 18:32 UTC
Re: Perl Special Variables Quick Reference
by Argel (Vicar) on Nov 04, 2009 at 02:23 UTC
    The hashes used to store named captures in Perl 5.10+ should probably be added to the regex list.

    Elda Taluta; Sarks Sark; Ark Arks

Login:
Password
remember me
What's my password?
Create A New User

Node Status?
node history
Node Type: perltutorial [id://353259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (23)
ikegami
Corion
tye
GrandFather
CountZero
marto
jdporter
holli
Gavin
atcroft
kennethk
thezip
Eyck
Perlbotics
Marshall
pemungkah
Utilitarian
ssandv
CColin
snape
MikeDexter
johnvk
im2
As of 2010-02-09 21:40 GMT
Sections?
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

What level of existential comfort do you require?

Palace
Executive suite at the best hotel
Regular hotel in a decent part of town
Motel
Boarding house
Sleeping Bag on Couch in Basement
Any port in a storm
Camping under the freeway overpass
Jail
Other

Results (281 votes), past polls