The answers above seem spot on in explaining where the problem is in your code, so I won't repeat their solutions here. Might I suggest you try a different approach than storing scalar references in an array though. What you are describing here seems a perfect opportunity to use a hash structure instead of scalar vars and an array. Try something like this (untested) code instead:

my %elements = ( hall_name => $hall_name, contact_name => $contact_name, contact_email => $contact_email, contact_tel => $contact_tel, ); while (my($key, $value) = each %elements) { print "$key -> $value<br />"; $value =~ s/'//g; } - or - foreach my $line (values %elements) { ... }

By using a hash, you are keeping all your data in one structure making the code clearer, and it makes it easier to pass this information to other methods or subroutines.

The only real issue here is that hashes don't preserve order like arrays do, so if you require a specific order when printing these values you may need to look at alternative solutions (like Tie::IxHash). But since it looks like you are outputting HTML, you should really look at a templating system like HTML::Template or Template Toolkit which work well with hashes of data.


In reply to Re: Storing an array of variables by cees
in thread Storing an array of variables by CodeJunkie

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.