Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Welcome to the Monastery
 
PerlMonks  

Re: Breaking out of an 'if'

by ikegami (Patriarch)
on Apr 14, 2005 at 15:34 UTC ( [id://447928]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Breaking out of an 'if'

if ($some_condition) { some_stuff(); if (!$some_condition2) { some_more_stuff(); } }

or

if ($some_condition) { some_stuff(); } if ($some_condition && !$some_condition2) { some_more_stuff(); }

or

IF: { if (some_condition) { some_stuff(); last IF if $some_condition2; some_more_stuff(); } }

btw, don't use & on function calls unless you must. It causes Perl to behave differently if the function has a prototype.

Replies are listed 'Best First'.
Re^2: Breaking out of an 'if'
by jpfarmer (Pilgrim) on Apr 14, 2005 at 15:42 UTC
    Can you explain the difference between the two methods of calling?

      The prototype is ignored when & is used.

      use strict; use warnings; sub testing(\@) { my ($arg) = @_; print("First argument: ", $arg, "\n"); $arg->[5] = 'e'; } my @a = qw( a b c d ); print("Test 1:\n"); testing(@a); print("\n"); print("Test 2:\n"); &testing(@a); print("\n"); __END__ output ====== Test 1: First argument: ARRAY(0x1ab2780) Test 2: First argument: a Can't use string ("a") as an ARRAY ref while "strict refs" in use at ! +.pl line 8 .

      It also varies the behaviour of function calls with no parens:

      sub testing { print("[@_]\n"); } sub test1 { testing; } sub test2 { &testing; } print("Test 1:\n"); test1(); print("\n"); print("Test 2:\n"); test2('moooo'); print("\n"); __END__ output ====== Test 1: [] Test 2: [moooo]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://447928]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.