I wrote ($nl) = $data =~ m{(\15\12?|\12)} because your usage of \n is still problematic - in this case the newline value for mac, *nix and windows is handled. Anyway, the whole point to this code makes my head hurt - I'm wondering why gmpassos didn't just use one of the existing template engines.

A /better/ idea would be to use this more like a state machine - here's a sample implementation:

my $data = qq`\nHTML1\n<% CODE1 %>\nHTML2\n<% CODE2 %>\nHTML3\n`; my $reader = get_reader( $data ); while (my $blob = $reader->()) { print "$blob->{'type'}: $blob->{'data'}\n";; } sub get_reader { my $input = shift; my $state = 'plain'; return sub { my $temp; return unless defined $input; if ($state eq 'plain') { if ($input =~ s/(.*?)<%//s) { $state = 'code'; return { type => 'plain', data => $1 }; } else { $temp = $input; undef $input; return { type => 'plain', data => $temp }; } } else { # state eq 'code' if ($input =~ s/(.*?)\%>//s) { $state = 'plain'; return { type => 'code', data => $1 }; } else { $temp = $input; undef $input; return { type => 'code', data => $temp }; } } } } __RETURNS__ plain: HTML1 code: CODE1 plain: HTML2 code: CODE2 plain: HTML3

Seeking Green geeks in Minnesota


In reply to Re^2: REGEX different on Linux & Win32! by diotalevi
in thread 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.