Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Re: CGI PM

by OeufMayo (Curate)
on Jan 29, 2001 at 00:51 UTC ( [id://54880]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: CGI PM
in thread CGI PM

Now that you have your cgi object, why not use the value you got from it? :)

You maybe want to do:

my $rowid = $ARGV[0] || $value ;

instead of:

my $rowid = $ARGV[0] || 'value';

<kbd>--
PerlMonger::Paris(http => 'paris.pm.org');</kbd>

Replies are listed 'Best First'.
Re: Re: Re: Re: CGI PM
by malaga (Pilgrim) on Jan 29, 2001 at 01:05 UTC
    I needed to know that. but something is still wrong. the data is being returned. here's where i am now:
    #!/usr/local/bin/perl use Data::Dumper; use strict; use CGI qw/:standard/; my $value = param('name'); my $rowid = $ARGV[0] || $value; my %data = (); my @fields = split(/\t/, <FILE>); chomp @fields; open FILE , "facultydummy.txt" or die "Cannot open: $!"; while(<FILE>) { chomp; my @row = split(/\t/); if ($row[0] eq $rowid) { @data{@fields} = @row; last; } } print "Content-type: text/html\n\n"; if ( keys %data ) { # found, display data print Dumper \%data; } else { # not found, show error print STDERR "Can't find row '$rowid'\n"; }
      Using -w and strict would *probably* give you an error message something like 'read on closed filehandle'.

      You're attempting to populate @fields where you declare it, and before you open the filehandle.

      @fields will be empty, which is a problem in your hash slice.

      I'm not sure what you intend to do, but I will personally guarantee that -w and strict will catch this error, and that you'll have better luck if there's something in @fields.

      What do you mean by "something is still wrong"? Do you mean that it's not in the format you want? If you want to output HTML, replace the entire second part with something like

      print header; if ( keys %data ) { # found, display data print ul( map { li("$_: $data{$_}") } keys %data); } else { # not found, show error print h1("Can't find row '$rowid'"); }

      The functions header, ul, li and h1 are all in CGI.pm (and do just what they sound like.) Ideally you'd want to use something like Template Toolkit or Text::Template for you html, rather than embedding it in the perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://54880]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found