in reply to defining a new var on the spot
This question has been asked so many times... ;-(
You don't want to do this. It is dangerous. See Dominus's expalnations on Why it's stupid to 'use a variable as a variable name'.
If you don't know the name of the array, then use a hash:
#!/bin/perl -w use strict; my %tmp; while( my $tmp=<DATA>) { if( $tmp=~ /^(.+)(\d+)$/) { $tmp{$1}->[$2]= 'foo'; # don't you love auto-vivification? } } __DATA__ foo2 foo5 foo0 bar bar2 bar1 foo3
|
|---|