in reply to How can I enter the data of different variables from a text file into a perl program?
You should probably read them into a hash:
my %vals; open my $infile, '<', 'data.txt' or die $!; while( <$infile> ) { chomp; my( $identifier, $value ) = split /\s*=\s*/; $vals{$identifier} = $value; } close $infile; my $calculation = $vals{x1} * $vals{y1}; $calculation = ( $vals{x1} * $vals{y1} ) / $vals{x2};
I gather you had something else in mind, such as importing the identifiers as fully fledged variables into your program, which is often (meaning almost always) a bad idea. For reference on that topic:
Symbolic references are incredibly useful under the right circumstances. And in the general course of writing a well designed Perl program those circumstances are rare.
Dave
|
---|