Special Variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beany
    New Member
    • Nov 2006
    • 173

    #1

    Special Variables

    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
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Don't get confused. They are really like any other scalar in perl, for example:

    Code:
    $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:

    Code:
    chomp;
    the above performs chomp on $_.

    Code:
    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.

    Comment

    • Beany
      New Member
      • Nov 2006
      • 173

      #3
      cool,

      will have a look at the link..
      thanks

      Comment

      Working...