Hi there Monks!
Can someone explain why this code does not match on my code?
I have to use regular expression for this. Thank you very much!!!
#!/perl/bin/perl
use CGI qw(:header);
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use strict;
print header();
use warnings 'all';
my $directory = "/test";
my $new_file = "$directory/test.txt";
my $out_put;
open(FH,'<',$new_file) || die $!;
my @test = <FH>;
foreach my $line (@test)
{
$line =~ /<!--\s+\d+nd movie -->\s*(.*?)\s*<!--\s+\/\d+nd movie --
+>/sgi;
$out_put = $1;
print $out_put;
}
close(FH);
Here is the test.txt file, I am trying to get whatever is in between tags - <!-- 1nd --><!-- /1nd table --> and <!-- 2nd table --><!-- /2nd table -->:
test.txt
<!-- 3nd table --><table cellpadding="0" cellspacing="0" border="0"><t
+r><td>Test Line no end of line.</td</tr></table><!-- /3nd table -->
<!-- 1nd -->
<table cellpadding="2" cellspacing="0" border="0"><tr><td><font color=
+red>Test Line</font></td></tr></table>
<!-- /1nd table -->
<!-- 4nd table --><table cellpadding="0" cellspacing="0" border="1"><t
+r><td><font color=navy>Test Line no end of line.</font></td></tr></ta
+ble><!-- /4nd table -->
<!-- 2nd table -->
<table cellpadding="0" cellspacing="0" border="0"><tr><td>Test Line no
+ end of line.</td</tr></table>
<!-- /2nd table -->
Thank you very much!!!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|