|
Posted by John W. Krahn on April 24, 2008, 7:08 pm
Please log in for more thread options
ds456 wrote:
> I am trying to build Perl/TK components from scratch inside another TK
> program. I am stumped on how to represent the " => " in a statement
> inside a variable.
>
> This is a normal statement and works ...
> $xw->Button(-text => "This is text")->place(-x => 1, -y => 1);
>
> So does this...
> $attrib = '-text';
> $value = 'This is text'
> $xw->Button($attrib => $value)->place(-x => 1, -y => 1);
>
> Since the "equal/greater than" is a signal to the compiler rather than a
> literal string, this does not...
> $string = "-title => 'This is text'";
> $xw->Button($string)->place(-x => 1, -y => 1);
>
> I am trying to programatically build the inside of the parens and add
> various options based on user input, but can't figure out how to represent
> the => .
>
> Suggestions anybody. Or is the above as clear as mud?
Assuming that the attributes are unique you could use a hash:
my %attributes = ( -title => 'This is text' );
$xw->Button( %attributes )->place( -x => 1, -y => 1 );
Or in either case you could use an array:
my @attributes = ( -title => 'This is text' );
$xw->Button( @attributes )->place( -x => 1, -y => 1 );
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
|