Sumit Shah wrote:
Hello All,
Heloo,
I have a string like: 'a = 1; b = 2; c = 3; d = 4'
Whats the best way to parse it so that I can get a value for c, which is
3? I have used the hash approach. But, I was wondering if there is a
faster way to do it in Perl.
Why do you say hashes are slow? Did you actuially benchmark however you
were doing it?
my $string = 'a = 1; b = 2; c = 3; d = 4';
my %stuff = $string =~ m{\s*(\D+) = (\d+)\;?}g;
use Data::Dumper;print Dumper \%stuff;
Auto creating variables is genrally a bad idea:
1) $a and $b are not to be used (perldoc -f sort)
2) what if there's $e, $f, $g etc but maybe no $cm how do you tell if
it exists() ? how can you loop thought them all?
3) what if they try to get sneaky and use data that give them access
of some sort?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/