[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] &MacPerl'Pick --> Variable



At 12.14 1998.03.19, Dakota Duff wrote:
>Why won't this work?  Can anyone help?

A hint: "this does not work" is deprecated syntax.  It is more helpful to
tell us what you expect, and what you got.

>if ($anim == "Buffalo")   {
>  $aa = "BUF";

If you had use warnings with the script, they would have told you that you
are trying a numeric equivalency test on something that is not a number.
You should use eq instead of ==.

Just for kicks, I rewrote it into what I think is a Better Way.  By using a
hash lookup table, you don't need all those equivalency tests.

(Also, the &MacPerl'Pick syntac is deprecated.  You can use the & still if
you like, but you should use :: instead of ' as the package delimiter,
though the ' will continue to work.)

#!perl -w
$anim = MacPerl::Pick('What kind?', 'Buffalo', 'Elk');
$spec = MacPerl::Pick('What kind?',
    'Bull', 'Cow', 'Bull Calf', 'Heifer Calf',
    '1 YR Old Bull', '1 YR Old Heifer',
    '2 YR Old Bull', '2 YR Old Heifer'
);

@anim = ('Buffalo', 'Elk');
%anim = ('Buffalo' => 'BUF', 'Elk' => 'ELK');
@spec = (
    'Bull', 'Cow', 'Bull Calf', 'Heifer Calf',
    '1 YR Old Bull', '1 YR Old Heifer',
    '2 YR Old Bull', '2 YR Old Heifer'
);
%spec = (
    'Bull' => 'BULL', 'Cow' => 'COWS', 'Bull Calf' => 'BCAV',
    'Heifer Calf' => 'HCAV', '1 YR Old Bull' => '1YRB',
    '1 YR Old Heifer' => '1YRH', '2 YR Old Bull'=> '2YRB',
    '2 YR Old Heifer' => '2YRH'
);

print $anim{$anim} . $spec{$spec};

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==               New Book:  MacPerl: Power and Ease               ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch