in reply to reading from a file and initializing a variable
UPDATE:corrected a type, I meant hash, not bash!
Hi,
It's doable, but, please read the other comments first: it's a whole lot better to stick with a hash!
#!/usr/bin/perl use strict; use warnings; # but you really don't want to do this # stick with a hash! # here we have 3 vars, but what if if there's more than 3? my ($step1,$step2,$step3); while (<DATA>) { my $line = $_; chomp $line; my ($var,$val) = split / /, $line; eval "$var=$val"; } # here we have 3 vars, but what if if there's more than 3? print $step1 . "\n"; print $step2 . "\n"; print $step3 . "\n"; __DATA__ $step1 1 $step2 1 $step3 1
|
---|