List Info

Thread: Re: Alphabetize a word




Re: Alphabetize a word
country flaguser name
United States
2007-09-05 09:21:45

What does the pattern " //" break down to? I'm somewhat familiar with
regular expressions and don't know what a forward slash does. I would
have guessed the matching pattern would've been the "." character that
matches any character (except n).

Paul Archer < tigger%40io.com">tiggerio.com>;
Sent by: perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
09/05/2007 10:12 AM
Please respond to
perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com

To
perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
cc

Subject
Re: [PBML] Alphabetize a word

Which gets us to the oneliner:
perl -e ' $word=&quot;alphabetize"; print join "&quot;, (sort split ( //, $word)),
"n"'

1:41pm, greenberg.d%40gmail.com">greenberg.dgmail.com wrote:

> As for returning it as a string instead of an array of characters, look
at the "join" function. With it, you can explicitly return a string.
>
> -David
&gt;
> Sent via BlackBerry by AT&T
>
>; -----Original Message-----
> From: Paul Archer < tigger%40io.com">tiggerio.com>;
>
> Date: Wed, 5 Sep 2007 08:20:52
> To: perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
> Subject: Re: [PBML] Alphabetize a word
>;
>
> If what you are looking for is a list of the letters in a word, in
> alphabetical order, then you want something like:
&gt;
> perl -e ' $word=&quot;alphabetize"; array= sort split ( //, $word); print
&gt; array, "n&quot;'
>
> And you're doing fine with the 'shift'. No reason not to do it just the
way
&gt; you have it.
>
> Paul
>;
> 9:13am, Ryan J Nauman wrote:
&gt;
> > I wrote the following code to alphabetize a word:
&gt; >
>; > sub alphabetize
> > {
> > my $word = uc(shift);
> > my $wordlen = length($word);
>; > my letters;
> >
>; > for (my $i = 0; $i < length $word; $i++)
> > {
> > push letters, substr($word, $i, 1);
> > }
> >
>; > letters = sort letters;
> > return letters;
> > }
> >
>; > This function will always only receive one parameter. In this case I
do
&gt; > not know if shift is the best method or not. $_ was not giving me
> > anything so I went with shift. Alternatively, I think I could've used
_.
> > Does it matter?
> >
>; > If it can be optimized in any way I would appreciate pointers. My
> > ultimate question though is I want it to return a string instead of
the
&gt; > sorted character array that it is now. I can write it using a for loop
>; > and string concatenation but I think that would be extremely
inefficient.
>; > Help appreciated!
> >
>; >
>; > [Non-text portions of this message have been removed]
> >
>; >
>;
> ---------------------------
> 404 Error - Item Not Found
&gt; <haiku&gt;
> You step in the stream,
> but the water has moved on.
> That page is not here.
&gt; </haiku>
> ---------------------------
>
> -----11004 days until retirement!-----
&gt;
>
> Unsubscribing info is here:
http://help.yahoo.com/help/us/groups/groups-32.html
> Yahoo! Groups Links
&gt;
>
>
>;
>

__________________________________________________________
"Can't you recognize bullshit? Don't you think it would be a
useful item to add to your intellectual toolkits to be capable
of saying, when a ton of wet steaming bullshit lands on your
head, 'My goodness, this appears to be bullshit'?
_____________Neal Stephenson, "Cryptonomicon&quot;__________________

-----11004 days until retirement!-----


[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Alphabetize a word
country flaguser name
United States
2007-09-05 10:28:29

The slashes delimit a regular expression. In this case, the regexp is empty.
Using an empty regular expression for the split means that each character
will become a separate element in our array.

Paul

10:21am, Ryan J Nauman wrote:

> What does the pattern " //" break down to? I'm somewhat familiar with
>; regular expressions and don't know what a forward slash does. I would
&gt; have guessed the matching pattern would've been the ".&quot; character that
>; matches any character (except n).
>
>
&gt;
>
> Paul Archer < tigger%40io.com">tiggerio.com>;
> Sent by: perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
> 09/05/2007 10:12 AM
> Please respond to
> perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
>
>
> To
> perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
> cc
>
> Subject
> Re: [PBML] Alphabetize a word
>;
>
>
>
>
&gt;
> Which gets us to the oneliner:
> perl -e ' $word=&quot;alphabetize"; print join "&quot;, (sort split ( //, $word)),
> "n&quot;'
>
> 1:41pm, greenberg.d%40gmail.com">greenberg.dgmail.com wrote:
&gt;
>&gt; As for returning it as a string instead of an array of characters, look
>; at the "join" function. With it, you can explicitly return a string.
>>
>> -David
&gt;>
&gt;> Sent via BlackBerry by AT&T
>>
>> -----Original Message-----
>&gt; From: Paul Archer < tigger%40io.com">tiggerio.com>;
>>;
>>; Date: Wed, 5 Sep 2007 08:20:52
>> To: perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com
>> Subject: Re: [PBML] Alphabetize a word
>;>
>;>
>;> If what you are looking for is a list of the letters in a word, in
>&gt; alphabetical order, then you want something like:
&gt;>
&gt;> perl -e ' $word=&quot;alphabetize"; array= sort split ( //, $word); print
&gt;> array, "n&quot;'
>>
>> And you're doing fine with the 'shift'. No reason not to do it just the
> way
>> you have it.
>>
>> Paul
>;>
>;> 9:13am, Ryan J Nauman wrote:
&gt;>
&gt;>> I wrote the following code to alphabetize a word:
&gt;>>
>>&gt; sub alphabetize
>>;> {
>&gt;> my $word = uc(shift);
>>> my $wordlen = length($word);
>;>> my letters;
>>&gt;
>&gt;> for (my $i = 0; $i < length $word; $i++)
>>&gt; {
>&gt;> push letters, substr($word, $i, 1);
>>> }
>&gt;>
&gt;>> letters = sort letters;
>>&gt; return letters;
>>&gt; }
>&gt;>
&gt;>> This function will always only receive one parameter. In this case I
> do
>&gt;> not know if shift is the best method or not. $_ was not giving me
>&gt;> anything so I went with shift. Alternatively, I think I could've used
>; _.
>&gt;> Does it matter?
>>>;
>>;> If it can be optimized in any way I would appreciate pointers. My
>&gt;> ultimate question though is I want it to return a string instead of
> the
>>> sorted character array that it is now. I can write it using a for loop
>;>> and string concatenation but I think that would be extremely
> inefficient.
>&gt;> Help appreciated!
>&gt;>
&gt;>>
>>&gt; [Non-text portions of this message have been removed]
>>&gt;
>&gt;>
&gt;>
&gt;> ---------------------------
>> 404 Error - Item Not Found
&gt;> <haiku&gt;
>&gt; You step in the stream,
>> but the water has moved on.
>> That page is not here.
&gt;> </haiku>
>> ---------------------------
>>
>> -----11004 days until retirement!-----
&gt;>
&gt;>
&gt;> Unsubscribing info is here:
&gt; http://help.yahoo.com/help/us/groups/groups-32.html
>&gt; Yahoo! Groups Links
&gt;>
&gt;>
&gt;>
&gt;>
&gt;>
&gt;
> __________________________________________________________
> "Can't you recognize bullshit? Don't you think it would be a
> useful item to add to your intellectual toolkits to be capable
> of saying, when a ton of wet steaming bullshit lands on your
>; head, 'My goodness, this appears to be bullshit'?
> _____________Neal Stephenson, "Cryptonomicon&quot;__________________
>
> -----11004 days until retirement!-----
&gt;
>
>
&gt; [Non-text portions of this message have been removed]
>
>;

---------------------------------------------------------
";You will always be lucky if you know how to make friends
with strange cats."; - Colonial American proverb
---------------------------------------------------------

-----11004 days until retirement!-----

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )