PDA

View Full Version : just started yesterday (having some trouble_


wildrover
05-31-2008, 02:28 AM
$r=<STDIN>;
chomp $r;
if ($r == 10) {
print '$r is 10';
} else {
print '$r is something other than 10';
$r=10;
print '$r is set to 10';

say i used "surf" for the stdin.
my little code will say $r does not = 10
instead of it saying "surf does not =10"
i realy dont understand why it would do this.
its realy boggleing my mind.

FishMonger
05-31-2008, 02:48 AM
Use " " double quotes when you need variable interpolation.
$r=<STDIN>;
chomp $r;
if ($r == 10) {
print "$r is 10";
} else {
print "$r is something other than 10";
$r=10;
print "$r is set to 10";
}

When posting code, please use the [code] tags, as I have done, instead of the [quote] tags so that the indentation of the code blocks are preserved.