in reply to hash or nest loop
I need to take the first x co-ord in file 1, and substract the x value in file 2 from it - repeat for all x values in file 2.
My code:
use strict; use warnings; $|++; use constant X => 0; use constant Y => 1; use constant Z => 2; # take the first x co-ord in file 1 my @f1_coords = do { my $filename = 'file1'; open( my $fh, "<$filename" ) or die "Cannot open '$filename' for reading: $!\n"; my $line = <$fh>; close $fh; split( ' ', $line ); }; # substract the x value in file 2 from it - repeat for all x values in + file 2 my $filename = 'file2'; open( my $fh, "<$filename" ) or die "Cannot open '$filename' for reading: $!\n"; my $outname = 'file3'; open( my $out_fh = ">$outname" ) or die "Cannot open '$outname' for writing: $!\n"; while (my $line = <$fh>) { my @f2_coords = split( ' ', $line ); print $out_fh $f1_coords[X] - $f2_coords[X], $/; } close $out_fh; close $fh;
You will want to read through my code a few times. It contains a ton of Perl idioms that may help you learn your way. Enjoy!
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
|
|---|