in reply to Array reference

from Do your own work ¹ ²

> Asking for help is one thing, but requesting us to just do your work for you for free is not going to happen - you should ask the kind folks at the perlguru's I need a program that... forum instead.

Cheers Rolf

( addicted to the Perl Programming Language)

¹) for those getting locked out, sorry! Deep linking [id://172086#your_work] didn't work! And this is to general.

²) corrected link, thx ano-monk for link to workaround

Replies are listed 'Best First'.
Re^2: Array reference
by rkk (Novice) on Jun 12, 2013 at 22:55 UTC

    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.

      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 !!!
Re^2: Array reference
by Anonymous Monk on Jun 13, 2013 at 00:24 UTC