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

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

Thread Next
From:
Stas Bekman
Date:
May 19, 2003 00:33
Subject:
interpolating constants in m/.{m,n}/
Message ID:
3EC888A1.8080709@stason.org
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";'
abcd-efgh-ijkl-mnop-qrst-uvwx-yz

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'
abcd-efgh-ijkl-mnop-qrst-uvwx-yz

I can neither do:
   m/.{+SIZE}/
nor
   m/.{SIZE()}/
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
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About