Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Declaring Variables

by perlmonkey (Hermit)
on Feb 28, 2001 at 07:50 UTC ( #61278=note: print w/ replies, xml ) Need Help??


in reply to Declaring Variables

I am NOT suggesting this, but I thought I would chime in. You can modify the stack paramaters directly:

use strict; sub test { if( $_[0] =~ /regex/ ) { $_[1] = "match"; } else { $_[1] = "no match"; } } my $bool; test( "foo", $bool ); print "foo: $bool\n"; test( "regex", $bool ); print "regex: $bool\n";
That is just silly though. Use the 'vars' method mentioned above or just have your subs return a value instead of setting a global variable if that is possible.

You can also encapsulate a my'd variable and make it semi global via subroutine calls, but this is sort of silly also:
use strict; { my $foo; sub setFoo{ $foo = shift; } sub getFoo{ return $foo; } }


Comment on Re: Declaring Variables
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-12-28 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls