Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: return Both ARRAY and SCALAR

by jhourcle (Prior)
on May 01, 2009 at 13:25 UTC ( #761287=note: print w/replies, xml ) Need Help??

in reply to return Both ARRAY and SCALAR

You wouldn't have gotten that behaviour if you had 'use strict'.

You're not actually overloading, what's happening is that you're assigning to an array based on the name of the variable:

sub XX{ my $x = 'one'; #scalar value push(@{$x}, 'two'); # push(@one, 'two') push(@{$x}, 'three'); # push(@one, 'three') return $x; }

Once it's in a module, '@one' is out of scope. If you really want this exact behaviour, you're likely going to need to look into a tied array that stringifies to your 'scalar' value.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://761287]
LanX explains much cargo bla ...
[Eily]: what? I thought PHP was known for its reliable and consistent behaviour and documentation!
[LanX]: ... and a lot of pseudo Perl experts
[Eily]: though honestly, I'm sure I have seen people use closure to mean anonysub for perl as well
[stonecolddevin]: good morning friends
[LanX]: yes, mainly pseudo Perl experts
[Eily]: good morning stonecolddevin
LanX has to go/
[Eily]: bye LanX

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2018-02-23 17:15 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (305 votes). Check out past polls.