in reply to splitting

Do I get a fine or something for overusing foreach? But, seriously, what's wrong with this approach?
$dlm = '~'; $str = 'my~mind~has~been~broken'; foreach (split(/$dlm/,$str)) { push(@ary,$_,$dlm); } $ary[$#ary--]; print join(',',@ary),"\n";
Sure it's not pretty, but I suppose that's the goal...

#!/home/bbq/bin/perl
# Trust no1!

Replies are listed 'Best First'.
RE: Re: splitting
by Eugene (Scribe) on Apr 28, 2000 at 18:57 UTC
    That works if your delimeter is always the same. Like ~ in your case. But what if you use a regex to match some pattern, so that your delimenter is text in quotes?