what i think is, not simply writing a script...i like to write a script which must take less time to run and less memory use..i like to fine tune my program...
for ex, my program has a subroutine(1 file open &file close and 1print )
2if loops(1 file open &file close and 3print ) and a while loop with split, chomp
3system cmd's, 2if loops..like that..
i like to know:
1).in perl what statements will use less cpu, memory, time to run...
what loops or statments or what are all the things one programmer should try to avoid and what should be included...what r all the best practices?...
2). is that same for perl in both unix and windows?..
3).whether those rules or ideas r same to unix shell scriptiing or not?
Whether you can make a lot of difference with such advice I doubt it, as in my opinion Perl is already very efficient provided you do not use a particularly dumb way to do something. And those advice do not generally make much sense unless you are really familiar with the internals of Perl.
But there are a few obvious observations, though. For example, sequential search for an item in an array is dumb because you need to search for all items before you can tell an item is not in the array. If you use a hash to store the items as keys in the first place, you will get significant performance improvements.
This benchmark test tells you so:
The program generates 50000 items and then try to randomly generate another set of 1000 items to search for in these 50000 items. I expect most if not all of them will not match. Here we comment out line (2) as shown leaving (1) open, and use time() to time the result on my Windows XP system (with cygwin):
$ time perl test1.pl
real 0m0.895s
user 0m0.015s
sys 0m0.015s
Good. Less than 1 sec. Now with the line (1) commented out but not (2):
$ time perl test1.pl
real 4m14.705s
user 0m0.015s
sys 0m0.015s
The search now takes more than 4 minutes to complete. The two only differ in the way of searching. The data generation step is common for both tests. So we can conclude using a bad way to search can hurt performance when the number of searches is large.
Hi folks,
need a small help
lets say i have a text file with the following content:
james
tom
jack
spielberg
i want to append text to the beginning of each line with a variable(lets says FirName:) and i want to combine all the names with a space in between and store it in another... (11 Replies)
Hi Guys,
I need help in scripting out the below :
this is a sample data i have in my file:
jobname type 8:00:00 AM
I need to remove the ":00" from the time field alone.
Thanks in advance for all ur help (8 Replies)
Hi All,
I have a conf file and it has two entries seperated by comma, look like :-
best1,ls /opt/bmc/Patrol3/*/best1
......, .......................
In which "Best1" is the product name and "ls /opt/bmc/Patrol3/*/best1" is the way to find the product version of Best1 in that particular... (5 Replies)
Hello all! Please help me with the following complex regexp which works in egrep:
egrep '\"http:\/\/ccc\.bbb\.com\/documents\/0000\/{4}\/(+\.{3})*\"' my-file.htmlBut silently does not work in sed:
sed "s/\"http:\/\/ccc\.bbb\.com\/documents\/0000\/{4}\/(+\.{3})*\"/aaa/g" my-file.htmlor
sed... (7 Replies)
Hi,
My task is to check the file test.txt every 15 min from Mon-Fri 9:00AM - 6:00PM. We get this file from our mainframes, every 15 min it will update the same file.
My task is to compare file timestamp with current system time stamp and check if the file is updated or not.
If the file doesn't... (0 Replies)
Hello Friends,
I am very new to scripting and currently have come across a situation where I need to create a UNIX script which would look for certain text in a file and then email me if it finds it.
I am trying to trouble shoot an issue with our internet websites and I need to know when I... (1 Reply)
Hello fellas or ladies.
I am new on this site and new to the unix operating system. I have been working with UNIX and i love it so far, i learned some stuff and most of the beneficiary command but I need help renaming all the files in my directory and doing them one by one is just tiring.... (1 Reply)
guys i need bit of help!!
i am writing a script which finds files that have not been accessed for a no of days and delete those files...the no of days value is inputted at the command line....
i am using the following :
find $1 -atime +7 -exec rm -i
in the second step i want to copy all... (2 Replies)
can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files...
pls someone help me on this...
thanking in anticipation.... (1 Reply)
Well I have a new hosting account. I love these guys, because they have everything I need, and give me everything I need, but at the cost of I must configure it myself. I am trying to create a subdomain, and they use raw zone access for dns administration. I have no idea how to configure the zone... (1 Reply)