in reply to Re^4: a little problem with sorting my data
in thread a little problem with sorting my data
I think you need to sort <SW> rather than <RW>
It is good that you have added 'use strict' and declared all your variables with 'my'. It is generally best to declare your variables in the smallest possible scope, rather than declaring them all at file scope.
You are chomping $eachline and $eachline1, which you are not setting or using. These statements can be removed.
It is better to use the three argument form of open
The following is untested, as I have no input data to test with.
use strict; use warnings; # An input LOG file which holds information about different users. my $file_name = "QoEWeb_DB_Log.txt"; open(my $sw, '<', $file_name) or die "$file_name: $!"; #Will write the result into an OUTPUT file. open(my $file, '>', 'output.txt') or die "output.txt: $!"; foreach ( sort { $a->[8] <=> $b->[8] } map { [ split /:/ ] } <$sw> ) { my ($field1, $field2, $key1, $field5) = @$_[2,4,8,6]; my @file_name1 = ("Carlo_Arnold_2.232_Final.txt", "Sohaib_Ahma +d_2.225_Fi nal.txt"); #Input LOG files; Each file holds informaton about Individu +al user. I will be adding about 30 files here. foreach my $file (@file_name1) { open(my $rw,$file) or die "$file: $!"; while (<$rw>) { my @ff_array = split(/:/,$_); #Taking required + fields fr om the second set of input files. my $key2 = $ff_array[0]; my $field3 = $ff_array[1]; if( $key1 == $key2) # Finding a match between +the two in put files { print $file "$field1:$field2:$key1:$f +ield5:$fie ld3"; #Printing the desired result from both batch of input files. } } close($rw) or die "ERROR CLOSING FILE: $!"; } } close $file or die "ERROR CLOSING FILE: $!"; close $sw or die "ERROR CLOSING FILE: $!";
|
|---|