-----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Monday, February 11, 2008 4:35 PM To: Perl Beginners Subject: Re: hash usage
Johnson, Reginald (GTI) wrote: > I have two input files and I put each into a hash. If the key of one > hash matches the other then I output some values from both. I have > accomplished the output that I want but I want to know if it can be done > in a more efficient manner. Yes. #!/usr/bin/perl use strict; use warnings; my $servername = 'BCCMD1'; open my $ACTLOG, '<', '/home/johnsre/SCRIPTS/BKUPINFO/actlog1269822' or die "actlog file cannot open $!\n"; my %actHash; while ( <$ACTLOG> ) { my ( $actsess, $actmess ) = ( split /,/ )[ 3, 4 ]; $actHash{ $actsess } = $actmess; } close $ACTLOG; open my $SUMMARY, '<', '/home/johnsre/SCRIPTS/BKUPINFO/summary_1269822' or die "summary file cannot open $!\n"; while ( <$SUMMARY> ) { next if /$servername/; chomp; my ( $sumstart, $sumend, $sessnumber, $sessnode, $sumbytes ) = ( split /,/ )[ 1, 2, 4, 5, 12 ]; if ( exists $actHash{ $sessnumber } ) { print "output=>$sessnode,$sumstart,$sumend,$sumbytes,$sessnumber,$actHash{$ses snumber}"; } } close $SUMMARY; __END__ John -- Thank you for the reply. I'm definitely still in the crawl before you can walk stage with perl and hashes. Can you help me understand why I would make the the file handle a scalar $SUMMARY instead of just SUMMARY. Also, I've always shied away from the style of "next if /$servername/;" I interpret this if statement as "if $servername matches then do something else next", right? -------------------------------------------------------- This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing. -------------------------------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/