Parser

Discussion in 'Perl' started by anoop4real, Apr 25, 2007.

  1. anoop4real

    anoop4real New Member

    Joined:
    Dec 18, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,
    Can any one tell me how to parse all the files (*.txt ,*.xml etc) in a folder by taking the folder name as argument and to search for a particular word in that files , I want to write a perl scipt for this, pls give me some pointers.

    Regards,
    Anoop4real
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    You want the directory listing?
     
  3. murugaperumal

    murugaperumal New Member

    Joined:
    Feb 20, 2010
    Messages:
    15
    Likes Received:
    1
    Trophy Points:
    0
    Dear Friend,

    The following coding is used to give your requirement
    Code:
    use strict;
    use warnings;
    use Data::Dumper;
    my $var;
    foreach(@ARGV)
    {
    opendir(DIR,$_);
    my @array=readdir(DIR);
    foreach(@array)
    {
        $var=$_;
        if($var=~/(\.txt|\.xml)/)
        {
         system("grep -lh 'welcome' $var");
        }
    }
    }
    
    :crazy:
     
  4. ungalnanban

    ungalnanban New Member

    Joined:
    Feb 19, 2010
    Messages:
    45
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    Chennai
    Mr.Murugaperumal Why you are posting same answer twice?

    Before Submit your answer see your Preview Image
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice