achak01 has asked for the wisdom of the Perl Monks concerning the following question:

I am having a log file which looks like this

[12/21/10 18:39:20] [OAInstall]
[INFO] Configurable value OPC_BACKUP_DIR is not available in ovconfget for backup directory.
[12/21/10 18:39:20] [OAInstall] [INFO] Creating the log file
[12/21/10 18:39:20] [OAInstall] [INFO] Successfully created the log file
[12/21/10 18:39:20] [OAInstall] [INFO] HP Operations-agent installation action selected.
[12/21/10 18:39:20] [OAInstall] [INFO] Copying HP Operations agent packages is successful
[12/21/10 18:39:20] [OAInstall] [INFO] HP Operations-agent install options are: -install -defer_configure [12/21/10 18:39:20] [oasetup] [oasetup] [INFO] Validating pre-requisites for installation on btovm465.ind.hp.com
Requirements: -------------- [ PASS ] Is user root [ PASS ] Is Operating system Linux [ PASS ] Is architecture X86 [ PASS ] Check if DCE Agent is not installed [ PASS ] 700 MB free disk space required for opt and var together Recommendations: ----------------- [ FAIL ] Check if Open motif is installed Open motif toolkit not installed, xglance functionality will be affecte d.

STATUS: All requirements are OK; at least one recommendation has failed. [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] btovm465.ind.hp.com meets all pre-requisites [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] HP Operations agent installation started on - Tue Dec 21 18:39:21 IST 2010
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Log file for the installation is at : /var/opt/OV/log/oainstall.log
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Checking if Bundle xml file /var/opt/OV/installation/standalone/OVO-Agent.xml is present
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Bundle xml file /var/opt/OV/installation/standalone/OVO-Agent.xml found
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Getting component package file names from /var/opt/OV/installation/standalone/OVO-Agent.xml file
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 1=HPOvXpl.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 2=HPOvSecCo.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 3=HPOvBbc.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 4=HPOvSecCC.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 5=HPOvCtrl.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 6=HPOvDepl.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 7=HPOvConf.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 8=HPOvPacc.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 9=HPOvPerfMI.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 10=HPOvGlanc.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 11=HPOvPerfAgt.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 12=HPOvPerlA.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 13=HPOvAgtLc.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 14=HPOvEaAgt.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Component Package xml file name 15=HPOvOpsAgt.xml
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 0=HPOvXpl.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvXpl.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvXpl.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvXpl.rpm.gz=HPOvLcore
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 0=HPOvXpl
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvXpl package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 1=HPOvSecCo.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvSecCo.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvSecCo.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvSecCo.rpm.gz=HPOvLcore
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 1=HPOvSecCo
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvSecCo package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 2=HPOvBbc.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvBbc.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvBbc.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvBbc.rpm.gz=HPOvLcore
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 2=HPOvBbc
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvBbc package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 3=HPOvSecCC.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvSecCC.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvSecCC.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvSecCC.rpm.gz=HPOvLcore
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 3=HPOvSecCC
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvSecCC package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 4=HPOvCtrl.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvCtrl.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvCtrl.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvCtrl.rpm.gz=HPOvLcore
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 4=HPOvCtrl
[12/21/10 18:39:21] [oasetup]
[oasetup] [INFO] Current HPOvCtrl package version=11.00.060 [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 5=HPOvDepl.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvDepl.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvDepl.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvDepl.rpm.gz=HPOvLcore
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 5=HPOvDepl
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvDepl package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 6=HPOvConf.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvConf.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvConf.rpm.gz=Linux [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvConf.rpm.gz=HPOvLcore [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 6=HPOvConf [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvConf package version=11.00.060 [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 7=HPOvPacc.rpm.gz
[12/21/10 18:39:21] [oasetup]
[oasetup] [INFO] Compression type of package HPOvPacc.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvPacc.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvPacc.rpm.gz=HPOvPerf
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 7=HPOvPacc
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvPacc package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 8=HPOvPerfMI.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvPerfMI.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvPerfMI.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvPerfMI.rpm.gz=HPOvPerf [12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 8=HPOvPerfMI
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Current HPOvPerfMI package version=11.00.060
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compressed Package Name 9=HPOvGlanc.rpm.gz
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Compression type of package HPOvGlanc.rpm.gz=gzip
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] os type of package HPOvGlanc.rpm.gz=Linux
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvGlanc.rpm.gz=HPOvPerf
[12/21/10 18:39:21] [oasetup] [oasetup] [INFO] Package name 9=HPOvGlanc
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Current HPOvGlanc package version=11.00.060
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compressed Package Name 10=HPOvPerfAgt.rpm.gz
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compression type of package HPOvPerfAgt.rpm.gz=gzip
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] os type of package HPOvPerfAgt.rpm.gz=Linux
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvPerfAgt.rpm.gz=HPOvPerf
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Package name 10=HPOvPerfAgt
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Current HPOvPerfAgt package version=11.00.060
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compressed Package Name 11=HPOvPerlA.rpm.gz
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compression type of package HPOvPerlA.rpm.gz=gzip
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] os type of package HPOvPerlA.rpm.gz=Linux
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvPerlA.rpm.gz=HPOvAcc
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Package name 11=HPOvPerlA
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Current HPOvPerlA package version=05.08.091
[12/21/10 18:39:22] [oasetup]
[oasetup] [INFO] Compressed Package Name 12=HPOvAgtLc.rpm.gz [12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compression type of package HPOvAgtLc.rpm.gz=gzip
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] os type of package HPOvAgtLc.rpm.gz=Linux
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvAgtLc.rpm.gz=HPOvEa
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Package name 12=HPOvAgtLc
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Current HPOvAgtLc package version=11.00.060
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compressed Package Name 13=HPOvEaAgt.rpm.gz
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compression type of package HPOvEaAgt.rpm.gz=gzip
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] os type of package HPOvEaAgt.rpm.gz=Linux
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvEaAgt.rpm.gz=HPOvEa
[12/21/10 18:39:22]
[oasetup] [oasetup] [INFO] Package name 13=HPOvEaAgt
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Current HPOvEaAgt package version=11.00.060
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compressed Package Name 14=HPOvOpsAgt.rpm.gz
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Compression type of package HPOvOpsAgt.rpm.gz=gzip
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] os type of package HPOvOpsAgt.rpm.gz=Linux
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Product descriptor of the package HPOvOpsAgt.rpm.gz=HPOvEa [12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Package name 14=HPOvOpsAgt
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Current HPOvOpsAgt package version=11.00.060
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Extracting all the packages.
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvXpl.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvSecCo.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvBbc.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvSecCC.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvCtrl.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvDepl.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvConf.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvPacc.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvPerfMI.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvGlanc.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvPerfAgt.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvPerlA.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvAgtLc.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvEaAgt.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Component package HPOvOpsAgt.rpm.gz extracted successfully
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Installing the HPOvXpl package...
[12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Installing with the "rpm -i /var/opt/OV/installation/standalone/HPOvXpl.rpm" command
[12/21/10 18:39:22] [HPOvXpl] [preinstall] [INFO] Architecture check not deferred for package level, proceeding with architecture check
[12/21/10 18:39:22] [HPOvXpl] [preinstall] [INFO] Determined node architecture: x86
[12/21/10 18:39:22] [HPOvXpl] [preinstall] [INFO] Determined that the package architecture and node architecture are compatible: x86
[12/21/10 18:39:22] [HPOvXpl] [preinstall] [INFO] Determined the packages to be compatible with the node on which installation is being attempted
[12/21/10 18:39:22] [HPOvXpl] [preinstall] [INFO] /var/opt/OV found
* /opt/OV is fine, continuing. [12/21/10 18:39:23] [HPOvXpl] [preinstall] [INFO] Checking for component conflicts
[12/21/10 18:39:23] [HPOvXpl] [preinstall] [INFO] no component conflicts found
[12/21/10 18:39:23] [HPOvXpl] [preinstall] [INFO] Component not configured.Stopping Ctrl will be skipped
[12/21/10 18:39:23] [HPOvXpl] [preinstall] [INFO] Component not configured. Skipping ovtrcd stop
[12/21/10 18:39:24] [HPOvXpl] [postinstall] [INFO] Creating directories under OvInstallDir
[12/21/10 18:39:24] [HPOvXpl] [postinstall] [INFO] Directories created under OvInstallDir
[12/21/10 18:39:24] [oasetup] [oasetup] [INFO] The component package HPOvXpl installed successfully
[12/21/10 18:39:24] [oasetup] [oasetup] [INFO] Installing the HPOvSecCo package...
[12/21/10 18:39:24] [oasetup] [oasetup] [INFO] Installing with the "rpm -i /var/opt/OV/installation/standalone/HPOvSecCo.rpm" command
[12/21/10 18:39:24] [HPOvSecCo] [preinstall] [INFO] Architecture check not deferred for package level, proceeding with architecture check
[12/21/10 18:39:24] [HPOvSecCo] [preinstall] [INFO] Determined node architecture: x86
[12/21/10 18:39:24] [HPOvSecCo] [preinstall]
[INFO] Determined that the package architecture and node architecture are compatible: x86
[12/21/10 18:39:24] [HPOvSecCo] [preinstall]
[INFO] Determined the packages to be compatible with the node on which installation is being attempted
[12/21/10 18:39:24] [HPOvSecCo] [preinstall] [INFO] /var/opt/OV found
[12/21/10 18:39:24] [HPOvSecCo] [preinstall] [INFO] /opt/OV found
[12/21/10 18:39:24] [HPOvSecCo] [preinstall] [INFO] Checking whether SecCore can be installed
[12/21/10 18:39:24] [HPOvSecCo] [preinstall] [INFO] Component not configured. skipping Ctrl stop
[12/21/10 18:39:24] [oasetup] [oasetup] [INFO] The component package HPOvSecCo installed successfully

I have created a code which will give me the install time taken by each component which is somewhat liek this
#!/usr/bin/perl use Time::Local; open(file1,"/var/oalogs/oainstall.linux.log") || die("File not found") +; @data=<file1>; close(file1); @component = (HPOvXpl,HPOvSecCo,HPOvBbc,HPOvSecCC,HPOvCtrl,HPOvDepl,HP +OvConf,HPOvPacc,HPOvPerfMI,HPOvGlanc,HPOvPerfAgt,HPOvPerlA,HPOvAgtLc, +HPOvEaAgt,HPOvOpsAgt); sub install { @cmpstartinstall= grep{/Installing the $component[0] package/}@d +ata; @startime = map {/^\[(.+?)\]/;$1;} @cmpstartinstall; #print "@startime\n"; if($startime[0] =~ /^([\d]+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)/) { $mon = $1; $mon--; $mday = $2; $year = $3; $hour = $4; $min = $5; $sec = $6; if($year =~ /^\d{2}$/) { $year = "20" . $year; } $cmpstart = timelocal($sec,$min,$hour,$mday,$mon,$year);# #print "$cmpstart\n"; } @cmpendinstall = grep {/The component package $component[0] inst +alled successfully/}@data; @endtime = map {/^\[(.+?)\]/;$1;} @cmpendinstall; if($endtime[0] =~ /^([\d]+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)/) { $mon = $1; $mon--; $mday = $2; $year = $3; $hour = $4; $min = $5; $sec = $6; if($year =~ /^\d{2}$/) { $year = "20" . $year; } $cmpend = timelocal($sec,$min,$hour,$mday,$mon,$year);# } $diff=$cmpend-$cmpstart; print "$diff\n"; #print "@cmpendinstall\n" } install();
Can i further tweak it to reduce the coding and make it more efficient.?

Replies are listed 'Best First'.
Re: Need to optimize my perl code
by GrandFather (Saint) on Jan 29, 2011 at 06:59 UTC

    Is there an efficiency issue with the code? How many times too slow is the code?

    Efficiency aside, there is plenty of scope for improving the code. As a first step use strictures (use strict; use warnings;). Then factor out the large lumps of repeated code into a sub. With a few other changes something like the following results:

    use strict; use warnings; use Time::Local; my @data = <DATA>; my @component = qw(HPOvXpl HPOvSecCo HPOvBbc HPOvSecCC HPOvCtrl HPOvDe +pl HPOvConf HPOvPacc HPOvPerfMI HPOvGlanc HPOvPerfAgt HPOvPerlA HPOvAgtLc HPOvEaAgt HPOvOpsAgt ); install ($_) for @component; sub install { my ($component) = @_; my @cmpstartinstall = grep {/Installing the $component package/} @ +data; my @startime = map {/^\[(.+?)\]/; $1;} @cmpstartinstall; my $cmpstart = asEpoch ($startime[0]); my @endtime = map {/^\[(.+?)\]/; $1;} grep {/The component package $component installed successfully +/} @data; my $cmpend = asEpoch ($endtime[0]); return if ! defined $cmpstart || ! defined $cmpend; my $diff = $cmpend - $cmpstart; print "$component: $diff\n"; } sub asEpoch { my ($time) = @_; return if ! defined $time; return if $time !~ /^([\d]+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)/; my ($mon, $mday, $year, $hour, $min, $sec) = ($1, $2, $3, $4, $5, +$6); $mon--; $year += 2000 if $year < 100; return timelocal ($sec, $min, $hour, $mday, $mon, $year); } __DATA__ ... [12/21/10 18:39:22] [oasetup] [oasetup] [INFO] Installing the HPOvXpl +package... ... [12/21/10 18:39:24] [oasetup] [oasetup] [INFO] The component package H +POvXpl installed successfully [12/21/10 18:39:24] [oasetup] [oasetup] [INFO] Installing the HPOvSecC +o package... ... [12/21/10 18:39:24] [oasetup] [oasetup] [INFO] The component package H +POvSecCo installed successfully

    Prints:

    HPOvXpl: 2 HPOvSecCo: 0

    Note that the desired component is passed into the install sub and the entire log is processed for each call to install. That could easily be improved on, but significant changes would be needed to the code.

    True laziness is hard work
      Many Many Thnaks. This is exactly what i was looking for
Re: Need to optimize my perl code
by davido (Cardinal) on Jan 29, 2011 at 06:50 UTC

    Is there a problem with its efficiency? I mean is it running unacceptably slowly (assuming the efficiency you seek is speed)? Is it consuming too much memory?

    You could avoid slurping the file by building @cmpstartinstall and @cmpendinstall on the fly while iterating over the lines of the file. Currently you're slurping the file (which is an unseen loop), then grepping the file for @cmpstartinstall (a second implicit loop), and then grepping the file for @cmpendinstall (a third implicit loop). If you iterated over the file line by line and used push @cmpstartinstall if m/xxxxxxxxxxxxxx/, along with push @cmpendinstall if m/yyyyyyyyyyy/, you reduce the three implicit loops to one explicit one. That way, you're essentially iterating over the file only one time; the time you read it and push lines into @cmpstartinstall and @cmpendinstall.

    But although that may be a more efficient way of handling it (from both the standpoint of memory usage, as well as processor cycles), the gains will not be significant if the file is only a hundred or so lines long. If, in your current version, the time required to read in the file is 1/10th of a second, and the time required to grep through it twice is 1/10th of a second each time, for a grand total of 3/10ths of a second, with a total runtime including startup compilation/interpretation of 1.5 seconds, and the process runs once a week, do you care if you can reduce the execution portion of the script from 3/10ths to 1/10th of a second, with a total footprint of 1.2 seconds once a week?

    On the other hand, if your logfile is millions of lines long, and your current solution bogs down the system by slurping the file and iterating over it three times, and the script takes 2 minutes to execute with a frequency of 5 minutes, you've got a significant problem.

    The first example isn't worth fiddling with except to satisfy curiosity and gain some practice in "best practices." The second example would require entirely rethinking the problem, starting with devising a means of caching results to prevent the need to parse the whole file so frequently.

    Don't get me wrong; I enjoy challenging myself to find more efficient ways of doing things. But from a practical standpoint, you may not really be gaining much.


    Dave

Re: Need to optimize my perl code
by wjw (Priest) on Jan 29, 2011 at 06:08 UTC
    Might want to try Date::Calc for taking care of the time comparisons/calcs....
    • ...the majority is always wrong, and always the last to know about it...
    • The Spice must flow...
    • ..by my will, and by will alone.. I set my mind in motion