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: Advanced:
How to give CGI/perl output in table form

 



ankit
Novice

Apr 19, 2010, 10:02 PM

Post #1 of 11 (5865 views)
How to give CGI/perl output in table form Can't Post

Hi Friends------
I have draw the table but i am not able how to give out put for my result , Can you please tell me how can i do this----

(1)This is the script for Table which is working---

start_table(),
print table({-border=>undef},
caption('Output of the Query'),
Tr({-align=>'CENTER',-valign=>'TOP'},
[
th(['Sequence Name', 'Restriction Enzyme','Restriction Site','Total No. of Fragments']),

td([' ' , param('enzyme'),' ']),
]
)
),


(2) Now i want to give out put of following code--(in btw table)

print "Your requested enzyme(s): ",em(param('enzyme')),p,
"<code><pre>\n";
(my $paramenzyme = param('enzyme')) =~ s/,/ /g;
foreach my $enzyme (split(" ", $paramenzyme)) {
print "Locations for $enzyme: ",
join( ' ', $restrict->get_enzyme_map($enzyme)), "\n";


my @count=' ';
@count = join ' ', $restrict->get_enzyme_map($enzyme)+1, "\n";
print "Total Fragments of the sequence are: @count \n";
hr,

}


roolic
User

Apr 23, 2010, 2:08 AM

Post #2 of 11 (5826 views)
Re: [ankit] How to give CGI/perl output in table form [In reply to] Can't Post

using the modules for html generation is making the code hard to red. just be simple

Code
 
print "<p>Your requested enzyme(s): ",em(param('enzyme')),p, "</p>\n";

# table start
print '<table border="none">\n";

# teable header
print "<tr>\n"; # header row start
foreach my $head ('Sequence Name', 'Restriction Enzyme','Restriction Site','Total No. of Fragments'){
print "<th>$head</th>\n"; # header cell
}
print "</tr>\n"; # header row end

# table content
(my $paramenzyme = param('enzyme')) =~ s/,/ /g;

# printing table rows within the circle
foreach my $enzyme (split(/\s+/, $paramenzyme)) {

# define the values for columns here as
# $seq_name, $restr_enzyme, $restr_site, $count

# then print the table row

print "<tr>\n"; # row start
foreach my $value ( $seq_name, $restr_enzyme, $restr_site, $count ){
print "<td>$value</td>\n"; # data cell
}
print "</tr>\n"; # row end
}

# finish the table
print "</table>\n";



ankit
Novice

Apr 25, 2010, 11:23 PM

Post #3 of 11 (5745 views)
Re: [roolic] How to give CGI/perl output in table form [In reply to] Can't Post

Thanks roolic but when do this there is some error comes in browser-
"syntax error at C:/myscript/webrebase100.cgi line 115, near "foreach my $head .('Sequence Name"
Bad name after enzyme' at C:/myscript/webrebase100.cgi line 122."

and when i see the apache error log then it gives multiple errors which is----
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: Bareword found where operator expected at C:/myscript/webrebase100.cgi line 115, near "foreach my $head ('Sequence"
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: (Might be a runaway multi-line '' string starting on line 111)
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: \t(Do you need to predeclare foreach?)
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: Bareword found where operator expected at C:/myscript/webrebase100.cgi line 115, near "','Restriction"
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: \t(Missing operator before Restriction?)
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: Bareword found where operator expected at C:/myscript/webrebase100.cgi line 115, near "','Restriction"
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: \t(Missing operator before Restriction?)
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: Bareword found where operator expected at C:/myscript/webrebase100.cgi line 115, near "','Total"
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: \t(Missing operator before Total?)
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: syntax error at C:/myscript/webrebase100.cgi line 115, near "foreach my $head ('Sequence Name"
[Mon Apr 26 11:50:15 2010] [error] [client 127.0.0.1] [Mon Apr 26 11:50:15 2010] webrebase100.cgi: Bad name after enzyme' at C:/myscript/webrebase100.cgi line 122.


Help me --


roolic
User

Apr 26, 2010, 1:55 AM

Post #4 of 11 (5740 views)
Re: [ankit] How to give CGI/perl output in table form [In reply to] Can't Post

could you attach the file?


ankit
Novice

Apr 26, 2010, 2:18 AM

Post #5 of 11 (5737 views)
Re: [roolic] How to give CGI/perl output in table form [In reply to] Can't Post

Hi,,
I have attached that file and one another file in which a graph is showing,below is the script in which i want to give my output draw a graph of my result of restriction enzymes and there sites.
So plz help me in this also.

my %dataset = ( 1 => 3,
2 => 17,
3 => 34,
4 => 23,
5 => 25,
6 => 20,
7 => 12,
8 => 3,
9 => 1
);

# create new image
my $graph = new GD::Graph::bars(600, 300);

# discover maximum values of x and y for graph parameters
my( $xmax) = sort {$b <=> $a} keys %dataset;
my( $ymax) = sort {$b <=> $a} values %dataset;
# how many ticks to put on y axis
my $yticks = int($ymax / 5) + 1;

# define input arrays and enter 0 if undefined x value
my(@xsizes) = (0 .. $xmax);
my(@ycounts) = ();
foreach my $x (@xsizes) {
if ( defined $dataset{$x}) {
push @ycounts, $dataset{$x};
}else{
push @ycounts, 0;
}
}

# set parameters for graph
$graph->set(
transparent => 0,
title => "Summary of mutation data",
x_label => 'Mutants per cluster',
y_label => 'Number of mutants',
x_all_ticks => 1,
y_all_ticks => 0,
y_tick_number => $yticks,
zero_axis => 0,
zero_axis_only => 0,
);

# plot the data on the graph
my $gd = $graph->plot(
[ xsizes,
ycounts
]
);

# output file
my $pngfile = "gdgraph1.png";
unless(open(PNG, ">$pngfile")) {
croak "Cannot open $pngfile:$!\n";
}

# set output file handle PNG to binary stream
# (this is important sometimes, for example doing
# GCI programming on some operating systems
binmode PNG;

# print the image to the output file
print PNG $gd->png;
Attachments: webrebase.txt (4.46 KB)
  gdgraph1.png (1.99 KB)


ankit
Novice

Apr 27, 2010, 9:33 PM

Post #6 of 11 (5657 views)
Re: [roolic] How to give CGI/perl output in table form [In reply to] Can't Post

Reply me ??Is any problem there. ??
its urgrnt.


FishMonger
Veteran / Moderator

Apr 29, 2010, 6:57 AM

Post #7 of 11 (5604 views)
Re: [ankit] How to give CGI/perl output in table form [In reply to] Can't Post

Start by adding these 2 pragmas and fix the problems that they point out.

Code
use strict; 
use warnings;


Why are you attempting to load the CGI module twice?

Personally, I'd extract the html code and use a template.
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm



Quote

Code
$restr_enzyme => param('enzyme'); 
$restr_site=> $restrict->get_enzyme_map($enzyme);
$count=> join ' ', $restrict->get_enzyme_map($enzyme)+1, "\n";


Don't use the => fat comma.

Change it to:

Code
my $restr_enzyme = param('enzyme'); 
my $restr_site = $restrict->get_enzyme_map($enzyme);
my $count = join(' ', $restrict->get_enzyme_map($enzyme)+1, "\n");



FishMonger
Veteran / Moderator

Apr 29, 2010, 7:06 AM

Post #8 of 11 (5603 views)
Re: [ankit] How to give CGI/perl output in table form [In reply to] Can't Post

Don't use barewords for filehandles. Instead, use a lexical var and the 3 arg form of open.

Code
open my $img, '>', $img_path or die "can not write to $img_path: $!"; 
binmode $img;
print $img $img_binary;
close $img or die "failed to close <$img_path> $!";



Quote

Code
      '<body>', 
'<body background="images-2/plasmid22.jpg"><center>' ,
'<body bgcolor=white>',


Why are you printing 3 body tags?


ankit
Novice

Apr 29, 2010, 9:44 PM

Post #9 of 11 (5584 views)
Re: [FishMonger] How to give CGI/perl output in table form [In reply to] Can't Post

but it still give error on-

syntax error at C:/myscript/webrebase100.cgi line 114, near "foreach my $head ('Sequence Name"
Bad name after enzyme' at C:/myscript/webrebase100.cgi line 120.

Help me --------


FishMonger
Veteran / Moderator

Apr 30, 2010, 4:34 AM

Post #10 of 11 (5569 views)
Re: [ankit] How to give CGI/perl output in table form [In reply to] Can't Post


In Reply To
but it still give error on-

syntax error at C:/myscript/webrebase100.cgi line 114, near "foreach my $head ('Sequence Name"
Bad name after enzyme' at C:/myscript/webrebase100.cgi line 120.

Help me --------


You have a quoting problem just prior to line 114.


Code
# table start  
print '<table border="none">\n";

You used a single quote at the beginning, but used a double quote at the end. Since you need interpolation for the \n char, change that print statement to:

Code
print "<table border='none'>\n";



ankit
Novice

Apr 30, 2010, 10:17 PM

Post #11 of 11 (5541 views)
Re: [FishMonger] How to give CGI/perl output in table form [In reply to] Can't Post

Thanks friend ,,now its working . but it is no spliting restriction enzymes and it print all in each line like this-

Restriction Enzyme Restriction Site Total No. of Fragments
EcoRI HindIII AceI 5 6
EcoRI HindIII AceI 3 4
EcoRI HindIII AceI 7 8

I think this line not working properly -

foreach my $enzyme (split(" ", $paramenzyme)) {

help me here also
and one more thing in which you help me .

I want to draw a graph by the help of this script
Can you plz help me to draw a graph by the help of this script-

my %dataset = ( 1 => 3,
2 => 17,
3 => 34,
4 => 23,
5 => 25,
6 => 20,
7 => 12,
8 => 3,
9 => 1
);

# create new image
my $graph = new GD::Graph::bars(600, 300);

# discover maximum values of x and y for graph parameters
my( $xmax) = sort {$b <=> $a} keys %dataset;
my( $ymax) = sort {$b <=> $a} values %dataset;
# how many ticks to put on y axis
my $yticks = int($ymax / 5) + 1;

# define input arrays and enter 0 if undefined x value
my(@xsizes) = (0 .. $xmax);
my(@ycounts) = ();
foreach my $x (@xsizes) {
if ( defined $dataset{$x}) {
push @ycounts, $dataset{$x};
}else{
push @ycounts, 0;
}
}

# set parameters for graph
$graph->set(
transparent => 0,
title => "Summary of mutation data",
x_label => 'Mutants per cluster',
y_label => 'Number of mutants',
x_all_ticks => 1,
y_all_ticks => 0,
y_tick_number => $yticks,
zero_axis => 0,
zero_axis_only => 0,
);

# plot the data on the graph
my $gd = $graph->plot(
[ xsizes,
ycounts
]
);

# output file
my $pngfile = "gdgraph1.png";
unless(open(PNG, ">$pngfile")) {
croak "Cannot open $pngfile:$!\n";
}

# set output file handle PNG to binary stream
# (this is important sometimes, for example doing
# GCI programming on some operating systems
binmode PNG;

# print the image to the output file
print PNG $gd->png;


Tell me how can give my table output in this.

 
 


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

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