note
ELISHEVA
<p>Welcome to PerlMonks and Happy New Year!</p>
<p>It looks like you might be confusing variable names and strings. <c>"$pax_$plus"</c> simply creates a string. If <c>$pax</c> is "foo", and <c>$plus</c> is "100", then <c>"$pax_$plus"</c> creates the string <strike><c>"foo_100"</c></strike> <c>"100"</c> , not the variable <c>$foo_100</c>. (see [moritz]'s reply below for why the resulting string is "100" and <i>not</i> "foo_100")</p>
<p>When you want to retrieve data associated with a series of consecutive numbers (i.e. 1 to 4), you need to use an array, like this:</p>
<code>
# use these lines at the start to get Perl help you find
# bugs
use strict;
use warnings;
# Note: declare your variables with "my"
# This helps Perl catch any misspellings in variable names
# and reminds you to set initial values for everything
# price for 0, 1, 2, 3, 4 persons
my @pax = (0, 100, 260, 300, 450);
my $plus = 1;
my $currencycode = 'ZAR';
my $sleeps='';
my $maxadults = 4;
while ($maxadults >= $plus) {
my $paxing = $pax[$plus]; #get $plus member of @pax array
$sleeps = $sleeps . "$currencycode$paxing for $plus persons<br>";
$plus++;
}
</code>
880060
880060