Created
September 12, 2013 21:15
-
-
Save sashaphanes/6543892 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
############################################################## | |
#This program takes 2 inputs: | |
############################################################## | |
#import files | |
my ($file1, $file2) = @ARGV; | |
die "usage: $0 file1 file2\n" | |
unless $file1 && $file2; | |
#transposing columns and rows | |
my @rows = (); | |
my @transposed = (); | |
push(@rows, [qw(0 1 2 3 4 5 6 7 8 9 10)]); | |
push(@rows, [qw(6 7 3 6 9 3 1 5 2 4 6)]); | |
for my $row (@rows) { | |
for my $column (0 .. $#{$row}) { | |
push(@{$transposed[$column]}, $row->[$column]); | |
} | |
} | |
for my $new_row (@transposed) { | |
for my $new_col (@{$new_row}) { | |
print $new_col, " "; | |
} | |
print "\n"; | |
} | |
#combining files | |
my ($file1, $file2) = @ARGV; | |
die "usage: $0 file1 file2\n" | |
unless $file1 && $file2; | |
use File::Slurp; | |
my @a = read_file($file1) | |
or die "couldn't read $file1 - $!"; | |
my @b = read_file($file2) | |
or die "couldn't read $file2 - $!"; | |
my $combined = {}; # hashref | |
my $i=0; | |
foreach (@a) { | |
chomp; | |
$combined->{$i}{b} = '' unless defined $combined->{$i}{b}; | |
$combined->[$i++]{a} = $_; | |
} | |
$i=0; | |
foreach (@b) { | |
chomp; | |
$combined->{$i}{a} = '' unless defined $combined->{$i}{a}; | |
$combined->[$i++]{b} = $_; | |
} | |
foreach my $i (sort {$a<=>$b} keys %$combined) { | |
print $combined->{$i}{a}, ("\t" x 2), $combined->{$i}{b}, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment