Subject: | Incorrect variable names returned by extract_variable() |
Hi,
When using the extract_variable() function, some of the variable names
returned by Text::Balanced are incorrect. The output of the attached
script is:
foo is (?^:^(km|mi)$) /^(km|mi)$/
foo contains variable names:
$)
$/
There are two issues:
A) The first variable detected, $), is not a valid variable name in
Perl. Maybe Text::Balanced could check against the Perl variable naming
rules:
http://perl.cyberciti.biz/tutorial/rules-for-naming-perl-variable-name.php
B) The second variable, $/, is a Perl special variable
(http://www.kichwa.com/quik_ref/spec_variables.html), which is fine.
However, in the given context, at the end of a regular expression, the
dollar sign does not indicate a variable but matches the end of string.
Best,
Florent
Subject: | tb_issue.pl |
#! /usr/bin/env perl
use strict;
use warnings;
use Text::Balanced qw(extract_multiple extract_variable);
my $foo = qr/^(km|mi)$/ .' '. '/^(km|mi)$/';
print "foo is $foo\n";
print "foo contains variable names:\n";
for my $var_name (extract_multiple($foo,[sub{extract_variable($_[0],'')}],undef,1)) {
print " $var_name\n";
}
exit;