in reply to String expansion script
#!/usr/bin/perl -ln use strict; use warnings; sub expand; sub doit; print for expand $_; sub expand { local $_=shift; return doit $`, (split /:/, $1), $' if /\{([\w:]+)\}/; return doit $`, $1 .. $2 , $' if /\[(\w+):(\w+)\]/; $_; } sub doit { my ($pre,$post)=(shift,pop); map { my $pre=$pre . $_; map $pre . $_, expand $post } @_; } __END__
Original description:
("specifications" have changed too)This is another short program that for me is a complete application, and I hope that this time there's not a common utility to do the same...Basically it expands strings of the form
to the listfoo[01:100]bar-{fred:barney:wilma}More info here!foo01bar-fred foo02bar-fred ... foo100bar-fred foo01bar-barney ... foo100bar-wilma
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Original code [was "Re: String expansion script"]
by ambrus (Abbot) on Feb 22, 2005 at 18:09 UTC | |
by blazar (Canon) on Feb 23, 2005 at 09:36 UTC |
In Section
Cool Uses for Perl