467,926 Members | 1,886 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

Special Variables


i need serious help with special variables, ie $_ $/ etc etc

I just cant seem to understand these...

can someone please explain these variables to me in the simplest form? POSSIBLY PROVIDING AN EXAMPLE....

I've read tonnes of info on them but can't seem to get my head around it..

thanks in advance
Jul 8 '08 #1
  • viewed: 956
2 Replies
Expert 2GB
Don't get confused. They are really like any other scalar in perl, for example:

Expand|Select|Wrap|Line Numbers
  1. $foo = 'foo';
The one that is the most different is $_ which is simply the default scalar that perl uses for many functions if you do not tell perl which scalar to use, for example:

Expand|Select|Wrap|Line Numbers
  1. chomp;
the above performs chomp on $_.

Expand|Select|Wrap|Line Numbers
  1. chomp $foo;
the above performs chomp on $foo.

(See $_ on the page linked to below.)

Other variables like $/ are just predefined variables that perl uses for many internal operations. Each time you run perl, perl gives them a value (predefined).

They are all discussed on this page and many have examples: http://perldoc.perl.org/perlvar.html

They are all global in scope (last time I checked). Meaning you have to use the local() function if you want to create a temporary definition for one of them in a block of code. See the local() function documentation.
Jul 8 '08 #2

will have a look at the link..
Jul 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Mosher | last post: by
14 posts views Thread by tertius | last post: by
2 posts views Thread by Jim Schueler | last post: by
1 post views Thread by Vannela | last post: by
3 posts views Thread by ATH0 | last post: by
11 posts views Thread by T O | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.