Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: More efficient return of values from sub

by jbrugger (Parson)
on Mar 26, 2005 at 09:54 UTC ( [id://442462]=note: print w/replies, xml ) Need Help??


in reply to More efficient return of values from sub

I would use oo to solve this, an object keeps all the vals for you that you need, and you can do lots more with them as you pass on.
#!/usr/bin/perl use strict; my $obj = blah->new(); sub A() { print( $obj->getName . " , " . $obj->{address} . "\n" ); } sub B() { print( $obj->getName . " , " . $obj->{address} . "\n" ); } A; B; package blah; use strict; sub new() { my $classname=shift; my $self=bless{}; $self->{name} = "Sam"; $self->{address} = "123 Main st"; return $self; } sub getName() { my $self=shift; if ($self->{name}) { return $self->{name}; } else { #Init name and return value... } } 1;
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://442462]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-23 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found