Tool to create Perl based scripts

I

IJALAB

Hi All,

I have to automate a lot of validation scripts in Perl. Is there a
simple way/tool to do the same. basically log files will be created
and i have to look for certain keywords in the log files and make a
decision to validate the tests. I am just looking to save time in
automating my perl writing task.
any pointers welcome..thanks a lot

regards
bala
 
J

johngnub

Hi All,

I have to automate a lot of validation scripts in Perl. Is there a
simple way/tool to do the same. basically log files will be created
and i have to look for certain keywords in the log files and make a
decision to validate the tests. I am just looking to save time in
automating my perl writing task.
any pointers welcome..thanks a lot

regards
bala

Well, Not a CS major, but willing to try ..Some step by step tasks,
und allways in Perl, more then one way around the barn to milk the
cow...

# To open a file:
open (IN,"<some.dat");
@then = <IN>;close (IN);

# Now then has data, info from the file

To loop over a file, the array of lines from the file, in the array
then:
foreach $line (@then){
# To see if it has "fun", simple match,
if ($line =~ /fun/ ) {
print "OH fun!\n";
}
# simiple but usefull regex meta opers, ,
# \s+ equiv to spaces, \S+ equiv to words that are not spaces, \d+
digits,
# To see if its a word then fun, thus ich bin "foo fun bar"
if ($line =~ /\S+\s+fun\s+\S+/ ) {
print "A word then fun and a word.\n";
}
# close out the loop, hint use the "%" key in vi to spy the (){} of
life.
}
# The end.

# PS: put the car in 1st gear, then step on the pedal, NASCAR is not a
good way to learn how to drive. Yada. jb.
 
U

usenet

@then = <IN>; ......
foreach $line (@then){

Never, ever, ever read a file into an array if your only intention is
to process the file line-by-line.

Just read each line and process it as it is read:

foreach my $line(<$in>) { #and use lexical filehandles
#do something with each $line
}
 
B

Billy Patton

I prefer perl above all other languages. But sometimes it's not the best
language for the job.
If you are simply looking for keywords within a file I would suggest using
csh,sh,ksh,bash or zsh to do simple grep commands.
It's very fast. If, your on a unix box, cygwin, mingw or mac osx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top