in reply to Re: Array reference
in thread Array reference

well.. I also know that no body wants to write a code for free.. I have asked for the help not for the entire code..

#!/usr/bin/perl use strict; open (FILE, "ip.txt") || die "can't: $!"; open (OUTPUT,">op.txt") || die "can't: $!"; my @lines=(); my @l1=(); my @l2=(); @lines=<FILE>; my %hash=(); my $i=0; my $j=$i+1; my @arr1=(); my @arr2=(); my @arr3=(); while($j <= $#lines) { #print "$j\n"; @l1=split(/\t/,"$lines[$i]"); @l2=split(/\t/,"$lines[$j]"); if(abs($l2[3]-$l1[3]) <= 500 && $l1[6] eq $l2[6]) { $hash{$lines[$j]}=1; if(!exists $hash{$lines[$i]}) { $hash{$lines[$i]}=1; push(@arr1,$l1[3]); push(@arr2,$l1[7]); push(@arr3,$lines[$i]); #print OUTPUT "$lines[$i]"; } #print OUTPUT "$lines[$j]"; push(@arr1,$l2[3]); push(@arr2,$l2[7]); push(@arr3,$lines[$j]) } else { @s_arr2=sort{$a<=>$b}@arr2; if($s_arr2[-1]-$s_arr2[0] <= 500) { //got struck $i=$j; $j=$i+1; }

Thanks.

Replies are listed 'Best First'.
Re^3: Array reference
by JockoHelios (Scribe) on Jun 12, 2013 at 23:31 UTC
    Now that I have some script to examine, I have a question and a few observations.

    From the input and desired output you posted, it appears that you want to sort on the last field in each array, then remove any row based on the difference in that last field. Is that correct ?

    First, my @s_arr2 must be declared for this line

    @s_arr2=sort{$a<=>$b}@arr2;

    Then, on this line

    if(abs($l2[3]-$l1[3]) <= 500 && $l1[6] eq $l2[6])

    are you intending to subtract text fields in the abs section ? Based on your data, you're subtracting "mir" from "mir" because Perl array indices start with zero.

    Also on that same line, if you meant

    abs($l2[2]-$l1[2]) <= 500

    to do subtractions on the 70, 90, 100, 120 values, those differences won't come close to 500, so no row would be deleted based on that result.

    Dyslexics Untie !!!