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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.