Tool to create Perl based scripts

Discussion in 'Perl Misc' started by IJALAB, Feb 20, 2007.

  1. IJALAB

    IJALAB Guest

    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
     
    IJALAB, Feb 20, 2007
    #1
    1. Advertising

  2. IJALAB

    johngnub Guest

    On Feb 20, 3:52 am, "IJALAB" <> wrote:
    > 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.
     
    johngnub, Feb 20, 2007
    #2
    1. Advertising

  3. IJALAB

    Guest

    On Feb 20, 1:13 pm, "johngnub" <> wrote:

    > @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
    }

    --
    The best way to get a good answer is to ask a good question.
    David Filmer (http://DavidFilmer.com)
     
    , Feb 20, 2007
    #3
  4. IJALAB

    Billy Patton Guest

    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.

    "IJALAB" <> wrote in message
    news:...
    > 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
    >
     
    Billy Patton, Feb 22, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Danielsson
    Replies:
    8
    Views:
    629
    Mike Meyer
    Jul 22, 2005
  2. Jp Calderone
    Replies:
    0
    Views:
    459
    Jp Calderone
    Jul 21, 2005
  3. davidj411
    Replies:
    0
    Views:
    514
    davidj411
    Jun 27, 2008
  4. Replies:
    9
    Views:
    240
    blazar
    Feb 27, 2007
  5. Replies:
    13
    Views:
    533
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page