Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

The Concept of References

by leriksen (Curate)
on Apr 14, 2005 at 06:19 UTC ( [id://447659]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $count = 10;
    
  2. or download this
    $copy = $count;
    
  3. or download this
    $ref = \$count; # initialise $ref's value to be a reference to $count
    
  4. or download this
    print "ref $ref\n";
    
    ref SCALAR(0x000003e8)
    
  5. or download this
    print "ref value $$ref\n";
    
    ref value 10
    
  6. or download this
    @array = (10, 20, 30);
    
  7. or download this
    @copy = @array;
    
  8. or download this
    $ref = \@array;
    
  9. or download this
    print "ref $ref\n";
    
    ref ARRAY(0x000003e8)
    
  10. or download this
    print $ref->[1];
    
    20
    
  11. or download this
    print $$ref[1];
    
    20
    
  12. or download this
    %hash = (a => 1, b => 2);
    
  13. or download this
    $ref = \%hash;
    
  14. or download this
    print "ref $ref";
    
    ...
    print $$ref{b};
    
    2
    
  15. or download this
    $array[1] = @another; # nope - number of entries in @another is assign
    +ed to $array[1]
    
  16. or download this
    $array[1] = \@another;
    
    print $array[1]->[0]; # the first entry in the referenced array
    
  17. or download this
    
    sub func {
    ...
    }
    
    func(@ten_million);
    
  18. or download this
    sub func {
       my ($aref) =@_;
    ...
    }
    
    func(\@ten_million);
    
  19. or download this
    $ref = \@array;
    
    ...
    print "ref $ref\n";
    
    1001
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://447659]
Approved by BrowserUk
Front-paged by ghenry
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found