Looping backreferences

Andrew Savige ajsavige at yahoo.com.au
Wed Aug 20 22:43:45 CDT 2003

Joshua Goodall wrote:
> I would like (for no other reason than shorter lines and out of
> curiousity) to be able to more intuitively write
> $net = join ".", reverse $zone =~ /^(?:(\d+)\.){2,3}in-addr\.arpa$/;
> but of course this only returns a single backreference, not the three
> I'm hoping for when I feed it "3.2.1.in-addr.arpa".
> Anyone know if/how it's possible to have a variable-length list returned
> by a regex? (preferably 5.6 compat)

If the data is already validated, this might be acceptable:

$net = join ".", reverse $zone =~ /\d+/g;

Well, it's shorter. :-) I can't think of a way to stop your optional
third capture returning undef.


http://search.yahoo.com.au - Yahoo! Search
- Looking for more? Try the new Yahoo! Search

More information about the Melbourne-pm mailing list