in reply to Storing an array of variables
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.
|
|---|