>>>>> "I" == Icarus <rsarpi@[EMAIL PROTECTED]
> writes:
I> Thanks everybody...here is the final code I crafted from my original
I> and your suggestions.
I> #!/usr/bin/perl
I> use warnings;
I> use strict;
good.
I> my $ca_path = "log_ca.txt";
I> my $aa_path = "log_aa.txt";
I> my %final_re****t;
I> my @[EMAIL PROTECTED]
I> my @[EMAIL PROTECTED]
't declare things before they are used/needed.
I> open (CAFILE, $ca_path) or die $!;
I> my @[EMAIL PROTECTED]
= <CAFILE>;
I> open(AAFILE, $aa_path) or die $!;
I> my @[EMAIL PROTECTED]
= <AAFILE>;
use File::Slurp ;
my @[EMAIL PROTECTED]
= read_file( $aa_path ) ;
simpler and faster. also look below as how it can be used
I> #sort arrays
I> my @[EMAIL PROTECTED]
= sort @[EMAIL PROTECTED]
I> my @[EMAIL PROTECTED]
= sort @[EMAIL PROTECTED]
are you sorting now before you extract the filenames? i haven't
followed this thread closely but this seems wrong to me. but i will go
with it.
you can sort on the output of readfile:
my @[EMAIL PROTECTED]
= sort read_file( $aa_path ) ;
I> my $total_items = @[EMAIL PROTECTED]
don't need that temp variable. see below
I> foreach(@[EMAIL PROTECTED]
){
I> s/\s+\z//; # Remove all trailing whitespace
I> push @[EMAIL PROTECTED]
/\d+->(.+)/;
I> }
you can extract the filename and remove the whitespace in one go:
my @[EMAIL PROTECTED]
= map /\d+->(.+)$/, @[EMAIL PROTECTED]
;
that assumes a simple newline at the end. do you really have more white
space there?
and another merger:
my @[EMAIL PROTECTED]
= map /\d+->(.+)$/, sort read_file( $aa_path ) ;
hmm, one line for seven so far!
of course duplicate this for the other file. i left that to you as an
exercise.
I> for (1..$total_items){
for( 1 .. @[EMAIL PROTECTED]
){
you can just use the array size here.
I> $final_re****t{ pop @[EMAIL PROTECTED]
} = pop @[EMAIL PROTECTED]
I> }
why the loop and pop? try a simple slice:
@[EMAIL PROTECTED]
@[EMAIL PROTECTED]
} = @[EMAIL PROTECTED]
assignment of all the keys/values.
I> print "CA FILENAME => AA_FILENAME\n";
I> print '-' x 27, "\n";
I> foreach (sort { $a cmp $b } keys(%final_re****t) ){
no need for the cmp as sort defaults to a string compare.
I> print "$_ => $final_re****t{$_}\n";
I> }
just a different way to do that:
print map "$_ => $final_re****t{$_}\n", sort keys %final_re****t ;
uri
--
Uri Guttman ------ uri@[EMAIL PROTECTED]
-------- http://www.sysarch.com
--
----- Perl Code Review , Architecture, Development, Training, Sup****t
------
--------- Free Perl Training --- http://perlhunter.com/college.html
---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com
---------


|