in reply to another way to split with limit

Maybe you should rephrase your question, but if your needs is to re-write $_ without separators, you could use:

tr /://; print;

Or, to avoid the third argument in split, you could use slices:

$_ = 'p:e:r:l:p:e:r:l'; @a[0..3] = split /:/; print @a;

But I'm not sure I've understood your question :))

Replies are listed 'Best First'.
Re: Re: another way to split with limit
by Anonymous Monk on Aug 20, 2001 at 00:11 UTC
    # give stdin a:b or hello:world or etc:etc while (<STDIN>){ ($a,$b) = split(/:/,$_,2); print "$a$b\n"; }
    I want to get those two values, how else can I do that with or without using split :) can I do
    (split(/:/)[0..1]? (split(/:/)[0,1]?
      Ok so I guess your print statement here isn't related to your question and that you only want to match both side of `:'
      You could do so like that:
      ($a, $b) = /(\w+):(\w+)/;
      The regex at the right remembers the matches due to the parenthesis, and $a get the first value and $b the second.
      Guillaume