Sorting in Safe compartments under Perl 5.8

Discussion in 'Perl Misc' started by Zbigniew Fiedorowicz, Nov 5, 2003.

  1. I've run into problem in using sort under Perl 5.8.0 running under the
    Linux Redhat 9.0 distribution. The code works flawlessly under Perl
    5.6.0 under Linux Redhat 7.2. Under 5.8.0/RH 9.0 sorting fails with
    error messages of the form:

    Use of uninitialized value in numeric comparison (<=>) at (eval 2)

    I'd be particularly interested in hearing whether this code works under
    Perl 5.8.0 under other operating systems.

    Here's the code:
    ----------- cut here ----------------------
    #!/usr/bin/perl -w

    use strict;
    use Safe;

    sub PGsort {
    local($a,$b);
    my $compare = shift;

    sort {&$compare($a, $b) } @_;
    }


    my $cmp = new Safe;
    print "Safe version $Safe::VERSION\n";

    $cmp->share('&PGsort');
    my $string = <<'EOF';

    my @list = (4,6,2, 5 ,10, 8, 9 );

    my $str = join( " ", PGsort sub {$_[0] <=> $_[1] } , @list );

    print $str;

    EOF

    $cmp->reval($string);
    ----------- cut here ----------------------

    Thanks in advance,
    Zbigniew Fiedorowicz
     
    Zbigniew Fiedorowicz, Nov 5, 2003
    #1
    1. Advertising

  2. Here's another data point (according to private email): the code runs fine
    under Perl 5.8.0/SunOS 5.8 with Safe version 2.07

    Zbigniew Fiedorowicz wrote:
    > I've run into problem in using sort under Perl 5.8.0 running under the
    > Linux Redhat 9.0 distribution. The code works flawlessly under Perl
    > 5.6.0 under Linux Redhat 7.2. Under 5.8.0/RH 9.0 sorting fails with
    > error messages of the form:
    >
    > Use of uninitialized value in numeric comparison (<=>) at (eval 2)
    >
    > I'd be particularly interested in hearing whether this code works under
    > Perl 5.8.0 under other operating systems.
    >
    > Here's the code:
    > ----------- cut here ----------------------
    > #!/usr/bin/perl -w
    >
    > use strict;
    > use Safe;
    >
    > sub PGsort {
    > local($a,$b);
    > my $compare = shift;
    >
    > sort {&$compare($a, $b) } @_;
    > }
    >
    >
    > my $cmp = new Safe;
    > print "Safe version $Safe::VERSION\n";
    >
    > $cmp->share('&PGsort');
    > my $string = <<'EOF';
    >
    > my @list = (4,6,2, 5 ,10, 8, 9 );
    >
    > my $str = join( " ", PGsort sub {$_[0] <=> $_[1] } , @list );
    >
    > print $str;
    >
    > EOF
    >
    > $cmp->reval($string);
    > ----------- cut here ----------------------
    >
    > Thanks in advance,
    > Zbigniew Fiedorowicz
    >
     
    Zbigniew Fiedorowicz, Nov 5, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriel Rossetti
    Replies:
    0
    Views:
    1,366
    Gabriel Rossetti
    Aug 29, 2008
  2. Replies:
    1
    Views:
    356
    Brian Candler
    Aug 12, 2003
  3. Aredridel

    Not just $SAFE, but damn $SAFE

    Aredridel, Sep 2, 2004, in forum: Ruby
    Replies:
    19
    Views:
    254
  4. Farrel Lifson

    $SAFE =4 safe enough?

    Farrel Lifson, Aug 29, 2006, in forum: Ruby
    Replies:
    7
    Views:
    113
    Eric Hodel
    Aug 31, 2006
  5. John Nagle
    Replies:
    5
    Views:
    487
    John Nagle
    Mar 12, 2012
Loading...

Share This Page