note
blue_cowdawg
<ul><ul><i>
</i></ul></ul>
<p>
I modified your code a bit so you can see what's happening:
<code>
use strict;
my $R;
my $i=1;
sub mySub {
printf "\n\n%d. R = \"%s\"\n",$i++,$R;
unless ($R) {
print "CONDITION WORKS\n";
$R = 'some string';
}
}
print mySub(); #prints CONDITION WORKS\nsome string
print mySub(); #prints some string
print mySub(); #again
</code>
This ends up producing this for an output:
<code>
1. R = ""
CONDITION WORKS
some string
2. R = "some string"
some string
3. R = "some string"
some string
</code>
On the first iteration <code>$R</code> is undefined and there for in a "false" state. Therefore your print inside the "unless" gets executed and an assignment gets performed on <code>$R</code>. Where it gets trickier is the next iterations. Since you have <code>unless($R)</code> as the last evalutation the value of <code>$R</code> becomes the return value for the sub since you didn't specify one. see [perldoc://sub] and search for "return" if you want more on this.
</p>
<div class="pmsig"><div class="pmsig-72516">
<hr>
<font size="-2">
Peter L. Berghold -- Unix Professional<br>
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg<br>
</font>
</div></div>
1019982
1019982