CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Third column not displaying properly

 



logan
New User

Oct 17, 2012, 3:55 AM

Post #1 of 5 (1076 views)
Third column not displaying properly Can't Post

Table3.pm

Code
package Table3; 

use Text::Table;

sub addrow {
$tb=${$_[0]};
$tb->load( [ $_[1], $_[2] ], $_[3] );
}

use Storable;

sub save {
$htb=$_[0];
store $htb, 'filename';
}

sub retriv {
$htb=retrieve('filename');
return $htb;
}

1;


CmdLine.pm

Code
package CmdLine; 
use Table3;

sub create {
my $tb=Text::Table->new("Time", "Scared feeling", "Akathisia");
return $tb;
}

# touch 'filename'
if (! -e 'filename') {
$tb=create;
Table3::save(\$tb);
}

my $htb=Table3::retriv;
my $tb=${$htb};

use Term::Menu;

while(1) {
my $prompt=new Term::Menu;
my $answer=$prompt->menu(
add => ["Add new entry.", 'a'],
save => ["Save", 's'],
view => ["View", 'v'],
quit => ["Quit", 'q']
);
if ($answer eq 'quit') {
last;
}
elsif ($answer eq 'add') {
if (! -e 'filename') {
$tb=create;
Table3::save(\$tb);
}
# add new entry here.
my $entry={'timeofday'=>"", 'scared'=>"", 'aka'=>""};
while (1) {
my $prompt=new Term::Menu;
my $answer=$prompt->menu(
save => ["Save entry", 'v'],
timeofday => ["Time of day", 't'],
scared => ["Scared feeling", 's'],
aka => ["Akathisia", 'a'],
back => ["Back", 'b']
);
if ($answer eq 'timeofday') {
$entry->{'timeofday'}=<>;
}
elsif ($answer eq 'scared') {
$entry->{'scared'}=<>;
}
elsif ($answer eq 'aka') {
$entry->{'aka'}=<>;
}
elsif ($answer eq 'back') {
last;
}
elsif ($answer eq 'save') {
Table3::addrow(\$tb, $entry->{'timeofday'}, $entry->{'scared'}, $entry->{'aka'});
}
else {}
}

#Table3::addrow(\$tb, '3 days ago', 'no');
}
elsif ($answer eq 'save') {
Table3::save(\$tb);
}
elsif ($answer eq 'view') {
$htb=Table3::retriv;
print ${$htb};
}
else {}
}



logan
New User

Oct 17, 2012, 4:07 AM

Post #2 of 5 (1071 views)
Re: [logan] Third column not displaying properly [In reply to] Can't Post


Code
$tb->load( [ $_[1], $_[2] ], $_[3] );


oops


wickedxter
User

Oct 17, 2012, 9:36 AM

Post #3 of 5 (1042 views)
Re: [logan] Third column not displaying properly [In reply to] Can't Post

so im guessing this is were ur problem lies?


Code
 
$tb->load( [ $_[1], $_[2] ], $_[3] );

#should be

$tb->load( $_[1], $_[2] , $_[3] );



logan
New User

Oct 17, 2012, 9:39 PM

Post #4 of 5 (1035 views)
Re: [wickedxter] Third column not displaying properly [In reply to] Can't Post


In Reply To
so im guessing this is were ur problem lies?


Code
 
$tb->load( [ $_[1], $_[2] ], $_[3] );

#should be

$tb->load( $_[1], $_[2] , $_[3] );



no

Code
$tb–>load( [ $_[1], $_[2], $_[3] ] ];



FishMonger
Veteran / Moderator

Oct 18, 2012, 7:08 AM

Post #5 of 5 (1029 views)
Re: [logan] Third column not displaying properly [In reply to] Can't Post

Your starting point should to add the strict and warnings pragmas to both modules and fix the problems that they point out. Those pragmas should be in every script you write.

All use statements should be at the top, not interspersed in the code.

The subs should be exported.

It would be cleaner to use a dispatch table instead of the if/elsif/else block(s).

The empty else{} block should be removed.

Data retrieved via the <> operator should be chomp'd to remove the line terminator.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives