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
> have guessed the matching pattern would've been the "." character that
> matches any character (except n).
>
>
>
>
> Paul Archer < tigger%40io.com">tigger
io.com>
> Sent by: perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com
> 09/05/2007 10:12 AM
> Please respond to
> perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com
>
>
> To
> perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com
> cc
>
> Subject
> Re: [PBML] Alphabetize a word
>
>
>
>
>
>
> Which gets us to the oneliner:
> perl -e ' $word="alphabetize"; print join "", (sort split ( //, $word)),
> "n"'
>
> 1:41pm, greenberg.d%40gmail.com">greenberg.d
gmail.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
>>
>> Sent via BlackBerry by AT&T
>>
>> -----Original Message-----
>> From: Paul Archer < tigger%40io.com">tigger
io.com>
>>
>> Date: Wed, 5 Sep 2007 08:20:52
>> To: perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.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:
>>
>> perl -e ' $word="alphabetize";
array= sort split ( //, $word); print
>>
array, "n"'
>>
>> 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:
>>
>>> I wrote the following code to alphabetize a word:
>>>
>>> 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
>>> 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
>>> 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
>> <haiku>
>> You step in the stream,
>> but the water has moved on.
>> That page is not here.
>> </haiku>
>> ---------------------------
>>
>> -----11004 days until retirement!-----
>>
>>
>> Unsubscribing info is here:
> http://help.yahoo.com/help/us/groups/groups-32.html
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>
> __________________________________________________________
> "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"__________________
>
> -----11004 days until retirement!-----
>
>
>
> [Non-text portions of this message have been removed]
>
>
---------------------