Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: data structure problem

by kcott (Canon)
on Nov 08, 2012 at 06:36 UTC ( #1002824=note: print w/replies, xml ) Need Help??


in reply to data structure problem

G'day perltux,

I was thinking of a hash before I'd even read as far as %hash=(preset=>\@preset, ....

Here's a bare-bones (but working) solution that doesn't use the -choices option. First, a few notes:

  • The -browsecmd callback is passed the widget as the first argument. As I haven't needed that, you'll see undef in a few places. You may need to change that.
  • I made some decisions about display defaults: you may want to make changes here also.
  • As I was uncertain what some of the terms you used referred to, my choices for variable names may be less than meaningful.

Here's the code:

#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my %choices = ( preset => [ qw{tom snare metal analog} ], card1 => [ qw{mellowstr brightstr string3} ], ram => [ qw{acoustic rock bass jazz strato distorted} ], ); my @list_order = qw{preset card1 ram}; my ($current_list, $current_choice); my $mw = MainWindow->new(); my $be_F = $mw->Frame()->pack(); my $ex_F = $mw->Frame()->pack(); my $list_BE = $be_F->BrowseEntry( -variable => \$current_list, -browsecmd => \&update_choices, )->pack(-side => 'left'); my $vary_BE = $be_F->BrowseEntry( -variable => \$current_choice, -browsecmd => \&make_choice, )->pack(-side => 'left'); for (@list_order) { $list_BE->insert(end => $_); } update_choices(undef, $list_order[0]); $ex_F->Button(-text => 'Exit', -command => sub { exit })->pack(); MainLoop; sub update_choices { my (undef, $list) = @_; $current_list = $list; $current_choice = $choices{$list}[0]; $vary_BE->delete(0 => 'end'); for (@{$choices{$list}}) { $vary_BE->insert(end => $_); } return; } sub make_choice { my (undef, $choice) = @_; $current_choice = $choice; return; }

-- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002824]
help
Chatterbox?
[Corion]: The API itself will basically be my $iter = generate_http_requ ests(method => 'GET', url => '/settings/:name', headers => ???, get_params => ['foo','bar']), but I'm not sure how to parametrize values in the headers and how to specify lists of ...
[choroba]: On the other hand, lots of options to receive the requests :-)
[Corion]: ... values to be used. For example, I think for headers, one would want to have various kinds of Content-Encoding headers, but for the get_parameters one would have various kinds of Bobby Tables
[choroba]: What about [metadoc:// Algorithm::Loops]?
[Corion]: choroba: Yeah, but handing off the request to Dancer,Plack, Mojolicious,LWP is easy once I have the data filled into some structure ;))
[choroba]: Algorithm::Loops
[Corion]: choroba: I'm using that to generate the permutations, but I don't know how the user can pass the intended values to my function in a sane way
[Corion]: I have a prototype that permutes the get_parameters, but the values used for the get parameters should be different from the values used for the headers and potentially for parts of the URL
[Corion]: But yes, in general, my approach will be "split the URL into another set of parameters, generate an array of allowed values for each parameter and then NestedLoops() over the set"
[choroba]: hmm... so you need something like bag from Test::Deep, but not for checking, but for generation

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-01-17 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (152 votes). Check out past polls.