From: A. Sinan Unur on
ds456 <dsxxxxx(a)yahoo.com> wrote in
news:SPWdnfNw-qCDv4zVnZ2dnUVZ_jidnZ2d(a)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(a)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/
From: ds456 on
> 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
From: A. Sinan Unur on
ds456 <dsxxxxx(a)yahoo.com> wrote in
news:M5OdncJMt5nssIzVnZ2dnUVZ_hCdnZ2d(a)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(a)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/
From: Gerry Ford on

"ds456" <dsxxxxx(a)yahoo.com> wrote in message
news:M5OdncJMt5nssIzVnZ2dnUVZ_hCdnZ2d(a)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


From: Uri Guttman on
>>>>> "d" == ds456 <dsxxxxx(a)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(a)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 ---------