[Milan-pm] PErl Test

Hakim Cassimally hakim.cassimally at gmail.com
Tue Mar 24 10:14:25 PDT 2009


2009/3/24 marcos rebelo <oleber at gmail.com>

> it is correct now
>

Correct how?

use strict; use warnings;
use Data::Dumper;
use Test::More tests => 1;

my %a;
@a{1,2,19,6,2,6}=(1..6);
my $keys = [ keys %a ];

is_deeply
    $keys,
    [ 1, 19, 2, 6 ],
    'http://milan.pm.org/perl_test.html, question 14'
    or diag Dumper $keys;

####
1..1
not ok 1 - http://milan.pm.org/perl_test.html, question 14
#   Failed test 'http://milan.pm.org/perl_test.html, question 14'
#   at isd.pl line 11.
#     Structures begin differing at:
#          $got->[0] = '6'
#     $expected->[0] = '1'
# $VAR1 = [
#           '6',
#           '1',
#           '19',
#           '2'
#         ];
# Looks like you failed 1 test of 1

osf' ;-)


>
> 2009/3/24 Hakim Cassimally <hakim.cassimally at gmail.com>:
> > 2009/3/24 marcos rebelo <oleber at gmail.com>
> >>
> >> On Tue, Mar 24, 2009 at 5:54 PM, Michele Beltrame <mb at cattlegrid.info>
> >> wrote:
> >> > I would say number 14 could be changed a bit, as keys() might return
> >> > keys in any order, so arrays shown as options could not be correct as
> >> > far as ordering is concerned.
> >>
> >> before there was a sort in there. You don't imagine the casino in the
> >> Lisbon PM, the alphabetic order, ...
> >>
> >> So at the end, this is the only possible answer.
> >
> > Except that without the sort the answer is wrong, and with the sort the
> > answer is right ;-)
> >
> > DB<6> @a{1,2,19,6,2,6}=(1..6); print Dumper([ sort keys %a
> > ]);
> > $VAR1 = ['1','19','2','6'];
> >
> > You could try sort { $a <=> $b } keys %a to be clearer?
> > osf'
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/milan-pm/attachments/20090324/cea24697/attachment-0001.html>


More information about the Milan-pm mailing list