in reply to scope of my $x in if statements
Setting aside why you want to do this, how about:
That example seems to do all that you want.#!/usr/bin/env perl use strict; sub f { return 2; } sub g { my ($y) = shift @_; return $y*2; } if ( my $k = g(my $x = f()) ) { print "If the answer is four I'm happy. Answer == $k\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: scope of my $x in if statements
by ikegami (Patriarch) on May 07, 2009 at 20:49 UTC | |
by mikeraz (Friar) on May 07, 2009 at 20:54 UTC | |
by ikegami (Patriarch) on May 07, 2009 at 21:05 UTC |