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: Intermediate:
Put log dump in textarea using CGI

 



r00tuser
New User

Apr 6, 2013, 3:30 AM

Post #1 of 3 (975 views)
Put log dump in textarea using CGI Can't Post

hey Guys -

I've recently starting using CGI in PERL. This is one thing that I got stuck with .. Basically, I am trying to dump log details into TEXTAREA of HTML. I went through PERLDOC of creating big text area in HTML, but in vain.

Here is my pseudo code, please let me know what where I am going wrong.


Code
 
#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;

print "content-type: text/html \n\n"; #HTTP HEADER



@huge_log_details = `command | grep something`;

foreach (@huge_log_details) {

@formatted_log = $_ . "<BR><BR>";
#print @formatted_log;
}


#Below code i tried doesn't seem to work, just displays the last line to log in TEXTAREA
print textarea(-name=>'foo',
-default=>"@formatted_log",
-rows=>110,
-columns=>150);


#print $cgi->textarea(-name=>'TEXT_AREA',
# -default=>"@formatted_log")
#print "<textarea> @newcmd </textarea>";



Also, I want the textarea to increase/decrease [rowsize] depending on the size of array @huge_log_details. Is there any function inbuilt in CGI that can make this happen.

-r00tuser


FishMonger
Veteran / Moderator

Apr 6, 2013, 6:39 AM

Post #2 of 3 (972 views)
Re: [r00tuser] Put log dump in textarea using CGI [In reply to] Can't Post

The first thing that you're doing wrong is forgetting to include the strict and warnings pragmas, which should be in every perl script you write.


Code
use strict; 
use warnings FATAL => 'all';


The strict pragma will require you to declare your vars, which is done with the 'my' keyword.


Code
my @huge_log_details = `command | grep something`;


The key line that's causing your problem is this one.

Code
@formatted_log = $_ . "<BR><BR>";

You are overwriting the array on each iteration of the loop and at the end it will contain only a single element, which is the last element in the @huge_log_details array.


Code
#!/usr/bin/perl  

use strict;
use warnings FATAL => 'all';
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;

print header(), start_html(); #HTTP HEADER

my @huge_log_details = `command | grep something`;

my $row_cnt = @huge_log_details;
my $formatted_log = join '<br><br>', @huge_log_details;

print textarea(-name=>'foo',
-default => $formatted_log,
-rows => $row_cnt,
-columns => 150
);



(This post was edited by FishMonger on Apr 6, 2013, 6:39 AM)


r00tuser
New User

Apr 7, 2013, 2:18 AM

Post #3 of 3 (954 views)
Re: [FishMonger] Put log dump in textarea using CGI [In reply to] Can't Post

Thanks for pointing out those mistakes and providing detailed explanation.

It worked like a charm!!

-r00tUser

 
 


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

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