how to capture large output in a perl variable

V

vsmurthy

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
 
X

xhoster

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top