Welcome to PerlMonks and Happy New Year!
It looks like you might be confusing variable names and strings. "$pax_$plus" simply creates a string. If $pax is "foo", and $plus is "100", then "$pax_$plus" creates the string "foo_100" "100" , not the variable $foo_100. (see moritz's reply below for why the resulting string is "100" and not "foo_100")
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:
# 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++; }
In reply to Re: Getting Value from joining 2 variables
by ELISHEVA
in thread Getting Value from joining 2 variables
by Noverast
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |