Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Of Symbol Tables and Globs

by broquaint (Abbot)
on Nov 08, 2002 at 14:53 UTC ( #211441=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    ## create an anonymous block to limit the scope of the package
    {
    ...
    $VAR1 = { 
              'var' => *globtut::var
            };
    
  2. or download this
    $globtut::var = "a string";
    @globtut::var  = qw( a list of strings );
    ...
    $VAR1 = { 
              'var' => *globtut::var
            };
    
  3. or download this
    use Data::Dumper;
    {
    ...
      package globtut::child;
      ##             ^^
    }
    
  4. or download this
    use Data::Dumper;
    {
    ...
    exists:  exists
    delete:  deleted
    defined: no foo
    
  5. or download this
    {
      package globtut;
    ...
    __output__
    
    *globtut::variable
    
  6. or download this
    {
      package globtut;
    ...
    __output__
    
    $variable: a string
    
  7. or download this
    $scalar = "a simple string";
    print *scalar{SCALAR}, "\n";
    ...
    __output__
    
    SCALAR(0x8107e78)
    
  8. or download this
    $scalar = "a simple string";
    print ${ *scalar{SCALAR} }, "\n";
    ...
    __output__
    
    a simple string
    
  9. or download this
      $scalar = "a simple string";
      print $::scalar, "\n";
    ...
      __output__
    
      a simple string
    
  10. or download this
    $scalar = "a simple string";
    print ${ *{$main::{scalar}}{SCALAR} }, "\n";
    ...
    __output__
    
    a simple string
    
  11. or download this
    ${ *scalar{FOO} } = "the FOO data type";
    
    __output__
    
    Can't use an undefined value as a SCALAR reference at - line 1.
    
  12. or download this
    ## this is fine as we're dereferencing the stored reference
    ${ *foo{SCALAR} } = "a string";
    ...
    __output__
    
    Can't modify glob elem in scalar assignment at - line 5, near ""a stri
    +ng";"
    
  13. or download this
    *foo = \"a scalar";
    print $foo, "\n";
    ...
    a scalar
    alistofstrings
    a subroutine
    
  14. or download this
    use Data::Dumper;
    ## use a fresh uncluttered package for minimal Dumper output
    ...
          'string' => *globtut::string,
          'foo' => *globtut::string
    };
    
  15. or download this
    ## put this code in Foo.pm
    
    ...
    }
    
    q</package Foo>;
    
  16. or download this
    use Data::Dumper;
    ## we'll stay out of the 'polluted' %main:: symbol table
    ...
              'BEGIN' => *globtut::BEGIN,
              'fooify' => *globtut::fooify
            };
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://211441]
Approved by adrianh
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (15)
As of 2014-07-31 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls