[30232] in Perl-Users-Digest
Perl-Users Digest, Issue: 1475 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 25 16:31:31 2008
Date: Fri, 25 Apr 2008 13:31:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 25 Apr 2008 Volume: 11 Number: 1475
Today's topics:
How to build the => in a statement? <dsxxxxx@yahoo.com>
Re: How to build the => in a statement? <someone@example.com>
Re: How to build the => in a statement? <1usa@llenroc.ude.invalid>
Re: How to build the => in a statement? <dsxxxxx@yahoo.com>
Re: How to build the => in a statement? <dsxxxxx@yahoo.com>
Re: How to build the => in a statement? <1usa@llenroc.ude.invalid>
Re: How to build the => in a statement? <dsxxxxx@yahoo.com>
Re: How to build the => in a statement? <1usa@llenroc.ude.invalid>
Re: How to build the => in a statement? <gerry@nowhere.ford>
Re: How to build the => in a statement? <uri@stemsystems.com>
Re: How to build the => in a statement? <ben@morrow.me.uk>
Re: How to build the => in a statement? <1usa@llenroc.ude.invalid>
Re: How to build the => in a statement? <ron@nowhere.ford>
Re: How to build the => in a statement? <abigail@abigail.be>
Re: How to build the => in a statement? <damercer@comcast.net>
Re: How to build the => in a statement? <damercer@comcast.net>
Re: How to build the => in a statement? <damercer@comcast.net>
Re: How to build the => in a statement? <john@castleamber.com>
Re: How to build the => in a statement? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Apr 2008 17:50:23 -0500
From: ds456 <dsxxxxx@yahoo.com>
Subject: How to build the => in a statement?
Message-Id: <AM-dnRU81ccyk4zVnZ2dnUVZ_vWdnZ2d@oco.net>
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?
DS
------------------------------
Date: Thu, 24 Apr 2008 23:08:19 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to build the => in a statement?
Message-Id: <Dp8Qj.1957$PM5.1559@edtnps92>
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
------------------------------
Date: Thu, 24 Apr 2008 23:09:14 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to build the => in a statement?
Message-Id: <Xns9A8AC2D602077asu1cornelledu@127.0.0.1>
ds456 <dsxxxxx@yahoo.com> wrote in
news:AM-dnRU81ccyk4zVnZ2dnUVZ_vWdnZ2d@oco.net:
> 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
Those are method arguments. Not run time strings.
> and add
> various options based on user input, but can't figure out how to
> represent the => .
This is a red herring. What you need to do is to pass the correct
arguments to the method.
So, if for some reason, you don't have the $attrib and $value separately
but embedded in a string of the form
"attrib => whatever"
you need to extract those two values and pass them as arguments to the
method call.
Easiest way to do that is
my ($attrib, $value) = split /\s*=>\s*/, $string;
But, given that you had obtain these things from a user interface means
at some point you have access to the attribute you want to set and the
value you want to set it to separately, so just use them as arguments.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Thu, 24 Apr 2008 19:10:34 -0500
From: ds456 <dsxxxxx@yahoo.com>
Subject: Re: How to build the => in a statement?
Message-Id: <SPWdnfBw-qDnvIzVnZ2dnUVZ_jidnZ2d@oco.net>
> Or in either case you could use an array:
>
> my @attributes = ( -title => 'This is text' );
>
> $xw->Button( @attributes )->place( -x => 1, -y => 1 );
>
>
>
> John
Thanks for the reply John, but that doesn't work for me either. Below is
the actual code and part of the error message.
my @attributes = ( -title => 'This is text');
$xw->Button( @attributes )->place(-x => 1, -y => 1);
#Tk::Error: unknown option "-title" at /usr/lib/perl5/Tk/Widget.pm line
205.
------------------------------
Date: Thu, 24 Apr 2008 19:13:18 -0500
From: ds456 <dsxxxxx@yahoo.com>
Subject: Re: How to build the => in a statement?
Message-Id: <SPWdnfNw-qCDv4zVnZ2dnUVZ_jidnZ2d@oco.net>
O
> This is a red herring. What you need to do is to pass the correct
> arguments to the method.
>
> So, if for some reason, you don't have the $attrib and $value separately
> but embedded in a string of the form
>
> "attrib => whatever"
>
> you need to extract those two values and pass them as arguments to the
> method call.
Thanks for the reply Sinan, but I didn't make my question clear.
I have the attributes and values already separate, either in an array or
hash.
Example
$widget = Button;
-text 'OK'
-width 10
-state 'disabled'
-command '\&okcommand'
and so forth.
I don't want to hard code those widget options since there may be from 1
to 20 or so of them, depending on what kind of widget it is and what the
user wants.
Rather I want to feed the attributes and values to a routine that will
build the widget with whatever number options I pass to it.
Sort of like so...
foreach $key (keys @%hash) {
#Some code to build a string from the current hash key...
}
#Finally, a string is built that looks good...
$string = "-text => 'OK',
-width => 10, -state => 'disabled', -command => '\&okcommand'";
$xw->$widget($string)->pack();
But this doesn't work because the => operator can't be imbedded in the
string.
To put it logically, rather than in code, I am trying to do this...
$wx->$widget(
foreach $key (keys %hash){
$key => $hash{$key} ,
}
)->place(-x => somexpos, -y => someypos);
Thanks again
DS
------------------------------
Date: Fri, 25 Apr 2008 00:26:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to build the => in a statement?
Message-Id: <Xns9A8ACFF1F9A87asu1cornelledu@127.0.0.1>
ds456 <dsxxxxx@yahoo.com> wrote in
news:SPWdnfNw-qCDv4zVnZ2dnUVZ_jidnZ2d@oco.net:
> O
>> This is a red herring. What you need to do is to pass the correct
>> arguments to the method.
>>
>> So, if for some reason, you don't have the $attrib and $value
>> separately but embedded in a string of the form
>>
>> "attrib => whatever"
>>
>> you need to extract those two values and pass them as arguments to
>> the method call.
>
>
> Thanks for the reply Sinan, but I didn't make my question clear.
>
> I have the attributes and values already separate, either in an array
> or hash.
>
> Example
>
> $widget = Button;
> -text 'OK'
> -width 10
> -state 'disabled'
> -command '\&okcommand'
That is neither an array nor a hash. Have you seen the posting
guidelines for this group?
Post code. Code we can see and run. Not vague descriptions.
> Sort of like so...
>
> foreach $key (keys @%hash) {
> #Some code to build a string from the current hash key...
Yeah, where on God's green earth under God's lovely blue sky is that
code???
> #Finally, a string is built that looks good...
Beauty is in the eye of the beholder.
I do not understand you. The hash keys are the attributes (I am
assuming) and the hash contains the values for those attributes.
Use them
> $string = "-text => 'OK',
> -width => 10, -state => 'disabled', -command => '\&okcommand'";
From this, am I to assume that the hash originally contained
my %hash = (
-text => 'OK',
-width => 10,
-state => 'disabled',
-command => \&okcommand,
);
> $xw->$widget($string)->pack();
$xw->$widget(%hash)->pack;
> But this doesn't work because the => operator can't be imbedded
> in the string.
It can be. The run time string is not source code though, so it does not
mean the same thing. The method call expects a list of arguments not a
single stringified version of it.
> To put it logically, rather than in code, I am trying to do this...
>
> $wx->$widget(
> foreach $key (keys %hash){
> $key => $hash{$key} ,
> }
> )->place(-x => somexpos, -y => someypos);
I am afraid your logic does not seem suitably matched to Perl's
semantics. You cannot embed a for loop in an argument list.
$wx->$widget( %hash )->place( ... );
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Thu, 24 Apr 2008 20:01:37 -0500
From: ds456 <dsxxxxx@yahoo.com>
Subject: Re: How to build the => in a statement?
Message-Id: <M5OdncJMt5nssIzVnZ2dnUVZ_hCdnZ2d@oco.net>
> That is neither an array nor a hash. Have you seen the posting
> guidelines for this group?
>
> Post code. Code we can see and run. Not vague descriptions.
Sorry, but the last time I posted (quite a while ago) I got ripped by two
"experts" who, in effect, said "Stop posting all the damn code that we
don't have time to figure out - just ask the question!"
Anyway, you supplied the answer. The below works. The => operator CAN be
embedded in a variable despite my proving to myself in about 4 dozen
ways that it can't.
>
>
> my %hash = (
> -text => 'OK',
> -width => 10,
> -state => 'disabled',
> -command => \&okcommand,
> );
>
> $xw->$widget(%hash)->pack;
>
I just have to figure out why yours worked and mine doesn't. But it is a
lot easier to start from something that works, than trying to figure out
why something doesn't.
Thanks
DS
------------------------------
Date: Fri, 25 Apr 2008 01:23:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to build the => in a statement?
Message-Id: <Xns9A8AD998E57F9asu1cornelledu@127.0.0.1>
ds456 <dsxxxxx@yahoo.com> wrote in
news:M5OdncJMt5nssIzVnZ2dnUVZ_hCdnZ2d@oco.net:
>> That is neither an array nor a hash. Have you seen the posting
>> guidelines for this group?
>>
>> Post code. Code we can see and run. Not vague descriptions.
>
> Sorry, but the last time I posted (quite a while ago) I got ripped by
> two "experts" who, in effect, said "Stop posting all the damn code
> that we don't have time to figure out - just ask the question!"
Please read the posting guidelines. They explain how best to help others
help you by posting an *appropriate* amount of code.
> Anyway, you supplied the answer. The below works. The => operator
> CAN be embedded in a variable despite my proving to myself in about 4
> dozen ways that it can't.
Because => (fat comma) is not really being embedded anywhere below. You
misunderstood.
>> my %hash = (
>> -text => 'OK',
>> -width => 10,
>> -state => 'disabled',
>> -command => \&okcommand,
>> );
>>
>> $xw->$widget(%hash)->pack;
>>
>
> I just have to figure out why yours worked and mine doesn't. But it
> is a lot easier to start from something that works, than trying to
> figure out why something doesn't.
The version above passes a list of arguments rather than a single
stringfied version of that.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Thu, 24 Apr 2008 20:30:11 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: How to build the => in a statement?
Message-Id: <1209086577_3108@news.newsgroups.com>
"ds456" <dsxxxxx@yahoo.com> wrote in message
news:M5OdncJMt5nssIzVnZ2dnUVZ_hCdnZ2d@oco.net...
>> That is neither an array nor a hash. Have you seen the posting
>> guidelines for this group?
>>
>> Post code. Code we can see and run. Not vague descriptions.
>
> Sorry, but the last time I posted (quite a while ago) I got ripped by two
> "experts" who, in effect, said "Stop posting all the damn code that we
> don't have time to figure out - just ask the question!"
>
> Anyway, you supplied the answer. The below works. The => operator CAN be
> embedded in a variable despite my proving to myself in about 4 dozen
> ways that it can't.
>
>>
>>
>> my %hash = (
>> -text => 'OK',
>> -width => 10,
>> -state => 'disabled',
>> -command => \&okcommand,
>> );
>>
>> $xw->$widget(%hash)->pack;
>>
>
> I just have to figure out why yours worked and mine doesn't. But it is a
> lot easier to start from something that works, than trying to figure out
> why something doesn't.
DS,
These people were toilet-trained at gunpoint or have some other definciency
to make up for with mean-spiritedness.
With the red herring bit, he was actually alleging that you obfuscated your
trail deliberately, as opposed to were dealing with a new syntax whose
compiler comments are riddles.
I'm on my way to find a better place to talk about scripting languages and
leaving Dr. Unur, the cbfalconer of c.l.p.misc, and people whose constant
thumping about posting rules simply point away from their own ferret-like
behavior, behind.
--
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell. The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."
~~ Butch Hancock
------------------------------
Date: Fri, 25 Apr 2008 03:59:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to build the => in a statement?
Message-Id: <x7skxak2j6.fsf@mail.sysarch.com>
>>>>> "d" == ds456 <dsxxxxx@yahoo.com> writes:
>> Or in either case you could use an array:
>>
>> my @attributes = ( -title => 'This is text' );
>>
>> $xw->Button( @attributes )->place( -x => 1, -y => 1 );
>>
>>
>>
>> John
d> Thanks for the reply John, but that doesn't work for me either. Below is
d> the actual code and part of the error message.
d> my @attributes = ( -title => 'This is text');
d> $xw->Button( @attributes )->place(-x => 1, -y => 1);
d> #Tk::Error: unknown option "-title" at /usr/lib/perl5/Tk/Widget.pm line
d> 205.
ever think to rtfm? your code works with -text. john mistakenly used
-title as an example. but his concept is perfectly valid and works. just
use the correct attribute keys as the error told you.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 25 Apr 2008 04:49:07 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to build the => in a statement?
Message-Id: <ju08e5-prp1.ln1@osiris.mauzo.dyndns.org>
Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
> ds456 <dsxxxxx@yahoo.com> wrote in
> news:SPWdnfNw-qCDv4zVnZ2dnUVZ_jidnZ2d@oco.net:
>
> > To put it logically, rather than in code, I am trying to do this...
> >
> > $wx->$widget(
> > foreach $key (keys %hash){
> > $key => $hash{$key} ,
> > }
> > )->place(-x => somexpos, -y => someypos);
>
> I am afraid your logic does not seem suitably matched to Perl's
> semantics. You cannot embed a for loop in an argument list.
>
> $wx->$widget( %hash )->place( ... );
You can. It's called 'map':
$wx->widget(
map { $_ => $hash{$key} } keys %hash
)->place(...);
The fact that that particular map statement is equivalent to simply
evaluating the hash in list context doesn't mean the construction isn't
useful in general.
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk
------------------------------
Date: Fri, 25 Apr 2008 04:16:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to build the => in a statement?
Message-Id: <Xns9A8B2C033459asu1cornelledu@127.0.0.1>
Ben Morrow <ben@morrow.me.uk> wrote in
news:ju08e5-prp1.ln1@osiris.mauzo.dyndns.org:
>
> Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
>> ds456 <dsxxxxx@yahoo.com> wrote in
>> news:SPWdnfNw-qCDv4zVnZ2dnUVZ_jidnZ2d@oco.net:
>>
>> > To put it logically, rather than in code, I am trying to do
>> > this...
>> >
>> > $wx->$widget(
>> > foreach $key (keys %hash){
>> > $key => $hash{$key} ,
>> > }
>> > )->place(-x => somexpos, -y => someypos);
>>
>> I am afraid your logic does not seem suitably matched to Perl's
>> semantics. You cannot embed a for loop in an argument list.
>>
>> $wx->$widget( %hash )->place( ... );
>
> You can. It's called 'map':
No, a for loop and map are different beasts. The fact that map is a one-
to-possibly many transformation applied to the argument list and each
invocation to map could be translated into a loop equivalent and vice
versa does not make map and for equivalent.
>
> $wx->widget(
> map { $_ => $hash{$key} } keys %hash
> )->place(...);
>
> The fact that that particular map statement is equivalent to simply
> evaluating the hash in list context doesn't mean the construction
> isn't useful in general.
Of course, map is useful. However, the OP was transforming the whole
hash into a single string that looked like how a method call would look
like in the source and was surprised when that did not do what he
thought it would do. Clearly, there is a mismatch between how the OP
understands Perl constructs and what they mean. What is the point of
throwing the identity transformation into the argument list?
After all, I could also do the following:
#!/usr/bin/perl
use strict;
use warnings;
my %hash = qw( a 1 b 2 c 3 );
yabadabadooo(
do {
my @args;
for my $k ( sort keys %hash ) {
push @args, $k, $hash{$k};
}
@args;
}
);
sub yabadabadooo { print "@_\n"; }
__END__
and thereby place a for loop in the function call but that is just as
irrelvant as your response.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Fri, 25 Apr 2008 03:17:34 -0500
From: "Ron Ford" <ron@nowhere.ford>
Subject: Re: How to build the => in a statement?
Message-Id: <1209111021_3131@news.newsgroups.com>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns9A8B2C033459asu1cornelledu@127.0.0.1...
> Ben Morrow <ben@morrow.me.uk> wrote in
> news:ju08e5-prp1.ln1@osiris.mauzo.dyndns.org:
>
>>
>> Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
>>> ds456 <dsxxxxx@yahoo.com> wrote in
>>> news:SPWdnfNw-qCDv4zVnZ2dnUVZ_jidnZ2d@oco.net:
>>>
>>> > To put it logically, rather than in code, I am trying to do
>>> > this...
>>> >
>>> > $wx->$widget(
>>> > foreach $key (keys %hash){
>>> > $key => $hash{$key} ,
>>> > }
>>> > )->place(-x => somexpos, -y => someypos);
>>>
>>> I am afraid your logic does not seem suitably matched to Perl's
>>> semantics. You cannot embed a for loop in an argument list.
>>>
>>> $wx->$widget( %hash )->place( ... );
>>
>> You can. It's called 'map':
>
> No, a for loop and map are different beasts. The fact that map is a one-
> to-possibly many transformation applied to the argument list and each
> invocation to map could be translated into a loop equivalent and vice
> versa does not make map and for equivalent.
>
>>
>> $wx->widget(
>> map { $_ => $hash{$key} } keys %hash
>> )->place(...);
>>
>> The fact that that particular map statement is equivalent to simply
>> evaluating the hash in list context doesn't mean the construction
>> isn't useful in general.
>
> Of course, map is useful. However, the OP was transforming the whole
> hash into a single string that looked like how a method call would look
> like in the source and was surprised when that did not do what he
> thought it would do. Clearly, there is a mismatch between how the OP
> understands Perl constructs and what they mean. What is the point of
> throwing the identity transformation into the argument list?
>
> After all, I could also do the following:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my %hash = qw( a 1 b 2 c 3 );
>
> yabadabadooo(
> do {
> my @args;
> for my $k ( sort keys %hash ) {
> push @args, $k, $hash{$k};
> }
> @args;
> }
> );
>
> sub yabadabadooo { print "@_\n"; }
>
> __END__
>
> and thereby place a for loop in the function call but that is just as
> irrelvant as your response.
>
> Sinan
>
> --
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://www.rehabitation.com/clpmisc/
and he misappropiated the number of phony figs in our new 100-acre real
estate version. Would he care to speak to that?
--
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell. The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."
~~ Butch Hancock
------------------------------
Date: 25 Apr 2008 09:43:31 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: How to build the => in a statement?
Message-Id: <slrng139u2.gu5.abigail@alexandra.abigail.be>
_
ds456 (dsxxxxx@yahoo.com) wrote on VCCCLI September MCMXCIII in
<URL:news:SPWdnfBw-qDnvIzVnZ2dnUVZ_jidnZ2d@oco.net>:
^^ > Or in either case you could use an array:
^^ >
^^ > my @attributes = ( -title => 'This is text' );
^^ >
^^ > $xw->Button( @attributes )->place( -x => 1, -y => 1 );
^^ >
^^ >
^^ >
^^ > John
^^
^^ Thanks for the reply John, but that doesn't work for me either. Below is
^^ the actual code and part of the error message.
^^
^^
^^ my @attributes = ( -title => 'This is text');
^^ $xw->Button( @attributes )->place(-x => 1, -y => 1);
^^
^^ #Tk::Error: unknown option "-title" at /usr/lib/perl5/Tk/Widget.pm line
^^ 205.
From your original post:
>> 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);
You start with '-text', and then go to '-title'.
Guess where the problem lies.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: Fri, 25 Apr 2008 12:05:05 -0500
From: "Dan Mercer" <damercer@comcast.net>
Subject: Re: How to build the => in a statement?
Message-Id: <xZydnQPeSMsrjY_VnZ2dnUVZ_hmtnZ2d@comcast.com>
"ds456" <dsxxxxx@yahoo.com> wrote in message
news:AM-dnRU81ccyk4zVnZ2dnUVZ_vWdnZ2d@oco.net...
>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?
I think you have a fundamental misunderstanding of what => does. It's just
a
comma with the added advantage of quoting the previous word. So
$xw->Button(-text => "This is text")->place(-x => 1, -y => 1);
is equivalent to
$xw->Button("-text", "This is text")->place("-x", 1, "-y", 1);
You can always just put the pairs in an array and pass the array.
The alternate comma operator can add clarity. For instance,
the kill command takes a list of values as parameters, the first value of
which
identifies the signal. That value can be either a number or symbolic text.
kill 15, $pid1, $pid2;
can also be represented as
kill "TERM, $pid1, $pid2;
But I find it a little clearer to use
kill TERM => $pid1, $pid2;
Conceptually we write
kill SIGNAL, LIST
as a synopsis, but the kill function simply receives and processes a list.
So while you might
be thinking there's some Tk special magic in the use of '=>' in its
parameters, remember
the function is just getting a paired list. And why is it a paired list?
Because the data
will be turned into a hash in the object.
So, build an array and pass the array or build a hash and pass the hash,
it's six of one
and half dozen of another and Tk won't know the difference anyhow.
Dan Mercer
>
> DS
------------------------------
Date: Fri, 25 Apr 2008 12:11:35 -0500
From: "Dan Mercer" <damercer@comcast.net>
Subject: Re: How to build the => in a statement?
Message-Id: <xZydnT3eSMsrjY_VnZ2dnUVZ_hninZ2d@comcast.com>
"ds456" <dsxxxxx@yahoo.com> wrote in message
news:AM-dnRU81ccyk4zVnZ2dnUVZ_vWdnZ2d@oco.net...
>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?
I think you have a fundamental misunderstanding of what => does. It's just
a
comma with the added advantage of quoting the previous word. So
$xw->Button(-text => "This is text")->place(-x => 1, -y => 1);
is equivalent to
$xw->Button("-text", "This is text")->place("-x", 1, "-y", 1);
You can always just put the pairs in an array and pass the array.
The alternate comma operator can add clarity. For instance,
the kill command takes a list of values as parameters, the first value of
which identifies the signal. That value can be either a number or symbolic
text.
kill 15, $pid1, $pid2;
can also be represented as
kill "TERM, $pid1, $pid2;
But I find it a little clearer to use
kill TERM => $pid1, $pid2;
Conceptually we write
kill SIGNAL, LIST
as a synopsis, but the kill function simply receives and processes a list.
So while you might be thinking there's some Tk special magic in the use of
'=>' in its
parameters, remember the function is just getting a paired list. And why
is it a paired list?
Because the data will be turned into a hash in the object.
So, build an array and pass the array or build a hash and pass the hash,
it's six of one and half dozen of another and Tk won't know the difference
anyhow.
Dan Mercer
>
> DS
------------------------------
Date: Fri, 25 Apr 2008 12:08:32 -0500
From: "Dan Mercer" <damercer@comcast.net>
Subject: Re: How to build the => in a statement?
Message-Id: <xZydnQLeSMsrjY_VnZ2dnUVZ_hninZ2d@comcast.com>
"ds456" <dsxxxxx@yahoo.com> wrote in message
news:AM-dnRU81ccyk4zVnZ2dnUVZ_vWdnZ2d@oco.net...
>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?
I think you have a fundamental misunderstanding of what => does. It's just
a
comma with the added advantage of quoting the previous word. So
$xw->Button(-text => "This is text")->place(-x => 1, -y => 1);
is equivalent to
$xw->Button("-text", "This is text")->place("-x", 1, "-y", 1);
You can always just put the pairs in an array and pass the array.
The alternate comma operator can add clarity. For instance,
the kill command takes a list of values as parameters, the first value of
which identifies the signal. That value can be either a number or symbolic
text.
kill 15, $pid1, $pid2;
can also be represented as
kill "TERM, $pid1, $pid2;
But I find it a little clearer to use
kill TERM => $pid1, $pid2;
Conceptually we write
kill SIGNAL, LIST
as a synopsis, but the kill function simply receives and processes a list.
So while you might be thinking there's some Tk special magic in the use of
'=>' in its
parameters, remember the function is just getting a paired list. And why
is it a paired list?
Because the data will be turned into a hash in the object.
So, build an array and pass the array or build a hash and pass the hash,
it's six of one and half dozen of another and Tk won't know the difference
anyhow.
Dan Mercer
>
> DS
------------------------------
Date: 25 Apr 2008 17:39:31 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to build the => in a statement?
Message-Id: <Xns9A8B80C59E1AFcastleamber@130.133.1.4>
"Ron Ford" <ron@nowhere.ford> wrote:
If you morph again to keep trolling here, I'll contact your usenet
provider.
If you disagree with how some people post here, show them a better
example instead of trolling (again) this group. Sinan (IIRC) made a
valid point recently on people posting here:
* those who can help (even though it's not always in a nice way, you'll
get in the end help, and for free, even if you're too lazy to read
a book and/or documentation),
* those who can't just troll.
Based on your earlier trolls I would say that "can't" must be the story of
your life.
*ploink*
--
John
http://johnbokma.com/perl/
------------------------------
Date: Fri, 25 Apr 2008 19:05:43 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to build the => in a statement?
Message-Id: <n4j9e5-8mc.ln1@osiris.mauzo.dyndns.org>
Quoth "Dan Mercer" <damercer@comcast.net>:
>
> I think you have a fundamental misunderstanding of what => does. It's just
> a
> comma with the added advantage of quoting the previous word. So
>
> $xw->Button(-text => "This is text")->place(-x => 1, -y => 1);
>
> is equivalent to
>
> $xw->Button("-text", "This is text")->place("-x", 1, "-y", 1);
Strictly, it is equivalent to
$xw->Button( ( - "text" ), "This is text" )->place(...);
which is (due to a special case in unary minus added for Tk's benefit)
equivalent to
$xw->Button( "-text", "This is text" )->place(...);
This is important because '-' is not part of \w, so something like
( foo-bar => 1 )
will *not* be autoquoted.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk (Kate Rusby)
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1475
***************************************