develooper Front page | | Postings from April 2002

Re: Please explain

Thread Previous | Thread Next
April 8, 2002 13:35
Re: Please explain
Message ID:
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:


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,

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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About