Please let me know how to do the same
So far this the below code
use strict;
use warnings;
open (my $data , '<', $ARGV[0])|| die "could not open $ARGV[0]:\n$!";
my @array=(<$data>);
my @sorted=sort {(split(/\|/,$a))[2]<=>(split(/\|/,$b))[2]} @array;
print @sorted;
Please let me know how to open the array from a file
Thanks a lot for replying .I know the requirement is weird
The point is after sorting two files I have to compare files to each other
Is there any way I can do like this
open my $fh1, '<', @sorted or die "Can't open $file1: $!";
I have to do the following
while (<$fh1>){
chomp;
my @rec = split /\|/;
my $key = $rec[2];
$save{$key}->{'data'} = $_; #Save current record in hash
$save{$key}->{'flag'} = 'D';
}
If all you want to do is sort and compare two files, then simple Unix commands could do the job.
Maybe posting your representative data could give someone an idea of what you are trying to accomplish.
The point is I can't use unix(although I loveeeee it ) because people who pay me asked me to use only perl.
So you guys are my savior
The code is attached
You can see that in the below code 3 files are opening
open my $fh1, '<', $file1 or die "Can't open $file1: $!";
open my $fh2, '<', $file2 or die "Can't open $file2: $!";
open my $fh3, '>', $file3 or die "Can't open $file3: $!";
I want to open the sorted file instead of file1,file2
Is there a way I can use
open my $fh1, '<', @sorted or die "Can't open $file1: $!";
I am sure if you explain to them how Unix can make their and your lives easier, they'll be willing to lend an ear. Otherwise install Cygwin in Windows to take advantage of a Unix-like environment on Windows.