-59.077 89.301 115.664 7 -61.251 77.435 117.760 -6 -60.950 71.712 116.061 -7 -56.247 83.685 114.576 1 -59.263 76.107 112.555 -2 -59.895 65.296 111.185 3 -60.141 63.694 111.257 -3 -61.667 63.707 116.937 2 -58.722 60.429 111.307 -1 -57.511 42.922 112.108 6 #### 7 -59.077 89.301 115.664 -7 -60.950 71.712 116.061 #### -6 -61.251 77.435 117.760 6 -57.511 42.922 112.108 #### -1 -58.722 60.429 111.307 1 -56.247 83.685 114.576 #### 7 1 -59.077 89.301 115.664 -7 3 -60.950 71.712 116.061 #### -6 2 -61.251 77.435 117.760 6 10 -57.511 42.922 112.108 #### -1 9 -58.722 60.429 111.307 1 4 -56.247 83.685 114.576 #### #!/usr/bin/perl use warnings; use strict; open my $target, '>', "test-out-1" or die $!; open my $FILE, '<', 'input_file' or die $!; while (<$FILE>) { chomp; my @columns = unpack('a8 a8 a8 a6'); #print join(" ",map {$_} @columns), "\n"; #print "@columns[3] \n"; foreach (@columns[$#columns]) { print "$_ \n"; if ($_ =~ /-7/) { my $ID = $_; my $IDform = sprintf ("%4s", $ID); my $currentline = $.; my $currentlineform = sprintf ("%7s", $currentline); my @selection = (@columns[0..$#columns-1]); my $layout = "%10s"x(@selection) . "\n"; printf $target $IDform . $currentlineform . $layout, @selection; } } } #### -7 418 -17.459 -3.557 123.002 -7 419 -19.119 -2.327 121.948 -7 421 -18.172 -5.439 122.677 -7 423 -21.239 -5.003 128.245 -7 424 -17.575 -3.567 124.891 -7 425 -19.519 1.088 136.199 -7 426 -17.135 -5.042 124.510 -7 427 -19.539 -2.356 127.619 -7 429 -16.867 0.671 123.725 -7 430 -19.638 8.992 126.487 -7 431 -19.731 13.090 129.183 -7 432 -17.846 15.834 128.342 -7 440 -20.265 16.101 127.072 #### #!/usr/bin/perl use warnings; use strict; my $match; my @match = (); push (@match, $match); # I fear this is what I'm doing wrong - I'm not putting $match in @match correctly. @match = (-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); my $value = abs($match); # Here I'm trying to establish a variable that will basically be the absolute value of the fourth column of my input file, this is what I want to match. open my $target, '>', "test-out-$value" or die $!; open my $FILE, '<', 'input_file' or die $!; while (<$FILE>) { chomp; my @columns = unpack('a8 a8 a8 a6'); #print join(" ",map {$_} @columns), "\n"; #print "@columns[3] \n"; foreach (@columns[$#columns]) { if ($_ =~ /$value/) { my $ID = $_; my $IDform = sprintf ("%4s", $ID); # Also here I'm confused and I can't think about how to write what I want. I want to match the absolute value (a few lines above), but print the actual value (in my output file), not the absolute one. This worked easily in my first code (where I matched for specific number) but now I can't think how to write the general version. my $currentline = $.; my $currentlineform = sprintf ("%7s", $currentline);## my @selection = (@columns[0..$#columns-1]); my $layout = "%10s"x(@selection) . "\n"; printf $target $IDform . $currentlineform . $layout, @selection; } } }