in reply to Re^2: Using a tied scalar as an in memory file
in thread Using a tied scalar as an in memory file
In this code sample, which compares the usage of a parameter array element directly ($_[0]) with one common usage of the array ($param = shift @_)
use strict; use warnings; { package TiedObject; sub TIESCALAR { my $sClass = shift; return bless([ @_ ], $sClass); } sub STORE {} sub FETCH { shift->[0]; } } my $sErr; tie $sErr, 'TiedObject', 5, "More data"; printTiedObject($sErr); sub printTiedObject { my $oErr = tied($_[0]); #does not copy scalar, prints out "...is tied to..." print "using \@_ directly\n"; if (defined($oErr)) { print "\$_[0] is tied to <$oErr>\n"; } else { print "\$_[0] is not tied"; } #copies scalar, prints out "..is not tied" print "\nafter \$param0 = shift \@_\n"; my $param0 = shift @_; $oErr = tied ($param0); if (defined($oErr)) { print "\$param0 is tied to <$oErr>\n"; } else { print "\$param0 is not tied\n"; } }
we get the following output
using @_ directly $_[0] is tied to <TiedObject=ARRAY(0x814ed48)> after $param0 = shift @_ $param0 is not tied
Best, beth
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Using a tied scalar as an in memory file
by ikegami (Patriarch) on Feb 21, 2009 at 21:05 UTC | |
by ELISHEVA (Prior) on Feb 22, 2009 at 13:12 UTC | |
by ikegami (Patriarch) on Feb 22, 2009 at 19:01 UTC |