in reply to Must use global variables in format in module; feature or fault?
Though it isn't mentioned very explicitly, it looks like a bug that was fixed in a later version.
Closures, eval and lexicals
There have been many fixes in the area of anonymous subs, lexicals and closures. Although this means that Perl is now more "correct", it is possible that some existing code will break that happens to rely on the faulty behaviour. In practice this is unlikely unless your code contains a very complex nesting of anonymous subs, evals and lexicals.
I remember from experience that you can fix your code by wrapping your format declarations in BEGIN {}
Though I would probably switch to Perl6::Form, its all green on 5.8.8
And @_ is already a global which you could use :)
sub printFormat { local $~ = shift; return write; } BEGIN { format TEST = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_[0] ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_[0] . our %N2I = ( text2print => 0, ); format TESTNAMEY = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_[$N2I{text2print}] ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_[$N2I{text2print}] . use constant do { my $ix = 0; +{ map { $_ => $ix++ } qw[ TEXT2PRINT ] } }; format TESTNAMEDCONSTANTY = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_[TEXT2PRINT] ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $_[TEXT2PRINT] . }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Must use global variables in format in module; feature or fault?
by w8lle (Novice) on Aug 22, 2012 at 17:30 UTC |