develooper Front page | perl.perl5.porters | Postings from May 2003

interpolating constants in m/.{m,n}/

Thread Next
Stas Bekman
May 19, 2003 00:33
interpolating constants in m/.{m,n}/
Message ID:
I'm not sure if it's a bug or an expected behavior, but it seems that I can't 
use constants in m/.{m}/ and I see no references to it in the perlre manpage.

I'm trying to split string into substrings of SIZE chars and a remainder.

unpack "(A" . SIZE . ")*", $string

does the job:
% perl-5.8.1 -le 'use constant SIZE => 4; \
print join "-", unpack "(A" . SIZE . ")*", join "", "a".."z";'

but it doesn't work in 5.6.1. So I've tried to use a regex, but the only way I 
could embed a constant in m/.{m}/ was using the string interpolation 
workaround: @{[SIZE]}}

% perl-5.8.1 -le 'use constant SIZE => 4; $_ = join "", "a".."z"; my @w = 
/(.{@{[SIZE]}}|.+)/g; print join "-", @w'

I can neither do:
which I've tried to use, which is the usual trick for using constants in the 
hash keys. I know that {} here don't do the same thing, but I see no reason 
why shouldn't they behave identically to hash's {} brackets.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About