Re: Lvalue Str::words iterator
by Ingo Blechschmidt other posts by this author
Jun 15 2005 12:37PM messages near this date
Re: Lvalue Str::words iterator
|
Re: Lvalue Str::words iterator
Hi,
Juerd wrote:
> Ingo Blechschmidt skribis 2005-06-15 20:18 (+0200):
> > >> say join ",", @words; # "hi,my,name,is,ingo";
> > > Following the logic that .words returns the words, the words are no
> > > longer individual words when joined on comma instead of
> > > whitespace...
> > sorry, I don't quite get that.
>
> "foo bar baz".words.join(',').words.join(':') ne 'foo:bar:baz';
>
> so somewhere in that process, foo, bar and baz managed to no longer be
> words by the definition of words used by an on whitespace splitting
> words method - they're one word, together, when they're joined on
> comma.
ah! I understand :)
So maybe we should allow words() (or however we'll end up calling it) to
take an optional parameter specifying what's considered a wordchar,
with a default of rx/\w+/:
say "foo bar baz".words() .join(":"); # same as
say "foo bar baz".words(rx/\w+/) .join(":"); # "foo:bar:baz"
say "foo,bar,baz".words() .join(":"); # same as
# "," doesn't match /\w+/
say "foo,bar,baz".words(rx/\w+/) .join(":"); # "foo:bar:baz"
# Now "," is considered to be part of words:
say "foo,bar,baz".words(rx/[\w|,]+/).join(":"); # "foo,bar,baz"
say "foo bar baz".words(rx/b../) .join(":"); # "bar:baz"
Then your example...
say "foo bar baz".words.join(',').words.join(':'); # "foo bar baz";
And:
say "foo bar baz".words.join(",").words(rx/[\w|,]+/).join(":");
# "foo,bar,baz"
I hope these examples make sense...
--Ingo
--
Linux, the choice of a GNU | Perfection is reached, not when there is no
generation on a dual AMD | longer anything to add, but when there is
Athlon! | no longer anything to take away.
Thread:
Ingo Blechschmidt
Juerd
Ingo Blechschmidt
Juerd
Larry Wall
Ingo Blechschmidt
Juerd
|