Subject: Grep function inside a for loop does grep the values.
To: [EMAIL PROTECTED]
BCC to: From: [EMAIL PROTECTED]
Date sent: Tue, 19 Feb 2002 17:13:00 -0500
> Can somebody help me on what is wrong in the following piece of code?
>
> foreach (@prv_lst)
> {
> $item = $_;
foreach my $item (@prv_list) {
> @list_prv = grep (/$item/, @txn_log);
The @prv_list contains regexps? Don't you want either
@list_prv = grep (/\Q$item\E/, @txn_log);
or
@list_prv = grep {index $_, $item} , @txn_log;
Also it's not very good to have two arrays, one named @list_prv
and another @prv_list.
> print "The foll. are the Txn details for Trading Partner $item
> \n"; print @list_prv; for (@txn_lst) {
> $aprf = $_;
for my $aprf (@txn_lst) {
> $cnt = 0;
> @list_prv_txn = grep (/$aprf/, @list_prv);
Again does @txn_lst really contain regexps?
Also ... are you sure it's @txn_lst? Isn't it @txt_list ?
Please add
use warnings;
use strict;
on top of your script.
> for (@list_prv_txn)
> {$cnt++};
$cnt += @list_prv;
> print "The number of ${aprf}'s are ${cnt} \n" ;
> }
> }
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]