-----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Sunday, February 18, 2007 4:15 PM To: Perl Beginners Subject: Re: Inefficient code?
Johnson, Reginald (GTI) wrote: > My code is comparing the variables node and db in one input file to > bkup_node and bkup_db in the other input file. If they match then a > line is written to the output file. While I am getting the desired > output I don't think I am doing this in the most efficient manor. When I > have the print statement turned on I see that the code is still > comparing the same node and db after a match is found. Any advice would > be appreciated. You don't need to store both files in memory and you don't even need the whole lines of the file you do store in memory. You could do something like this: #!/usr/bin/perl use strict; use warnings; open RMANFILE, '<', "/adsm/CRONJOBS/RMAN/rman_out_temp-$today" or die "cannot open rman file: $!\n"; open LASTBKUPFILE, '<', '/adsm/CRONJOBS/RMAN/lastbkup_temp' or die "cannot open last backup file: $!\n"; open OUTFILE, '>', "/adsm/CRONJOBS/RMAN/RMANFILES/rman_out_temp-$today" or die "cannot open out file: $!\n"; my @bkupArray; while ( <LASTBKUPFILE> ) { # Only need to store three fields from '/adsm/CRONJOBS/RMAN/lastbkup_temp' push @bkupArray, [ /^([^_]+)/, ( split /,/ )[ 1, 11 ] ]; } while ( my $line = <RMANFILE> ) { chomp $line; my ( $node, $db ) = split ' ', $line; for my $bkline ( @bkupArray ) { print "node=>$node<= bkup_node=>$bkline->[0]<= db=>$db<= bkup_db=>$bkline->[1]<=\n"; if ( index( $node, $bkline->[0] ) >= 0 && index( $db, $bkline->[1] ) >= 0 ) { print OUTFILE "$line $bkline->[2]\n"; } } } __END__ Can you interpet to my how the regular expression in the code works. push @bkupArray, [ /^([^_]+)/, ( split /,/ )[ 1, 11 ] ]; I understand the slice getting 1 and 11th element but don't get how the regular expression works. -------------------------------------------------------- If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail. http://www.ml.com/email_terms/ -------------------------------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/