how to check whether the field is filled or empty in perl TK

K

king

I have a perl TK UI. Where the user will feed the Register value.

######################################################################
our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pack();

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.
 
B

Ben Morrow

Quoth king said:
I have a perl TK UI. Where the user will feed the Register value.

######################################################################
our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pack();

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
 
K

king

king said:
I have a perl TK UI. Where the user will feed the Register value.
######################################################################
our $t2=$left1->Label(-text=>'Register',-background=>'cyan')->pack();
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();

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


----------------------------------------------------------

----------------------------------------------------------
color]

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}
But value matching is also not working. Is there anyway to check that
value exactly matches or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top