in reply to Re^4: Reading a .txt file under 2 levels of compression
in thread Reading a .txt file under 2 levels of compression
This prints:$apples = 10; $pears = 6; take_one(\$apples); # take one apple take_one(\$pears); # take one pear print "I've still got $apples apples and $pears pears.\n"; sub take_one { my $ref = shift; # a reference $$ref-- # access the value of the referenced scalar }
I've still got 9 apples and 5 pears.
For more info, check out perlreftut and perlref.
It's easy for a programmer to detect if a value is a reference: just use ref: it'll return an empty string for a normal string, and "SCALAR" for a reference to a scalar.
It's a convention among module authors to use a reference to a scalar if you want to actually use the string value as data, instead of as a file name from which you'll read the contents; for example in the various HTML parsing modules.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Reading a .txt file under 2 levels of compression
by LazyIntern (Initiate) on Jan 14, 2011 at 00:45 UTC |