develooper Front page | perl.golf | Postings from April 2002

Re: Please explain

Thread Previous | Thread Next
From:
Yanick
Date:
April 8, 2002 13:35
Subject:
Re: Please explain
Message ID:
20020408164747.A30439@gilgamesh.sympatico.ca
On Mon, Apr 08, 2002 at 08:20:53PM +0000, Jean-Pierre wrote:
> [..] I caught  the construction "sort/./g", used by 60% of the solutions, on 
> the web, querying for "perl anagram".
> 
> Could someone give me either an explanation or a link?

I guess it would be easier if we expand the expression a little
bit. Let's take the instanceof the thing in my own solution for the hole:

map$1{join$|,sort/./g}.=$_,sort<>;

what it means is simply:

my @words = sort <>; # the lines of the file are sorted and thrown
                     # into @words

for my $line ( @words )
{
	# return an array of all elements of $line
	# matching '.'. I.e., all its characters. 
	# For all pratical purposes, it's a twisted
	# way to do @characters = split '', $line
	my @characters = ( $line =~ /./g ); 

	my $key = join $|, @characters;

	$1{ $key } = $line;  
}


Hoping this make the magic a wee bit less murky,
`/anick


-- 
Because it's fun. Now, that is a perfectly good reason to
do anything.        -- Kosuke Fujishima, 'Oh my Goddess!'

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