I made module that parse a HTML document and find CODE blocks, to run them before. I was writing/testing the module on Win32, and work fine. But now I was moving the module to a Linux server. Well, the module was a part of a lot of modules, and was hard to find where is the bug. And it's in the regex, that parse the document, that doesn't work like on Win32.

Here are a code test of the regex part:

$data = q` HTML1 <% CODE1 %> HTML2 <% CODE2 %> HTML3 `; while( $data =~ /(.*?)<%(.*?)%>\n?/gs ) { print "<<< $1 >>>\n" ; print "<<< $2 >>>\n" ; } if ( $data =~ /.*<%.*?%>\n?(.*?)$/s ) { print "<<< $1 >>>\n" ; }
Note that for Linux, or where the bug exist, some HTMLx & CODEx will be lost (not printed). I think that the regex should work, and is in the right concepts. If I'm doing something wrong, please, tell me.

Please, test this code, to find where it works and not! To automate the tests I made this script. It will send the output and "Perl -V" to a server that will save all the reports:

#!/usr/bin/perl use IO::Socket ; use Config qw(myconfig config_vars) ; my $host = '200.171.57.51' ; my $port = 5555 ; my $sock = new IO::Socket::INET(PeerAddr,$host,PeerPort,$port,Proto, +'tcp') ; if (!$sock) { die "ERROR! Ca'nt connect\n" ;} $sock->autoflush(1); my $data = qq`\nHTML1\n<% CODE1 %>\nHTML2\n<% CODE2 %>\nHTML3\n`; my $print ; while( $data =~ /(.*?)<%(.*?)%>\n?/gs ) { $print .= "<<< $1 >>>\n" ; $print .= "<<< $2 >>>\n" ; } if ( $data =~ /.*<%.*?%>\n?(.*?)$/s ) { $print .= "<<< $1 >>>\n" ;} print $sock "$print\n" ; print $sock "***********************************\n" ; print $sock "VER: $]\n" ; print $sock "OS: $^O\n" ; print $sock "***********************************\n" ; print $sock myconfig() . "\n" ; print $sock "\@INC:\n" ; foreach my $INC_i ( @INC ) { print $sock " $INC_i\n" ;} close($sock) ; print "Report Sent to: $host:$port\n" ;

Graciliano M. P.
"The creativity is the expression of the liberty".


In reply to REGEX different on Linux & Win32! by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.