in reply to storing all type of vars

As davorg has pointed out the errors in your code, I shall attempt to provide a working solution for your problem -
{ my @store; sub put { @store = ref($_[0]) ? @{$_[0]} : $_[0]; } sub get { return wantarray ? @store : \@store; } }
HTH

broquaint

Replies are listed 'Best First'.
Re: Re: storing all type of vars
by davorg (Chancellor) on Sep 11, 2001 at 15:22 UTC

    That doesn't quite do what I expected when storing a scalar value:

    use strict; { my @store; sub put { @store = ref($_[0]) ? @{$_[0]} : $_[0]; } sub get { return wantarray ? @store : \@store; } } my $scalar = 100; put($scalar); $scalar = get; print "$scalar\n";

    This prints:

    ARRAY(0x20026814)

    which means you're returning a reference when you should just be returning the value.

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>

      Of course, you're totally right.
      Mental note: think then code, but firstly sleep...

      broquaint