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++;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|