[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1351
  • Last Modified:

perl tk : Undefined subroutine &main::Label

I am teaching myself perl-tk.

here is my "first" run:

#!/usr/bin/perl -w
# use strict;
 use Tk;                                          # Slurp the module in.
# -------------------------------------------------------
# Create a main window
# -------------------------------------------------------
my $top = MainWindow->new();
$top->title ("Simple");
# -------------------------------------------------------
# Instantiate widgets and arrange them
# -------------------------------------------------------
$l = $top-->Label('text'   => 'hello',            # label properties
                 'anchor' => 'n',                 # anchor text to "north"
                 'relief' => 'groove',            # border style
                 'width'  =>  10, 'height' => 3);  # 10 chars wide, 3 high.

$l->pack();      # Give it a default place within the main window
# -------------------------------------------------------
# Sit in an infinite loop dispatching incoming events.
# -------------------------------------------------------
MainLoop();


I am using linux station over unix.

talm> perltk simple.prl
Undefined subroutine &main::Label called at simple.prl line 12.

what is the problem with this struct?

thanks,
tal


I understand that $top is struct from type "MainWindow"
0
Talmash
Asked:
Talmash
  • 2
1 Solution
 
FishMongerCommented:
Change:
$l = $top-->

To:
$l = $top->

Also, you should be running under strict.
0
 
FishMongerCommented:
Additionally, you should not quote the options.
#!/usr/bin/perl
 
use warnings;
use strict;
use Tk;                                          # Slurp the module in.
# -------------------------------------------------------
# Create a main window
# -------------------------------------------------------
my $top = MainWindow->new();
$top->title ("Simple");
# -------------------------------------------------------
# Instantiate widgets and arrange them
# -------------------------------------------------------
my $l = $top->Label(-text   => 'hello',            # label properties
                    -anchor => 'n',                 # anchor text to "north"
                    -relief => 'groove',            # border style
                    -width  =>  10, -height => 3);  # 10 chars wide, 3 high.
 
$l->pack();      # Give it a default place within the main window
# -------------------------------------------------------
# Sit in an infinite loop dispatching incoming events.
# -------------------------------------------------------
MainLoop();

Open in new window

0
 
TalmashAuthor Commented:
thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now