in reply to Re: Memcached and arrays?
in thread Memcached and arrays?

I thought subroutines can accept arrays then passed to @_? The plan was to use this code segment once working in a larger context.
sub mem_get{ my $tmp = $memd->get($_[0]); if (ref($tmp) eq "ARRAY"){ return @{$tmp}; }else{ return $tmp; }

Replies are listed 'Best First'.
Re^3: Memcached and arrays?
by ikegami (Patriarch) on Jan 21, 2010 at 06:22 UTC

    I thought subroutines can accept arrays then passed to @_

    That sentence is a contradiction. Array element can only be scalars, so @_ can't contain an array. It can only contain a reference to one since a reference is a scalar.

    In

    foo(@a)

    @a evaluates to its content, and those are used as the arguments. The above is the same as

    foo($a[0], $a[1], $a[2], $a[3]);

    The plan was to use this code segment once working in a larger context.

    Careful

    my $old_x = [qw( a b c )]; $memd->set(x => $x); my $new_x = mem_get('x'); # $new_x = 3 !?