develooper Front page | perl.perl6.language | Postings from June 2005

Re: Lvalue Str::words iterator

Thread Previous | Thread Next
From:
Ingo Blechschmidt
Date:
June 15, 2005 11:20
Subject:
Re: Lvalue Str::words iterator
Message ID:
d8pr4k$cr2$1@sea.gmane.org
Hi,

Juerd wrote:
> Ingo Blechschmidt skribis 2005-06-15 19:14 (+0200):
>> as Larry mentioned in another thread that he wants a "different
>> notation for word splitting"
>> (http://www.nntp.perl.org/group/perl.perl6.language/21874),
>> how about that, similar to Haskell's "words" function:
> 
> "words" is wrong for something that splits.

I took the name from Haskell's words, but I don't mind a name change.

> It'd be right for something that matches. Let me demonstrate: 
> 
>    "(foo bar --baz blah-- quux)".words;
> This should return <foo bar baz blah quux>, not <(foo bar --baz blah--
> quux)>. So the name "words" isn't good for this.

right, it should return <foo bar baz blah quux>, with the additional
lvalue ability, so that the following (contrived) example works:

    my $str     = "(foo bar --baz blah-- quux)";
    $str.words .= map:{ substr $^word, 1 };
    say $str;
         # "(oo ar --az lah-- uux)";

>>     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.

I wanted to show the contents of @words, I did not want to split the
string into words and then concatenate the words again.

   # Maybe this...
   say " hi my  name is ingo ".words.map:{ "($_)" }
         # "(hi) (my) (name) (is) (ingo)"
   # ...is clearer?


--Ingo

-- 
Linux, the choice of a GNU | Black holes result when God divides the
generation on a dual AMD   | universe by zero.  
Athlon!                    | 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About