Home: Perl Programming Help: Intermediate:
Routine to catch exp...



jkepler
Novice

Jul 25, 2014, 2:29 PM


Views: 1677
Routine to catch exp...

Hello,

I'm trying to make a routine to catch some expressions from a file. I'm assuming, wrongly, that can only be one in each line...
I'm capturing and appending the expressions like this:


Code
sub Grab($filename){ 

open (file1, "<$filename") or goto cont2;

while (<file1>){
my($line) = $_;

my ($exp) =
$line =~ m/
kepler_ # Required
(.+?) # Capture Desired Output
(:?\s\(|\(|\s+) # One required - no capture
/xi;

$expr = "kepler_".$1;
if(@Functions =~ /$expr/gi){goto cont1;}
if($1 =~ ""){goto cont1;}
$n += 1;
print $expr."\n";
$value1 = "Exp_".$n;
$key1 = $expr;
$functions{ $key1 } = $value1; # hash, using variables

cont1:
}
cont2:
close file1;
}
#END GRAB


The problem is that I'm getting duplicated items in the hash.
And, that can be more expressions in one line - but probably not...

Can anyone help me out here?

Kind regards,

Kepler


FishMonger
Veteran / Moderator

Jul 25, 2014, 5:34 PM


Views: 1669
Re: [jkepler] Routine to catch exp...

Cross posted on perlmonks.

http://www.perlmonks.org/?node_id=1095102