Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Flag variables

by arturo (Vicar)
on Mar 03, 2003 at 14:04 UTC ( #240027=note: print w/ replies, xml ) Need Help??


in reply to Flag variables

In addition to the locality issue (where is $flag set vs. where it's eventually tested), it's also not idiomatic Perl. Assuming you *were* going to use a flag variable, it's nice to use Perl's notion of truth:

my $foundFoo =0; foreach my $var( @somearray) { if ($var eq 'foo') { $foundFoo =1; last; } } if ( $foundFoo ) { someaction(); }

And let me also repeat the warning that &action(); does not mean the same as action();; prepending the ampersand, among other things, passes the current value of the @_ array as arguments to action. See perlsub for more information about stuff like that. update a comment by PodMaster alerted me to something here that may be misleading: &foo; is not the same as &foo();, in that the second will not pass @_ to foo, but the two forms still have different semantics; &foo() will call a user-defined sub over a builtin one (with an empty list of arguments), whereas foo() will not.

HTH

If not P, what? Q maybe?
"Sidney Morgenbesser"


Comment on Re: Flag 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://240027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2015-07-04 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls