enkomeks has asked for the wisdom of the Perl Monks concerning the following question:

I am a total newbie to perl scripting. Heres what i am trying to do: I am trying to integrate a test management tool with our a bug tracking tool (Jira). As part of that process, i need to create a subset of a larger select list but the indexes on this list need to match those in JIRA in order to get the integration between the tools working. For example, my complete list has: {a, b, c, d, e, f} with indexes 0..5 but i want to create a select list that only has {a, d, f} with indexes 0, 3, 5 such that when user selects say 'd', my test tool should match index 3 with corresponding index in JIRA. Bottomline, rather than creating an indexed list counting from 0 to say 5, i want to be able to specify a specific index for my label a, d and f: Here is what i have so far:
my @myList = ( {label => "a", value => '0'}, {label => "d", value => '3'}, {label => "f", value => '5'}, ); $m->out( '<select name="myselectlist">' ); for ( @myList) { $m -> out(qq(<option value=").$_->{value} . qq(">) . $_->{ label } + . qq(</option> )); } $m->out(</select>);
Results: When i run this, i get the select list alright, but it does not seem list the list is passing comparing indexes with jira. Any help or alternative ways to do this would be truly truly appreciated. I really need this. Thanks J

Replies are listed 'Best First'.
Re: HELP MEEE !!!!
by moritz (Cardinal) on Apr 19, 2009 at 18:14 UTC
    but i want to create a select list that only has {a, d, f} with indexes 0, 3, 5

    That condition doesn't appear in your program anywhere.

    You could for example define a hash with the keys a, d and f, and only call $m->out if $_->{label} exists in that hash.

    And by the way, if you scream at us in your title and append four exclamation marks the topic doesn't become more important for us - your chances for getting help would be much higher if you'd actually chose a title that describe what you want help with.

Re: Specifying array indexes in select list.
by ysth (Canon) on Apr 19, 2009 at 19:00 UTC
    When i run this, i get the select list alright, but it does not seem list the list is passing comparing indexes with jira
    Can you expand on this? Since the only thing your code does is create a select list, and you say it is "alright", what is it that you want to be different? Does jira expect different values than the 0,3,5?
    $m->out(</select>);
    That should be $m->out('</select>'). Maybe that's your problem?
Re: Specifying array indexes in select list.
by AnomalousMonk (Archbishop) on Apr 20, 2009 at 01:08 UTC
    qq(<option value=").$_->{value} . qq(">) . $_->{ label } . qq(</option +> )
    For greater convenience (and much greater visual clarity), hash and array values may be interpolated directly into double-quotish things.
    >perl -wMstrict -le "my @AoH = ( { number => 1, spelled => 'one', }, { number => 2, spelled => 'two', }, { number => 3, spelled => 'three', }, ); for my $hashref (@AoH) { print qq{$hashref->{number} is spelled $hashref->{spelled}}; } print ''; for my $i (0 .. $#AoH) { print qq{$AoH[$i]->{number} is spelled $AoH[$i]->{spelled}}; } " 1 is spelled one 2 is spelled two 3 is spelled three 1 is spelled one 2 is spelled two 3 is spelled three