how to check whether the field is filled or empty in perl TK
how to check whether the field is filled or empty in perl TK
am 14.11.2007 15:40:28 von king
I have a perl TK UI. Where the user will feed the Register value.
############################################################ ##########
our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pa ck();
our $pre1=$left2->Label(-background=>'green', -width=>12,-
borderwidth=>2, -relief=>'sunken')->Entry()-> pack();
our $ent1=$left2->Entry(-background=>'green', -width=>12,-
borderwidth=>2, -relief=>'sunken')->pack();
$Register_1=$ent1->get();
############################################################ ########
I want to check whether the user has feeded the register value or kept
it null.
so if i am doing a check like
if (defined $Register_1) { do this}
else { do this}
but its not working. How can i check whether the user has given some
value in the register block or not.
Re: how to check whether the field is filled or empty in perl TK
am 14.11.2007 18:12:47 von Jim Gibson
In article <1195050096.604403.314370@k35g2000prh.googlegroups.com>,
king wrote:
> I have a perl TK UI. Where the user will feed the Register value.
>
> ############################################################ ##########
> our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pa ck();
>
> our $pre1=$left2->Label(-background=>'green', -width=>12,-
> borderwidth=>2, -relief=>'sunken')->Entry()-> pack();
> our $ent1=$left2->Entry(-background=>'green', -width=>12,-
> borderwidth=>2, -relief=>'sunken')->pack();
>
> $Register_1=$ent1->get();
> ############################################################ ########
>
> I want to check whether the user has feeded the register value or kept
> it null.
>
> so if i am doing a check like
>
> if (defined $Register_1) { do this}
> else { do this}
>
> but its not working. How can i check whether the user has given some
> value in the register block or not.
Check if length($Register_1) is equal to 0.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Re: how to check whether the field is filled or empty in perl TK
am 15.11.2007 01:00:42 von Ben Morrow
Quoth king :
> I have a perl TK UI. Where the user will feed the Register value.
>
> ############################################################ ##########
> our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pa ck();
>
> our $pre1=$left2->Label(-background=>'green', -width=>12,-
> borderwidth=>2, -relief=>'sunken')->Entry()-> pack();
> our $ent1=$left2->Entry(-background=>'green', -width=>12,-
> borderwidth=>2, -relief=>'sunken')->pack();
>
> $Register_1=$ent1->get();
It's usually easier to tie the Entry directly to the variable, like this
my $Register_1;
our $ent1 = $left2->Entry(
-background => 'green',
-width => 12,
-borderwidth => 2,
-relief => 'sunken',
-textvariable => \$Register_1,
)->pack;
Then the value in $Register_1 is always the same as the value of the
Entry: changing either changes the other automatically.
Also, variable names with numbers in are usually a sign you should be
using a data structure instead; most obviously an array, but it would
probably be better to give your widgets meaningful names and use a hash.
Ben
Re: how to check whether the field is filled or empty in perl TK
am 15.11.2007 16:17:48 von king
On Nov 14, 10:12 pm, Jim Gibson wrote:
> In article <1195050096.604403.314...@k35g2000prh.googlegroups.com>,
>
>
>
> king wrote:
> > I have a perl TK UI. Where the user will feed the Register value.
>
> > ############################################################ ##########
> > our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pa ck();
>
> > our $pre1=$left2->Label(-background=>'green', -width=>12,-
> > borderwidth=>2, -relief=>'sunken')->Entry()-> pack();
> > our $ent1=$left2->Entry(-background=>'green', -width=>12,-
> > borderwidth=>2, -relief=>'sunken')->pack();
>
> > $Register_1=$ent1->get();
> > ############################################################ ########
>
> > I want to check whether the user has feeded the register value or kept
> > it null.
>
> > so if i am doing a check like
>
> > if (defined $Register_1) { do this}
> > else { do this}
>
> > but its not working. How can i check whether the user has given some
> > value in the register block or not.
>
> Check if length($Register_1) is equal to 0.
>
> --
> Jim Gibson
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com
Thanks for your valuble suggestion. Now its working for my
requirement.
But lets say I have put a value 2 in that field.
and if the value is 2 do something else do something else.
Like
if ($Register_1 == 2) { do this}
> > else { do this}
But value matching is also not working. Is there anyway to check that
value exactly matches or not.