The following prints
et:a)(b
eb:(a)(b)
eteb1:a)(b
eteb2:
i expected it to print
et:a)(b
eb:(a)(b)
eteb1:a)(b
eteb2:(a)(b)
were my expectations unexpected?
use strict;
use warnings;
use File::Slurp;
use Text::Balanced qw/extract_multiple extract_bracketed extract_tagge
+d/;
my $data = '(a)(b)';
et($data);
eb($data);
eteb($data);
sub et {
my $data = shift;
my @array = extract_multiple(
$data,
[ sub{extract_tagged($_[0], 'a', 'b', undef,)}, ],
undef,
1
);
display('et', @array)
}
sub eb {
my $data = shift;
my @array = extract_multiple(
$data,
[ sub{extract_bracketed($_[0], '()')}, ],
undef,
1
);
display('eb', @array)
}
sub eteb {
my $data = shift;
my @array = extract_multiple(
$data,
[ sub{extract_tagged($_[0], 'a', 'b', undef,)}, ],
undef,
1
);
display('eteb1', @array);
@array = extract_multiple(
$data,
[ sub{extract_bracketed($_[0], '()')}, ],
undef,
1
);
display('eteb2', @array);
}
sub display {
my $sub = shift;
print "$sub:";
print $_ for @_;
print "\n";
}
-
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.