in reply to How do read the varibles from a files and do some calculation

Probably it is better to simply use split, so that you don't need to worry about things like the format of the number.

use strict; use warnings; my ($A, $B, $C, $D); while (<DATA>) { chomp; my @parts = split /\|/; print "\$$parts[0] = $parts[1]\n"; eval("\$$parts[0] = $parts[1]"); } print "$A\n"; print "$B\n"; print "$C\n"; print "$D\n"; __DATA__ A|-10 B|20_000 C|20.1234 D|2E-3

Then you can do whatever you want with those variables.

Replies are listed 'Best First'.
Re^2: How do read the varibles from a files and do some calculation
by ikegami (Patriarch) on Oct 21, 2004 at 18:52 UTC

    If he wants a more flexible number format than \d+, one of the perlfaqs gives a regexp that matches what Perl considers a number.

    Your code handles A|system("rm -rf /") quite interestingly. If you call that a feature (plausible), then A|$B||$C is buggy. Using split(/\|/, $_, 2) instead of the current split solves it.

    Your code also handles A = system("rm -rf /")|0 quite interestingly, and I can't see that being called a feature.

      one of the perlfaqs gives a regexp that matches what Perl considers a number

      That would be perldoc -q whole, also available online.