Hi All,

I'm playing with record formats.  I need to be able to have more than one
kind of delimited
format available at one time.  I've written a sort routine to get the
values in the order
I want, but it assumes one variable name (in this example that is
%delimited format).  I want
something a little more dynamic.  I've tried passing the structure to the
sort routine, but
it wont play along.  Perhaps I'm approaching this all wrong.  Perhaps I'm
missing something
simple.  Any ideas how to better handle this?  Code example follows:

%delimited_format = (
      delimiter => "|",
      fields => { field_three => {index => 3,value => "THREE"},
                        field_two => {index => 2,value => "TWO"},
                        field_one => {index => 1,value => "ONE"},
                        field_four => {index => 4,value => "FOUR"},
                        field_five => {index => 5,value => "FIVE"},
      },
);

## this part wont work...
#foreach my $fieldname ( sort delim_sort(\%delimited_format) keys %
{$delimited_format{fields}}){
#     print "$fieldname\t";
#     print ${${$delimited_format{fields}}{$fieldname}}{index}."\t";
#     print $delimited_format{delimiter}."\n";
#}
#sub delim_sort{
#     my $hRef = shift;
#     ${${${$hRef}{fields}}{$a}}{index}
#     <=>
#     ${${${$hRef}{fields}}{$b}}{index}
#}

## this part will work...
foreach my $fieldname ( sort old_delim_sort keys %
{$delimited_format{fields}}){
      print "$fieldname\t";
      print ${${$delimited_format{fields}}{$fieldname}}{index}."\t";
      print $delimited_format{delimiter}."\n";
}
sub old_delim_sort{
      ${${$delimited_format{fields}}{$a}}{index}
      <=>
      ${${$delimited_format{fields}}{$b}}{index}
}
__END__

TIA,
Peter





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to