in reply to new to oop (problem with my object)

You're calling the methods open_row, open_table, etc. but in your Table class definition you called them row_open, table_open, etc.! That's not going to work.

Plus everything Fastolfe said.

Besides, you have a real mess in your methods: some of them call print to print out your table tags, and others simply return values. That's not going to work--decide on one or the other and stick to it. If I were you I'd have all my methods return data rather than printing it out, because it's more flexible that way.

So, for example, your row_open method prints out "<tr>", but then you set a value using the "name" method, then attempt to do something with it, and the name method just returns that value. And you don't do anything with it.

  • Comment on Re: new to oop (problem with my object)

Replies are listed 'Best First'.
Re: Re: new to oop (problem with my object)
by Fastolfe (Vicar) on Nov 17, 2000 at 02:16 UTC
    Which tells me there should have been a much more serious problem with the script than he was leading on.

    If you're getting "Internal Server Error", the first place you need to go is the web server's error logs (e.g. /var/log/httpd/error_log), which should contain full STDERR output from your script. An alternative is to use another module in the CGI arsenal:

    use CGI::Carp 'fatalsToBrowser';
    This would send errors to your web browser in addition to the server's log files, greatly aiding in your CGI development. In the future, it would help if you would tell us what you are seeing, in addition to simply what you aren't seeing.
      ahhh! i appreciate you guys looking at it..the printing of the html is actually working well now.. the 'fatalsToBrowser' told me what btrott was telling me about my mis-named method calls....it also appears as though i need to dereference my hash? I'm getting Table=HASH(0x100da2e8)->value when it does the following print: print "$table->value\n";
        $table->value is a method call, not a variable. Thus, you can't interpolate it in a string like you can $hashref->{key}.
        thanks for the help, if anyone cares:
        package Table; # # # Generic HTML Table Object # # sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{TABLE_OPEN} = undef; $self->{TABLE_CLOSE} = undef; $self->{ROW_OPEN} = undef; $self->{ROW_CLOSE} = undef; $self->{COL_OPEN} = undef; $self->{COL_CLOSE} = undef; $self->{NAME} = undef; $self->{VALUE} = undef; bless ($self, $class); return $self; } ################################################# sub table_open { my $self = shift; if (@_) { $self->{TABLE_OPEN} = shift } return print "<table $self->{TABLE_OPEN}>\n"; } sub table_close { my $self = shift; if (@_) { $self->{TABLE_CLOSE} = shift } return print "</table>\n"; } sub row_open { my $self = shift; if (@_) { $self->{ROW_OPEN} = shift } return print "\t<tr $self->{ROW_OPEN}>\n"; } sub row_close { my $self = shift; if (@_) { $self->{ROW_CLOSE} = shift } return print "\t</tr>\n"; } sub col_open { my $self = shift; if (@_) { $self->{COL_OPEN} = shift } return print "\t\t<td $self->{COL_OPEN}>\n"; } sub col_close { my $self = shift; if (@_) { $self->{COL_CLOSE} = shift } return print "\t\t</td>\n"; } sub name { my $self = shift; if (@_) { $self->{NAME} = shift } return print "\t\t\t$self->{NAME}\n"; } sub value { my $self = shift; if (@_) { $self->{VALUE} = shift } return print "\t\t\t$self->{VALUE}\n"; } 1; ################################################ # script i'm using to interface #!/usr/bin/perl -w use CGI::Carp 'fatalsToBrowser'; use strict; use Web; # my web processing module use Table; my ($website) = 'dev.merchantonline.com'; my ($i) = undef; $|=1; &parse(); # parse html post/get using the Web module &check_referer($website); # check refering url using the Web module &check_required('test'); # check required fields using the Web module print "Content-type:text/html\n\n"; print "<html>\n<body>\n"; print "test = " . $in{'test'} . "<br><br>\n"; my($table) = new Table(); $table->table_open('width=500'); foreach $i (sort keys %in){ $table->row_open(); $table->col_open(); $table->name($i); $table->col_close; $table->col_open; $table->value($in{$i}); $table->col_close; $table->row_close; } $table->table_close; print "got here\n"; exit;