Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code:
#!C:/perl/bin/perl.exe use strict; use warnings; my @tmp_oid = (); while(<DATA>) { chomp; my $last_oid = $_; if ($#tmp_oid < 2) { push @tmp_oid, $last_oid; } else { my $first_oid = shift @tmp_oid; if ( (pack("C*", split('\.', $first_oid)) cmp pack("C*", split +('\.', $last_oid)) ) > 0 ) { print "Sort needed\n"; } push @tmp_oid, $last_oid; } } __DATA__ 1.3.6.1.2.1.7.5.1.1.0.0.0.0.1020 1.3.6.1.2.1.7.5.1.1.0.0.0.0.1021 1.3.6.1.2.1.7.5.1.1.0.0.0.0.1022 1.3.6.1.2.1.7.5.1.1.0.0.0.0.1023 1.3.6.1.2.1.7.5.1.1.0.0.0.0.701
That produces this error:
Character in 'C' format wrapped in pack at sort.pl line 16, <DATA> lin +e 4. Character in 'C' format wrapped in pack at sort.pl line 16, <DATA> lin +e 4. Character in 'C' format wrapped in pack at sort.pl line 16, <DATA> lin +e 5. Character in 'C' format wrapped in pack at sort.pl line 16, <DATA> lin +e 5. Sort needed
My method seems to work correctly determining that a sort is required but why am I seeing this error? If I shorten the OIDs I don't see the error ???

2006-01-18 Retitled by g0n, as per Monastery guidelines
Original title: 'Sorting Question'

Replies are listed 'Best First'.
Re: pack() format error.
by dave_the_m (Monsignor) on Jan 17, 2006 at 20:34 UTC
    You are trying to pack characters > 255. Try using 'U*' rather than 'C*'

    Dave.

      That was it. Thanks Dave!
Re: pack() format error.
by japhy (Canon) on Jan 17, 2006 at 20:37 UTC
    It's because you have numbers above 255 being packed as "C", which is supposed to be for bytes only. Perhaps using "U" will do better?

    Update: see, this is why I should click "Submit" right away, instead of being distracted.


    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: pack() format error.
by blazar (Canon) on Jan 18, 2006 at 08:28 UTC
    1.3.6.1.2.1.7.5.1.1.0.0.0.0.1023
    $ perl -e 'printf "%x\n" x 3, 0, 255, 1023' 0 ff 3ff