how to capture large output in a perl variable

Discussion in 'Perl Misc' started by vsmurthy, Mar 22, 2005.

  1. vsmurthy

    vsmurthy Guest

    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
     
    vsmurthy, Mar 22, 2005
    #1
    1. Advertising

  2. vsmurthy

    Guest

    "vsmurthy" <> 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
     
    , Mar 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Li Chen
    Replies:
    0
    Views:
    140
    Li Chen
    Dec 20, 2006
  2. Maxim Zhukov
    Replies:
    3
    Views:
    158
    Igor Pirnovar
    Feb 9, 2009
  3. Chris Weiss

    How to capture output of CVS via Perl?

    Chris Weiss, Oct 8, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    196
    Tad McClellan
    Oct 9, 2004
  4. championsleeper
    Replies:
    8
    Views:
    598
  5. bloc
    Replies:
    3
    Views:
    115
    mertas
    Jul 6, 2006
Loading...

Share This Page