Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to capture large output in a perl variable

Reply
Thread Tools

how to capture large output in a perl variable

 
 
vsmurthy
Guest
Posts: n/a
 
      03-22-2005
Hi,
I have just begun to use Perl for CGI programming. I have a
situation where I run a command on the server through my perl script
and try to retrieve the result of the command into a perl variable and
then I try to display it on the web page:

my $var = `property <dataid>`;
print "<td align="middle">$var</td>";

This command (property) sometimes produces an output of size almost
0.5Mb to 1Mb for some values of <dataid>(I checked the size of the
output by executing the "property" command on the web server CLI).

I have 2 problems in capturing this output in the perl variable:
1] Only part of the output of the command is captured in the variable
when the output is large (i.e, when output size is greater than 0.1Mb).
How should I take care of this? Is there any feature in Perl to capture
very large output?

2] The other problem is that the output of the command has some XML in
it and when I capture it in the perl variable, the XML part is lost
(From the example below, all text between and including <List> and
</List> don't appear in the variable). How should one capture such data
since its not completely XML? Should I be using any PERL/XML functions?

Sample output:

Data <dataid> is not empty
Content has xxx entires:
------ similar text -------
------ similar text -------
<List>
<List1>123</List1>
<List2>345</List2>
------------------
------------------
<Listn>23</Listn>
</List>
Loc has 40 files:
filename-1
filename-2
----------
----------
----------
filename-40

Any help is greatly appreciated.

Thanks,
Vinay

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-22-2005
"vsmurthy" <(E-Mail Removed)> wrote:
....

> my $var = `property <dataid>`;
> print "<td align="middle">$var</td>";
>
> This command (property) sometimes produces an output of size almost
> 0.5Mb to 1Mb for some values of <dataid>(I checked the size of the
> output by executing the "property" command on the web server CLI).
>
> I have 2 problems in capturing this output in the perl variable:
> 1] Only part of the output of the command is captured in the variable
> when the output is large (i.e, when output size is greater than 0.1Mb).


I don't believe you:

$ perl
my $var = `perl -e 'print "x" x 100_000_000'`;
print length $var;
__END__
100000000


> How should I take care of this? Is there any feature in Perl to capture
> very large output?


You are doing something wrong. Post a short working example that
demonstrates your problem, and we'll help you figure out what you are doing
wrong.


> 2] The other problem is that the output of the command has some XML in
> it and when I capture it in the perl variable, the XML part is lost


Again, I don't believe you. The XML is in the variable. But since
you print the variable contents without escaping html entities (or whatever
they are called), the web browser is probably trying to interpret the XML
as HTML. Do the proper escaping.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to capture standart output to variable? Maxim Zhukov Ruby 3 02-09-2009 09:59 PM
run perl script and capture the output Li Chen Ruby 0 12-20-2006 04:25 AM
Using javascript to capture the output of an anchor to alter a variable bloc Javascript 3 07-06-2006 10:01 PM
capture output from print command to variable in perl championsleeper Perl Misc 8 04-21-2005 06:58 PM



Advertisments