Trying to get CGI selection to print

Discussion in 'Perl Misc' started by Nene, Oct 24, 2011.

  1. Nene

    Nene Guest

    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;
    ~
    Nene, Oct 24, 2011
    #1
    1. Advertising

  2. Nene

    Steve May Guest

    On 10/24/2011 01:25 PM, Nene wrote:
    > 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
    Steve May, Oct 24, 2011
    #2
    1. Advertising

  3. Nene

    J. Gleixner Guest

    On 10/24/11 20:25, Nene wrote:
    > 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";
    J. Gleixner, Oct 25, 2011
    #3
  4. On 2011-10-24 21:13, Ben Morrow <> wrote:
    > Quoth Nene <>:
    >> #!/usr/bin/perl -w

    >
    > 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
    Peter J. Holzer, Oct 26, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Niederberger
    Replies:
    2
    Views:
    16,484
    Christian Kaufhold
    Jan 7, 2005
  2. Andrew Crowe
    Replies:
    1
    Views:
    4,458
    Andrew Crowe
    Sep 13, 2004
  3. keto
    Replies:
    0
    Views:
    923
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    344
    David Cournapeau
    Dec 30, 2008
  5. erik
    Replies:
    19
    Views:
    450
    Gunnar Hjalmarsson
    Jun 27, 2005
Loading...

Share This Page