in reply to Variable auto creation
You could do this:
#!/bin/perl -w my( $_var, $_val)= split /\s*=\s*/, $ARGV[0]; die "can't use $_var as a variable name" if( $_var=~ /^_va[rl]$/); ${$_var}= $_val;
This is higly unsafe though, you cannot use strict (at least not strict 'refs') and you risk overwriting one of you existing variables.
Why not just use a hash:
#!/bin/perl -w use strict; my( $_var, $_val)= split /\s*=\s*/, $ARGV[0]; my %hash=( $var => $val);
If you call both snippets with foo=bar as argument The first one lets you use $foo and the second one $hash{foo}.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Variable auto creation
by darkomen (Acolyte) on Sep 28, 2000 at 17:17 UTC | |
by ar0n (Priest) on Sep 28, 2000 at 17:43 UTC |