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 19: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]