Match line by line

V

vincente13

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
 
V

vincente13

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
 
T

Ted Zlatanov

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
 
V

vincente13

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.
 

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,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top