Use of string var within qw//

Discussion in 'Perl Misc' started by joe.cipale@radisys.com, Jan 12, 2005.

  1. Guest

    I am attempting to build a Tk:Optionmenu pull down from a string that
    is passed to a sub-routine from one of my menu items. The string may
    look like this:
    2 3 8 10 14

    The string WILL change, which is why I want to pass the string to my
    menu pulldown as such:

    my @slt_opt = qw/\$slt/;

    $frame3->Label(-text => "Slot ID: ")->pack(-side => 'left',
    -anchor => 's',
    -expand => 1);

    $frame3->Optionmenu(-variable => \$slots,
    -options => [@slt_opt],
    -command => [sub {print "args=@_\n"}, 'First']);

    ======================================
    Am I reaching with what qw can do here?

    Regards,

    Joe
     
    , Jan 12, 2005
    #1
    1. Advertisements

  2. Paul Lalli Guest

    <> wrote in message
    news:...
    > I am attempting to build a Tk:Optionmenu pull down from a string that
    > is passed to a sub-routine from one of my menu items. The string may
    > look like this:
    > 2 3 8 10 14
    >
    > The string WILL change, which is why I want to pass the string to my
    > menu pulldown as such:
    >
    > my @slt_opt = qw/\$slt/;


    You have just created the following array:
    @slt_opt = ('\$slt');
    That is, an array with one element - the string containing a slash, a
    dollar sign, and the letters 's','l','t'. I am not clear on whether or
    not that's what you want. I find it likely, however, that you wanted an
    array containing the variable $slt. For that, you would do:
    my @slt_opt = $slt;
    or if you feel the need for explict parens:
    my @slt_opt = ($slt);


    > $frame3->Label(-text => "Slot ID: ")->pack(-side => 'left',
    > -anchor => 's',
    > -expand => 1);
    >
    > $frame3->Optionmenu(-variable => \$slots,
    > -options => [@slt_opt],
    > -command => [sub {print "args=@_\n"}, 'First']);
    >
    > ======================================
    > Am I reaching with what qw can do here?


    Your post does not make clear what you expect qw// to do. qw// takes a
    space-separated list of barewords, and transforms it into a list of
    single-quoted strings. Under no circumstances does variable
    interpolation happen in qw//. To wit:

    qw/foo bar baz/ is equivalent to ('foo', 'bar', 'baz')
    qw/$name $id $addr/ is equivalent to ('$name', '$id', '$addr') NOT
    ($name, $id, $addr).

    Does this answer your question?

    Paul Lalli
     
    Paul Lalli, Jan 12, 2005
    #2
    1. Advertisements

  3. Paul Lalli Guest

    <> wrote in message
    news:...
    > I am attempting to build a Tk:Optionmenu pull down from a string that
    > is passed to a sub-routine from one of my menu items. The string may
    > look like this:
    > 2 3 8 10 14
    >
    > The string WILL change, which is why I want to pass the string to my
    > menu pulldown as such:
    >
    > my @slt_opt = qw/\$slt/;
    >
    > $frame3->Label(-text => "Slot ID: ")->pack(-side => 'left',
    > -anchor => 's',
    > -expand => 1);
    >
    > $frame3->Optionmenu(-variable => \$slots,
    > -options => [@slt_opt],
    > -command => [sub {print "args=@_\n"}, 'First']);


    Reading this again, I *think* I understand. Are you looking to have
    the -options parameter be a reference to an anonymous array containing
    2, 3, 8, 10, 14? If so, you are indeed confused about qw//. In fact,
    I'd say you're assuming the exact *opposite* of qw//'s functionality.
    :)

    Instead, you should populate the anonymous array with the return value
    of the split() function:
    my $slt = '2 3 8 10 14';
    .. . .
    -options => [split ' ', $slt]

    Hope this helps,
    Paul Lalli
     
    Paul Lalli, Jan 12, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alvin Bruney

    Threads.. Session var lost, App var ok

    Alvin Bruney, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    459
    rooster575
    Dec 2, 2003
  2. thomson
    Replies:
    10
    Views:
    2,624
    Eliyahu Goldin
    Jun 20, 2005
  3. thomson
    Replies:
    0
    Views:
    480
    thomson
    Jun 20, 2005
  4. Fred
    Replies:
    3
    Views:
    418
    Alf P. Steinbach
    Aug 10, 2003
  5. Alex Vinokur
    Replies:
    4
    Views:
    548
    Ron Natalie
    Sep 24, 2003
Loading...

Share This Page