Re: Sorting EBCDIC
- From: Ben Morrow <benmorrow@xxxxxxxxxxxxx>
- Date: Fri, 15 Dec 2006 22:26:25 +0000
Quoth Uri Guttman <uri@xxxxxxxxxxxxxxx>:
"CH" == Chris Hamel <hamelcd@xxxxxxxxxxx> writes:
CH> Here's the rub: the source system is an IBM mainframe that is
CH> assigning the values backwards in EBCDIC. Our system is on an AIX
CH> server.
CH> So, if I'm looking at four orders:
CH> 1 2 A B
CH> The mainframe has created them in this order:
CH> 2 1 A B
CH> But a descending sort in Perl will put them in this order:
CH> B A 2 1
use the unix dd utility to do ebcdic/ascii conversion. you ain't gonna
easily get it right with tr///. there might be a cpan module for this
too and should be easy to find by searching for ebcdic
Err... Encode? :)
AFAI understand your problem, you have a set of single-character
strings, and you want to sort them by EBCDIC code point. Something like
this should work (obviously, you will need to adjust for your code page):
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use Sort::Maker qw/make_sorter/;
my @ids = qw/1 2 A B/;
my $sorter = make_sorter
plain =>
number => {
code => q{
ord Encode::encode cp1047 => $_;
},
descending => 1,
},
or die;
print for $sorter->(@ids);
__END__
This actually prints
2
1
B
A
rather than 2 1 A B: was this a mistake above?
[Uri: why is it necessary to say C<Encode::encode>? Plain C<encode>
doesn't work, even if encode is imported. Is this just an artefact of
the fact that make_sorter uses eval ""?]
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. benmorrow@xxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Sorting EBCDIC
- From: Uri Guttman
- Re: Sorting EBCDIC
- References:
- Sorting EBCDIC
- From: Chris Hamel
- Re: Sorting EBCDIC
- From: Uri Guttman
- Sorting EBCDIC
- Prev by Date: Re: Calculating values of a 2d array by comparison of 2 strings
- Next by Date: Re: Upgrading from 32 bit ActivePerl-5.8.8.817 to 64 bit ActivePerl-5.8.8.819
- Previous by thread: Re: Sorting EBCDIC
- Next by thread: Re: Sorting EBCDIC
- Index(es):