For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > compare speed problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author compare speed problem
Brent Clark

2005-08-08, 9:04 am

Hi all

I have some code (seen below) and for some reason it runs really,
sllooooowwww.
I have narrowed it down to the $p110rm0X eq $roomName. In the subroutine
compareRmNames

So basically my question is, is there a way to quicken the compare the
two strings.
I have commented out the adding the value to a new array.

Also I need to state, please dont shoot me on this code, I just got
passed on too.

If anyone can help, it would be most appreciated.

Kind Regards
Brent Clark

#------------------------------------------------------------------------------------------
sub updateDatFile {
#------------------------------------------------------------------------------------------

foreach my $fileName ( keys %$ref_allTariffData ){
next unless -e "$fileName.dat";
open (HDATFILE, "<$fileName.dat") or die "Cant open file
$fileName.dat $!";

print " Opened $fileName.dat <br />\n";
flock (HDATFILE, LOCK_SH) or die "Cant lock file $fileName.dat $!";
while(<HDATFILE> ){
chomp;
if(m/^(p110|p111|p116)/o){
print &compareRmNames($fileName, $_);
}else{
print TEMPHDATFILE "$_\n";
}
}

flock (HDATFILE, LOCK_UN) or die "Cant unlock file $fileName.dat $!";
close (HDATFILE) or die "Cant close file $fileName.dat $!";
}

#------------------------------------------------------------------------------------------
}
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
sub compareRmNames {
#------------------------------------------------------------------------------------------
my ($fileName, $currentLine) = @_;
my @resultant = ();
my @keys = ();
my $roomName = shift;
@linex = split(/\|/, $currentLine);

if ( $currentLine =~ m/^p110/io ){
&p110;
}elsif( $currentLine =~ m/^p111/io ){
&p111;
}elsif( $currentLine =~ m/^p116/io ){
&p116;
}
foreach my $roomName ( keys %{ $ref_allTariffData->{$fileName} } ){

$roomCode = $ref_allTariffData->{$fileName}{$roomName};
print "Room $roomCode <br />\n";

if( $p110key eq 'p110'){ #Speed problem starts here
if ($p110rm01 eq $roomName ){
# $resultant[0] = "$roomName|";
# $keys[0] = "$roomCode|";
}elsif ($p110rm02 eq $roomName){
# $resultant[1] = "$roomName|";
# $keys[1] = "$roomCode|";
}elsif ($p110rm03 eq $roomName){
# $resultant[2] = "$roomName|";
# $keys[2] = "$roomCode|";
}elsif ($p110rm04 eq $roomName){
# $resultant[3] = "$roomName|";
# $keys[3] = "$roomCode|";
}elsif ($p110rm05 eq $roomName){
# $resultant[4] = "$roomName|";
# $keys[4] = "$roomCode|";
}elsif ($p110rm06 eq $roomName){
# $resultant[5] = "$roomName|";
# $keys[5] = "$roomCode|";
}elsif ($p110rm07 eq $roomName){
# $resultant[6] = "$roomName|";
# $keys[6] = "$roomCode|";
}elsif ($p110rm08 eq $roomName){
# $resultant[7] = "$roomName|";
# $keys[7] = "$roomCode|";
}elsif ($p110rm09 eq $roomName){
# $resultant[8] = "$roomName|";
# $keys[8] = "$roomCode|";
}elsif ($p110rm10 eq $roomName){
# $resultant[9] = "$roomName|";
# $keys[9] = "$roomCode|";
}else{
print "Problem with $fileName p110 $roomName ";
}

if (scalar(@keys) ne 10){
for (1..(10-(scalar @keys)) ){
push @keys, "|";
push @resultant, "|";
}

}
}


return The string of the arrays @resultant and @keys
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com