D
DJ Stunks
Hey all,
I have an API I need to call as a string of comma separated values. I
want to name those values in a hash so that it's easy to see what I'm
setting each value to. However, the values have to go into the API
call in a certain order. The goal is to make the code as clean and as
self-documenting as possible (ideally both the API call syntax and the
call values should be clearly apparent in the Perl code)
I can do it using a hash slice as follows, but this seems like a
pretty bad approach so I thought I'd shop it around and see what you
all think would be a better approach. Tie::IxHash maybe? (I've never
used it)
TIA,
-jp
#/usr/bin/perl
use strict;
use warnings;
#API syntax: my_API_call
(<this_parameter>,<that_parameter>,<extra_parameter>)
my %parms = (
this_parameter => 'some value',
that_parameter => 'another value',
extra_parameter => 'a third value',
);
my @order = qw{ this_parameter that_parameter extra_parameter };
my $stringified_API_call = 'my_API_call(' . join(',', @parms
{ @order }) . ')';
print "call it: $stringified_API_call\n";
__END__
I have an API I need to call as a string of comma separated values. I
want to name those values in a hash so that it's easy to see what I'm
setting each value to. However, the values have to go into the API
call in a certain order. The goal is to make the code as clean and as
self-documenting as possible (ideally both the API call syntax and the
call values should be clearly apparent in the Perl code)
I can do it using a hash slice as follows, but this seems like a
pretty bad approach so I thought I'd shop it around and see what you
all think would be a better approach. Tie::IxHash maybe? (I've never
used it)
TIA,
-jp
#/usr/bin/perl
use strict;
use warnings;
#API syntax: my_API_call
(<this_parameter>,<that_parameter>,<extra_parameter>)
my %parms = (
this_parameter => 'some value',
that_parameter => 'another value',
extra_parameter => 'a third value',
);
my @order = qw{ this_parameter that_parameter extra_parameter };
my $stringified_API_call = 'my_API_call(' . join(',', @parms
{ @order }) . ')';
print "call it: $stringified_API_call\n";
__END__