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!'