Trying to get CGI selection to print

N

Nene

I'm still in the process of learning Perl CGI and OOP for Perl.

I'm trying get what I selected to print to screen but It doesn't. I
want to print $object->getNodes(), br;

#!/usr/bin/perl -w
use strict;
use CGI ':standard';
use Practice;
use Data::Dumper;
my $status;

print "Content-type: text/html\n\n";
print start_html(-title=>'ESP F5 Control',
-bgcolor=>'black',
-text=>'#00FFFF');
print "<h1>DR F5 Control</h1>\n";
print_prompt();
do_work();
print end_html;
sub print_prompt {
print start_form;
print "\n", br;
print popup_menu(
-name=>'Env',
-values=>['abc','cde','efg'],
-linebreak=>'yes');

print "<p><em>Servers</em><br>",
checkbox_group(
-name=>'sequence',
-default=>'',
-linebreak=>'true',
-values=>['10.254.22.66',
'10.254.22.67',
'10.254.22.68',
'10.254.22.69',
'10.254.22.70',
'10.254.22.71',
'10.254.22.72',
'10.254.22.73'],

-labels=>\my %labels,
-attributes=>\my %attributes);

print "<p><em>What action to execute?</em> ";
print "\n", br;
print radio_group(-name=>'status',
-
values=>['enabled','disabled']);

print "\n\n", br;
print "\n", br submit('Action','Submit');
print "\n\n", br;
print endform;
print "<hr>\n";
}

my @n;
sub do_work {
##################################
##################################

my(@values,$key);

print "<h2>Here are the current settings in this
form</h2>";
@values = param('sequence');
chomp(@values);

for my $value (@values) {
my $line = "$value:a";
push(@n, "$line");
}
#####################################

}

my $object = new Practice();
$object->setNodes(@n);
print $object->getNodes(), br;

#####
package Practice;

sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}

sub setEsp {
my ( $self, @esp ) = @_;
$self->{_esp} = \@esp if @esp;
return $self->{_esp};
}

sub getEsp {
my( $self ) = @_;
return @{ $self->{_esp} };
}

sub setStatus {
my ( $self, $status ) = @_;
$self->{_status} = \$status if $status;
return $self->{_status};
}

sub getStatus {
my( $self ) = @_;
return @{ $self->{_status} };
}

sub setNodes {
my ( $self, $nodes ) = @_;
$self->{_nodes} = \@nodes if @nodes;
return $self->{_nodes};
}

sub getNodes {
my( $self ) = @_;
return @{ $self->{_nodes} };
}

1;
~
 
S

Steve May

I'm still in the process of learning Perl CGI and OOP for Perl.

I'm trying get what I selected to print to screen but It doesn't. I
want to print $object->getNodes(), br;
sub setNodes {
my ( $self, $nodes ) = @_;
$self->{_nodes} = \@nodes if @nodes;
return $self->{_nodes};
}

Methinks $nodes is not the same thing as @nodes above...

\s
 
J

J. Gleixner

I'm still in the process of learning Perl CGI and OOP for Perl.

I'm trying get what I selected to print to screen but It doesn't. I
want to print $object->getNodes(), br;

When you're trying to learn something, simplify your problem by
doing one thing at a time. Remove CGI from the equation. Once
you get your program to print what you're looking for, *then* add
in the CGI parts.
print "Content-type: text/html\n\n";
[...]

If you're going to 'use CGI qw( :standard )' you can really
simplify your code, by actually using the methods it provides.
Oh, and print can accept a list.

e.g.

print header(),
start_html(
-title => 'ESP F5 Control',
-bgcolor => 'black',
-text => '#00ffff'),
h1( 'DR F5 Control' ), "\n";
 
P

Peter J. Holzer

You want

use warnings;

instead of -w. warnings allows you to turn some warnings off for
sections of your code where you need to,

This works with -w, too:

#!/usr/bin/perl -w
use strict;

my $x;

print "outside:\n";
print "-->$x<--\n";

{
no warnings 'uninitialized';
print "inside:\n";
print "-->$x<--\n";
}

print "outside again:\n";
print "-->$x<--\n";
__END__
outside:
Use of uninitialized value $x in concatenation (.) or string at ./foo line 7.
--><--
inside:
--><--
outside again:
Use of uninitialized value $x in concatenation (.) or string at ./foo line 16.
--><--


hp
 

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

Forum statistics

Threads
474,053
Messages
2,570,431
Members
47,075
Latest member
TysonV438

Latest Threads

Top