Match line by line

Discussion in 'Perl Misc' started by vincente13@gmail.com, Jun 5, 2006.

  1. Guest

    Hi all..

    my $jarFile = "input.jar";
    my $content = qx/jar tf $jarFile/;

    $content contains the list of files in the jar file.


    META-INF/
    META-INF/MANIFEST.MF
    searchjar/
    searchjar/JARFileFilter.class
    searchjar/Main.class

    In the program, i would like to use regex to match line by line to
    check if a specified string exists in it.

    my $userInputString = "Main.class";

    if(@match = $content =~ m/$userInputString/gs){
    print "File is found:\t";
    print @match;
    }

    How can i achieve to print out the result of "searchjar/Main.class"

    Appreciate any help
     
    , Jun 5, 2006
    #1
    1. Advertising

  2. Guest

    i guess i probably do it this way..
    correct me if there is anything wrong

    foreach my $item (split(/\n/, $content)) {
    if ($item =~ /$userInputString/) {
    print "\n\n", $item;
    }
    }

    spilt it with \n and compare it line by line


    wrote:
    > Hi all..
    >
    > my $jarFile = "input.jar";
    > my $content = qx/jar tf $jarFile/;
    >
    > $content contains the list of files in the jar file.
    >
    >
    > META-INF/
    > META-INF/MANIFEST.MF
    > searchjar/
    > searchjar/JARFileFilter.class
    > searchjar/Main.class
    >
    > In the program, i would like to use regex to match line by line to
    > check if a specified string exists in it.
    >
    > my $userInputString = "Main.class";
    >
    > if(@match = $content =~ m/$userInputString/gs){
    > print "File is found:\t";
    > print @match;
    > }
    >
    > How can i achieve to print out the result of "searchjar/Main.class"
    >
    > Appreciate any help
     
    , Jun 5, 2006
    #2
    1. Advertising

  3. Ted Zlatanov Guest

    On 5 Jun 2006, wrote:

    > my $jarFile = "input.jar";
    > my $content = qx/jar tf $jarFile/;
    >
    > $content contains the list of files in the jar file.
    >
    >
    > META-INF/
    > META-INF/MANIFEST.MF
    > searchjar/
    > searchjar/JARFileFilter.class
    > searchjar/Main.class
    >
    > In the program, i would like to use regex to match line by line to
    > check if a specified string exists in it.
    >
    > my $userInputString = "Main.class";
    >
    > if(@match = $content =~ m/$userInputString/gs){
    > print "File is found:\t";
    > print @match;
    > }
    >
    > How can i achieve to print out the result of "searchjar/Main.class"


    At least in my experience, you can treat JAR files as ZIP files,
    meaning you can use any CPAN modules for ZIP file handling. This may
    be easier, since you can then look at the contents rather than scrape
    the text output of the jar tool.

    HTH
    Ted
     
    Ted Zlatanov, Jun 5, 2006
    #3
  4. Guest

    > At least in my experience, you can treat JAR files as ZIP files,
    > meaning you can use any CPAN modules for ZIP file handling. This may
    > be easier, since you can then look at the contents rather than scrape
    > the text output of the jar tool.



    actually i was using the ZIP file handling module before that, but
    there is a need to install some external modules that need to be
    compiled that makes it troublesome..so i guess i fall back onto using
    this method instead.
     
    , Jun 6, 2006
    #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. hiwa
    Replies:
    0
    Views:
    649
  2. Victor
    Replies:
    2
    Views:
    657
    Victor
    May 17, 2004
  3. ekzept
    Replies:
    0
    Views:
    386
    ekzept
    Aug 10, 2007
  4. John Gordon
    Replies:
    13
    Views:
    500
    Ian Kelly
    Dec 20, 2011
  5. Volkan Civelek

    Match doesn't match

    Volkan Civelek, Jul 19, 2006, in forum: Ruby
    Replies:
    4
    Views:
    173
Loading...

Share This Page