in reply to Faster Flat File
that being said, there are a few other things you should do. here are some of them:
> use strict! it will save you many, many, problems. and use warnings, too. either by -w on the shebang line, or, if you have perl >= 5.6.0, use warnings;.
> when you open and close files, check that they were successful, and die (or warn, croak, etc.) if otherwise.
> don't use $a and $b as variable names, as these are generally reserved for sort.
> indent properly. your code is missing a closing brace, and is quite difficult to read without proper indentation.
> did you include enough code? what are $s, $r, $m, $p? i'm not sure why you're using the g modifier on your matches.
> if you're not using $rec later on, you don't need it. you can use $_ instead. i wasn't sure, so i left it in your code in my sample below.
here's a list of notes you might want to read:
while or foreach?
Opening files
Use strict warnings and diagnostics or die
perlre
here's an example of the kind of code i'm talking about. i haven't tested it, so i can't say it works. i've removed
#!/usr/local/bin/perl -w use strict; $|++; use FileHandle; my $path = "/path/to"; my $database = "database"; my $DATABASE = new FileHandle; ## what are these? what are they initialized to? my ($m, $p, $r, $s, $p); open ($DATABASE,"< ", $path/$database") or die("ERROR: cannot open database $path/$database! $!"); while(<DATABASE>) { my $rec = $_; chomp($rec); ## not good variable names, be descriptive my ($a, $b, $c, $d, $e, $f) = split(/\|/, $rec); if ($s =~ /$d/g) { if ($r =~ /$e/g){ if ($m =~ /$fa/g){ print "$b\n"; if ($c eq "Y"){ print "$a - tal\n"; } if ($p eq "Y"){ print "$e"; } } } ## ... do more stuff } ## ... do more stuff } close($DATABASE) or die("ERROR: cannot close database $path/$database! $!");
~Particle
|
|---|