... [how] you knew to promote my string to an array?

A subroutine such as your  add() can be called with an argument list; choroba just made the arguments you wanted to pass into an expression (specifically, an array) that would be accepted as a list expression by a subroutine call; see perlsub. (BTW: There's no need to use the  & sigil for a subroutine call. Indeed, you should avoid this syntax because it has some oddball effects; see especially the paragraph beginning 'A subroutine may be called using an explicit "&" prefix.' in the DESCRIPTION section of perlsub.) (Also BTW: IMHO it's not, in general, a good idea to use the variable names  $a $b as lexical names even in short example code; these are Perl special variables and have special significance and usage; see perlvar.)

... arguments ... all these generated the same answer ...

I'll avoid using the  & sigil prefix in all discussion and examples.
    print add($a, $b) . "\n";
Pass a list of two scalars (list elements are always scalars) to the  add subroutine.
    my $opt = "$a, $b";
    print add(eval($opt)) . "\n";
First, eval the Perl string list expression  "$a, $b" and then pass the resulting list returned by eval to the subroutine.
    my @opt = ($a, $b);
    print add(@opt) . "\n";
Expand an array to the argument list of a subroutine call.

c:\@Work\Perl\monks>perl -wMstrict -le "my ($x, $y) = (2, 3); ;; print add($x, $y); ;; my $opt_dq = \"$x, $y\"; print add(eval($opt_dq)); ;; my $opt_sq = '$x, $y'; print add(eval($opt_sq)); ;; my @opt = ($x, $y); print add(@opt); ;; my @ra = (99, @opt, 98); print add(@ra[ 2, 1 ]); ;; exit; ;; sub add { my ($x, $y) = @_; return $x + $y; } " 5 5 5 5 5

Questions:

... dash notation ...

This is notation used in Tcl/Tk that was, AFAIU, intentionally imported into | implemented in Perl/Tk just to make it look more familiar. Otherwise, the  => is just a "fat comma"; see perlop.


Give a man a fish:  <%-{-{-{-<


In reply to Re^4: tk option+value in variable? by AnomalousMonk
in thread tk option+value in variable? by cniggeler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.