You can use map, I've set this up two ways, the @elements array uses the references the way you use them in your code. I call map to do the substition, at that point you can print it out however you like, I used Data::Dumper so you can see what the var structure looks like. In the second example @elems2 I did away with the references, with subtle changes to the map function(I do not dereference $_) BTW, $_ can be dropped at that point, but I wanted to keep it symmetrical with the other map. Notice how the first Data::Dumper output shows that the elements array contains references to the strings and the second contains the strings.
#!/usr/bin/perl use Data::Dumper; $hall_name="Foo's Hall"; $contact_name="Prof Bar"; $contact_email="profbar\@fooshall.edu"; $contact_telephone="1'234'567'8901"; my @elements = ( \$hall_name, \$contact_name, \$contact_email, \$contact_telephone ); my @elems2 = ( $hall_name, $contact_name, $contact_email, $contact_telephone ); map { $$_ =~ s/'//g } @elements; print Dumper(\@elements); map { $_ =~ s/'//g } @elems2; print Dumper(\@elems2); __END__ #Output looks like: $VAR1 = [ \'Foos Hall', \'Prof Bar', \'profbar@fooshall.edu', \'12345678901' ]; $VAR1 = [ 'Foos Hall', 'Prof Bar', 'profbar@fooshall.edu', '12345678901' ]; # As you can see the first one contains the references, # And the second does not.
HTH
In reply to Re: Storing an array of variables
by pzbagel
in thread Storing an array of variables
by CodeJunkie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |