ala_poubelle has asked for the wisdom of the Perl Monks concerning the following question:

I don't understand why the following code, using Regexp::Common balanced regular expression does not work:

#use strict; use Regexp::Common qw /balanced/; my $file = <<END; * Converting valif() v1 0 1 pwl 0 -5 10n 5 e2 2 0 value=valif(v(1)>0, 2, -2) .tran 10n 10n .plot tran v(1) v(2) END #my %RE; my @file = split('\n',$file); my $re_valif=${RE}{balanced}{-keep}{-parens=>'()'}; print $re_valif . "\n"; foreach (@file) { print $_ . "\n"; /${RE}{balanced}{-parens=>'()'}/ and print "->Matched |$1|$2|$3|$4 +|\n"; }

Replies are listed 'Best First'.
Re: Regex::Common balanced does not seem to work
by arkturuz (Curate) on Nov 22, 2013 at 11:07 UTC
    You should always use strict and warnings. You get the following error when using those:
    Variable "$RE" is not imported at 1063912.pl line 20. Global symbol "$RE" requires explicit package name at 1063912.pl line +20. Execution of 1063912.pl aborted due to compilation errors.
    The fix is to change ${RE} to $RE