in reply to storing all type of vars

It doesn't work because you g'get' returns a list. If you evaluate that in scalar context you get the number of elements.
Use wantarray to check for the context:

{ my @store; sub put { @store = @_;} sub get { return wantarray ? @store : $store[0]; }}

Replies are listed 'Best First'.
Re: Re: storing all type of vars
by davorg (Chancellor) on Sep 11, 2001 at 14:14 UTC
      Nice catch!! For those confused by this, see Arrays are not lists. It helped clarify the difference between the two (and more importantly, why you should care) in my mind.

      -Blake

      Only if you define "a list" as being something rather specific that doesn't match many, many uses of the term "list" in even just the standard *.pod documentation.

      Some argue that you can't "evaluate a list in a scalar context" because the scalar context prevents the creation of the list in the first place (clearly they have a different, specific definition of the term "list" in mind when they say this). Some argue that there is no general rule about what you get when you evaluate a list in a scalar context: you could get the last element, a count of elements, the first element, or something else entirely. This fits a bit closer to my thinking on the matter.

      I prefer to be very careful and say that evaluting "something that would return a list if used in a list context" in a scalar context may get you any number of things. One of the most common is the last element of the list.

      I also feel that the term "list" is used to mean so many different things in so many different standard texts on Perl that saying anything definitive about "a list" without first carefully defining what "a list" means to you (at that moment) is likely to be an incorrect or at least overbroad statement.

              - tye (but my friends call me "Tye")