mixed cmp operator for sorting

W

Willem

Marc Girod wrote:
) On Monday, 23 September 2013 08:30:46 UTC+1, John W. Krahn wrote:
)
)> my @t = $a =~ /\D+|\d+/g;
)> my @s = $b =~ /\D+|\d+/g;
)>
)> Avoids zero length strings.
)
) Indeed, but it implies other changes in the following.

my @t = split /(\d+)/, $a;
my @s = split /(\d+)/, $a;

Avoids both issues.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
J

John W. Krahn

Willem said:
Marc Girod wrote:
) On Monday, 23 September 2013 08:30:46 UTC+1, John W. Krahn wrote:
)
)> my @t = $a =~ /\D+|\d+/g;
)> my @s = $b =~ /\D+|\d+/g;
)>
)> Avoids zero length strings.
)
) Indeed, but it implies other changes in the following.

my @t = split /(\d+)/, $a;
my @s = split /(\d+)/, $a;

Avoids both issues.

$ perl -le'use Data::Dumper; my $a = "12345"; my @t = split /(\d+)/, $a;
print Dumper \@t'
$VAR1 = [
'',
'12345'
];


Not, it appears, zero length strings.



John
 
W

Willem

John W. Krahn wrote:
) Willem wrote:
)> Marc Girod wrote:
)> ) On Monday, 23 September 2013 08:30:46 UTC+1, John W. Krahn wrote:
)> )
)> )> my @t = $a =~ /\D+|\d+/g;
)> )> my @s = $b =~ /\D+|\d+/g;
)> )>
)> )> Avoids zero length strings.
)> )
)> ) Indeed, but it implies other changes in the following.
)>
)> my @t = split /(\d+)/, $a;
)> my @s = split /(\d+)/, $a;
)>
)> Avoids both issues.
)
) $ perl -le'use Data::Dumper; my $a = "12345"; my @t = split /(\d+)/, $a;
) print Dumper \@t'
) $VAR1 = [
) '',
) '12345'
) ];
)
)
) Not, it appears, zero length strings.

'12345' is not a zero length string.

The original code expects the numbers to always be in even positions,
so in fact it works exactly as required.

Which is what was meant by "it implies other changes in the following."


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top