Douglas Houston wrote:

> Hi,
> 
> I am trying to initialize a dynamically-named array, i.e. with the
> following test code (if I type "script.pl char" at the command prompt) I
> get the message "array char contains 1 2 3" but I get a warning if 'use
> strict' is on. Can anyone show me how it should be done (I would like to
> use 'use strict'!)?
> 
> #!/usr/bin/perl -w
> #use strict;
> my ($string);
> 
> while (<$ARGV[0]>) {
>   chomp($string=$_);
>   @$string = (1,2,3);  #Won't work if 'use strict' pragma is used
> }
> 
> print "array $string contains @$string\n";

this normally can't be done cleanly and is generally not recommanded given 
there are other ways to accomplish bascially the same thing. but if you are 
here to see if it can be done at all, you might want to try something like:

#!/usr/bin/perl -w
use strict;

my $name = shift;

eval <<CODE;
no strict;
@ $name=1..3;
print "\$_\\n" for(@ $name);
CODE

#--
#-- print it again after eval
#--
while(my($k,$v) = each %::){
        next unless($k =~ /^$name$/);
        local *sym = $v;
        print join("\n",@main::sym),"\n";
}

__END__

prints:

1
2
3
1
2
3

david
-- 
$_='015001450154015401570040016701570162015401440'
,*,=*|=*_,split+local$";map{~$_&1&&{$,<<=1,$#.=qq~
/[EMAIL PROTECTED]||3])=>~}}0..s,.,,g-01;*_=*#,s
[[s/eval+w/.`9`/e]]n\\xng.print+eval(eval"qq`$_`")

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to