Bobby wrote:
"John W. Krahn" <[EMAIL PROTECTED]> wrote: Bobby wrote:
Bobby wrote:
open EXCLUDE, '<', $exclude_psc or die "Could not open
'$exclude_psc' $!";
while ( <EXCLUDE> ) {
next if $. == 1; # exclude header
chomp;
my ($excpsc,$keyword) = split /\|/;
%ex_psc = (exclpsc=>$excpsc,exkeyword =>$keyword );
You are assigning to the hash so it will only contain data from the last
record in the 'exclude_psc.txt' file. For more efficiency use
File::ReadBackwards and only read one record.
}
close EXCLUDE;
I don't understand, why would that only get me the last record in the
text file?
When you assign something to a variable any previous contents are
replaced by the new contents. So the second record is replaced by the
third record, the next time through the loop the third record is
replaced by the fourth record, the next time through the loop the fourth
record is replaced by the fifth record, etc., until the second-to-last
record is replaced by the last record.
Is there a better way to do that?
I would assume that you probably want to use $excpsc as the key and
$keyword as the value? It all depends on what your data looks like so I
can't be more definitive without seeing the data.
while ( <EXCLUDE> ) {
next if $. == 1; # exclude header
chomp;
my ( $excpsc, $keyword ) = split /\|/;
$ex_psc{ $excpsc } = $keyword;
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/