Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
use hash to name params, then stringify values in specific order
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="DJ Stunks, post: 4861890"] 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__ [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
use hash to name params, then stringify values in specific order
Top