>>>>> "CB" == Chet Butcher <> writes:
CB> In the following sequence
CB> $r = {}; # a hashref
CB> $r = []; # an arrayref
CB> $r = ?; # a scalar ref
CB> What is ? ? I want to pass a ref to a scalar (pass by reference)
CB> without resorting to
there is no special syntax to get a scalar ref like with hashes and arrays.
CB> my $r;
CB> mySub( \$r );
a do block works fine too:
my $r = do{ \my $r } ;
CB> I know it's not a big drama on the surface, but I'm trying to overload
CB> the method to return various results depending on the reference type,
CB> and I dont want the \ in some calls and not others.
you need the \ somewhere to generate a scalar ref. and like with arrays
and hashes you can get them in loops and subs without the do block:
<untested pseudo code>
while( 1 )
my $foo = get_stuff() ;
push @foos, \$foo ;
}
perl will allocate a fresh scalar so you get a fresh scalar ref each
iteration. this is like:
while( 1 )
my @bar = get_list() ;
my %baz = get_hash() ;
push @stuff, { bar => \@bar, baz => \%baz } ;
}
you get new arrays and hashes each iteration because a ref to the old
value is still around (inside @stuff's hashes).
uri
--
Uri Guttman ------
--------
http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training ---
http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ----
http://bestfriendscocoa.com ---------