http://qs1969.pair.com?node_id=460985


in reply to Re: string comparison
in thread string comparison

Seems like an overly complicated example. Isn't it just as simple as... ?
my $string1 = '~cake,pastry'; my $string2 = 'pastry,~caske'; if (sort_text($string1) eq sort_text($string2)) { print "match\n"; } sub sort_text { join(',', sort split(/,/, $_[0]) ) }
---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re^3: string comparison
by tphyahoo (Vicar) on May 27, 2005 at 10:02 UTC
    Extending this logic a bit, and using <DATA> to read in the test data:
    use strict; use warnings; my ($first_line, $current_line); while (<DATA>) { chomp; # get rid of newline # get the first line sorted if ($. == 1) { $first_line = join ",", sort( split /,/,); } else { #die if doesn't match the first line sorted. $current_line = join ",", sort( split /,/,); die "$_ didn't match first line" unless $current_line eq $firs +t_line; } } __DATA__ ~cake,pastry,donuts,meringue pastry,~cake,meringue,donuts meringue, donuts,pastry,~cake,meringue
    This dies on the third line, as it should.