By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,372 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,372 IT Pros & Developers. It's quick & easy.

Special Variables

100+
P: 173
Hi,

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
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
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

100+
P: 173
cool,

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

Post your reply

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