Hi,
I am reading a file and fetching only the records which matches the condition. I am using the following code block to do the matching. This works fine for the 1st iteration of the outer loop. after that point its just not working .
Input to the script will be like this -c="field1","field2","field3=value1","field4=value2,value3";
all conditions are ANDed. field4 is vslue2 or value3 ....
I am building (%conwithposition) with the position of the fileds,operator and ref to values(array if more then one vslue)
i am using the following code block. My aim is to put all the line matching the 1st cond in a temp array and use the same for further checking.
i have problem while pushing line(record) into @arraynew. Its only giving reference. I want to build a two-dimentional array of matched record.
my $arrayref =\@array;
my @arraynew;
foreach $key_pos(keys(%conwithposition)) {
#print "KEYLOOP::(@{$conwithposition{$key_pos}}[1],@{$conwithposit
+ion{$key_pos}}[2])\n";#,$line[@{$conwithposition{$key_pos}}[0]])\n";
$i=0;
#print "ARR:@arraynew\n";
file:for (@$arrayref) {
my $match = 0;
my @line = split /\t/;
#print "Line:::@$arrayref\n";
my @tmp;
my ($op, $arg1, $arg2) = (@{$conwithposition{$key_pos}}[1],@{$
+conwithposition{$key_pos}}[2],$line[@{$conwithposition{$key_pos}}[0]]
+);
$match = is_match($op,$arg2, $arg1);
if ($match){
push @tmp,@line[@sorted_cols];
print "@tmp\n";
}
push @arraynew,[@tmp];
$i++;
}
$arrayref = \@arraynew;
}
print "Result: @tmp\n";
sub is_match{
my ($operator,$valuesrc,$inputval_ref)=@_;
my $i;
if (ref $inputval_ref eq 'SCALAR'){
return 1 if ($valuesrc eq $$inputval_ref);
}
if (ref ($inputval_ref) eq 'ARRAY'){
my @valuetomatch=@$inputval_ref;
for $i(0 .. $#valuetomatch){
return 1 if ($valuesrc eq $valuetomatch[$i]);
}
}
return 0;
}
Can anybody correct my mistake?
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.