[27924] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9288 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 12 18:10:16 2006

Date: Mon, 12 Jun 2006 15:10:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 12 Jun 2006     Volume: 10 Number: 9288

Today's topics:
        Parsing XML and storing attributes in MySQL using Perl <jkugler@mit.edu>
    Re: Parsing XML and storing attributes in MySQL using P robic0
    Re: Parsing XML and storing attributes in MySQL using P <glex_no-spam@qwest-spam-no.invalid>
    Re: Parsing XML and storing attributes in MySQL using P xhoster@gmail.com
    Re: Proposed Changes (was Re: Posting Guidelines for co jgraber@ti.com
    Re: read a webpage with username/password jiehuang001@hotmail.com
    Re: read a webpage with username/password <dorward@yahoo.com>
    Re: Running system commands <tzz@lifelogs.com>
    Re: Unable to connect to SQLite database file <glex_no-spam@qwest-spam-no.invalid>
    Re: Using tee with Perl's system command <tzz@lifelogs.com>
    Re: Using tee with Perl's system command olson_ord@yahoo.it
    Re: Using tee with Perl's system command olson_ord@yahoo.it
    Re: Using tee with Perl's system command <jgibson@mail.arc.nasa.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 12 Jun 2006 13:53:04 -0700
From: "jkugler" <jkugler@mit.edu>
Subject: Parsing XML and storing attributes in MySQL using Perl
Message-Id: <1150145584.616559.38840@h76g2000cwa.googlegroups.com>

Hello,

I am trying to store huge amounts of data from xml files and put them
into a MySQL database. The xml files all are in this format:

<?xml version="1.0" encoding="UTF-8"?>
<snp_submission xsi:schemaLocation="http://www.hapmap.org
http://hapmap.cshl.org/xml-schema/2003-1
1-04/hapmap.xsd"
lsid="urn:LSID:ncbi.nlm.nih.gov:dbSNP/DCC_batch:34_chrom11_DELETE:005"
xmlns="http
://www.hapmap.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <batch_info>
        <class>DELETE</class>
        <group lsid="urn:lsid:dcc.hapmap.cshl.org:Labgroup:DBSNP:1"/>
        <date_created>2005-09-15</date_created>
        <contact>
            <name>Steve Sherry</name>
            <email>she...@ncbi.nlm.nih.gov</email>
        </contact>
    </batch_info>
    <snps>
        <snp
lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461544:111">
            <snp_class>
                <bac-overlap/>
            </snp_class>
            <sequence>

<flank_5>caaaggaatataaatcattctattataaagatacatgcacAGGgctgggtgcagtggctcacacctgtaatccc
agcactttgggaggccaaggcgggtggatcacctgaggacaggagtttgagaccagcctagccaacatggggaaactccatctctactaaaaatacaaa
aattagccaggtatagtggtgcacacctgtaataccagctactttggaggctgaggcaggagaatcgctggaacccaggaggcagaggtcaaagtgagc
caagatcataccattgcactccagcctgggcaacaagagcaaaactccatcttaaaaaaatatatatatatacatatacatacatatatatacacatat
atatacatatatacagatattatatatgtaaatgtatatatatgtgtatatatatacacatatatatacatattataactacatatatatacacacaca
catacatatacatgcacacatatgtttattgcagcactatttacgatagaaaatacatggaatcctcccaaatgcccatcaatgatatattggataaag
aaaatgtgatatatattcaccatggaatactatgcagccgttaaaataaatgagatcatgttctttgcagggacatggatgaagctggaagccatcacc
ctcagcaaactaacacaggaaaagaaaaccaaacaccacatgttctcagtcgtaagagggagttgaacaatgagagcaaacacatggatacatggaggg
gaacaacacacaccagggcctctcagcgggacaggggtaggagaCCATCAGGACAaacacgtggatacatggaggggaacaacacacaccagggcctct
cagggggacagggggtaggagaccatcaagacaaacacgtggatacatggaggggaacaacacacaccagggcctctcagggggacagggggtaggaga
ccatcaggacaaacacgtggatacatggaggggaa</flank_5>
                <variation>
                    <allele base="C"/>
                    <allele base="T"/>
                </variation>

<flank_3>aacacacaccagggcctctcagggggacagggggtaggagaccatcaRgacaaacacgtggRtacatggagggg
aacaacacacaccagggcctctcagggggacggggggtagRagaccatcaggacaaatagctaatgcatgcagggcctcatacctaggtgatgggttga
tgggtgcagcaaaccaccatggcacacatttacctatgtatcaaacctaYactttctgcacgtgtatcccagaacataaaataaaatttaaaaaatata
taCACTGATTCATGATCTCCTttctctccttctgaaacactctttaaaactttttagcatttccccctctgtcttccatgtctcctaactacatgtttc
ttattttccatgtctttattcctgtgttcattttggatagccccttctgacctatattacagtttactagttcactcttcaactgcttctaacatacta
atattctgttaaaaccattcatttgggtttaaatttcaattatgttattctctatggacattctatttgttttcttttaatcttcttggccattctcta
gagtttcctgttccattatgatatttttaattttttgttttactttaaacatactaaatatagttattttattttattttctgtatctgatactttcaa
taactgcagtctttgctagtcttttttctgtgctcttgctcatagtttttttcatttgttttCATGATTagaaaaacagagagagaagaaggagagtaa
agggaggaggcggaggaggagaaaagaagaaagcagagaagaagggacagagaaaaaaaggaagTTGGTTCTAACGTTTCTCTAACAACTGGCTTCAGT
GAAACACTCCCACCTTGTGGATTTTTAGGTTATTGAAATTAACCAGTCTTCtgggtgcagcacaccaacatggcacatgtatacatatgtaacaaacct
gcactttgtgcacatgtaccctaaaacttaaagta</flank_3>
                <length_class value="full-length"/>
            </sequence>
            <genomic_locations>
                <genomic_location active="true" type="exact">
                    <assembly_version>ncbi_build34</assembly_version>
                    <coordinates chrom="11" start="60749" stop="60749"
strand="forward"/>
                </genomic_location>
            </genomic_locations>
            <neighbour_snps>
                <neighbour_snp
lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461545:101"/>
                <neighbour_snp
lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461546:101"/>
                <neighbour_snp
lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461547:101"/>
                <neighbour_snp
lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2686858:100"/>
            </neighbour_snps>
        </snp>

I am trying to extract the following information: lsid, allele base,
cooordinates chrom, start, and strand. I would ideally like to use a
perl script to pull this data out and put it in MySQL, but I have had
no luck with XML::Parser since the information I am looking for is
embedded in the element's attributes.

If anyone has any ideas on how to get this data out of xml and into
MySQL, it would be much appreciated.

Thanks so much,

--James



------------------------------

Date: Mon, 12 Jun 2006 14:26:29 -0700
From: robic0
Subject: Re: Parsing XML and storing attributes in MySQL using Perl
Message-Id: <j2mr82p9mich026psoqrm1eph71f3tnmb6@4ax.com>

On 12 Jun 2006 13:53:04 -0700, "jkugler" <jkugler@mit.edu> wrote:

>Hello,
>
>I am trying to store huge amounts of data from xml files and put them
>into a MySQL database. The xml files all are in this format:
>
[xml snipped]

Hi James.

If you want you could use RXParse.pm (ver .91) posted on this group.
It would send the same attribute info to a tag handler.
Should be the same as the one you used.
From there you could check the "name" for the "value" data.

If you could hang on a while, I'm writing filter interfaces for
tags, namespace, attributes, content, etc.. The filters can be
either regexp or dos style. Each filter is specific, set by the
user who provides the handler to recieve that specific info.

Whats nice is that the regexp provided by the user is applied to
just the sub-parsed global data, the category is guaranteed.
Tag is tag, attrib is attrib, content is content.

Its almost there. Yours is a basic search but the intent is to
provide search/replace as well as multiple filter capability.
At my stage of development with this its really pretty easy.
The hold up is a base compliant parser, which is almost done.

Anyway, just some info for you. No need to use RXParse. The difference
between my module and all thats out there is its whole purpose is meant
to be interactive. Funny how the simple things you would expect from 
high power software just aint there, and its  so easy to do!

robic0
(god of porn)


------------------------------

Date: Mon, 12 Jun 2006 16:42:31 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Parsing XML and storing attributes in MySQL using Perl
Message-Id: <Ihljg.28$0n1.34629@news.uswest.net>

jkugler wrote:
[...]
>             <neighbour_snps>
>                 <neighbour_snp
> lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461545:101"/>
>                 <neighbour_snp
> lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461546:101"/>
>                 <neighbour_snp
> lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461547:101"/>
>                 <neighbour_snp
> lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2686858:100"/>
>             </neighbour_snps>
>         </snp>
> 
> I am trying to extract the following information: lsid, allele base,
> cooordinates chrom, start, and strand. I would ideally like to use a
> perl script to pull this data out and put it in MySQL, but I have had
> no luck with XML::Parser since the information I am looking for is
> embedded in the element's attributes.

Use XML::Parser to get the element's value, then parse the value using 
regular expressions, split, or various other means.

What have you tried? No one can point out coding errors, unless you post 
your code.

Look at using DBI, and DBD::mysql for interacting with MySQL. It's all 
available on CPAN ( http://search.cpan.org/ ).


------------------------------

Date: 12 Jun 2006 21:48:37 GMT
From: xhoster@gmail.com
Subject: Re: Parsing XML and storing attributes in MySQL using Perl
Message-Id: <20060612174847.504$hd@newsreader.com>

"jkugler" <jkugler@mit.edu> wrote:
> Hello,
>
> I am trying to store huge amounts of data from xml files and put them
> into a MySQL database.

What is huge?  Is it the number of files, or the number of entries per
file?  If the former, I would probably use XML::Simple.  If the later,
maybe look into XML::Twig.


> The xml files all are in this format:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <snp_submission xsi:schemaLocation="http://www.hapmap.org
> http://hapmap.cshl.org/xml-schema/2003-1
> 1-04/hapmap.xsd"
> lsid="urn:LSID:ncbi.nlm.nih.gov:dbSNP/DCC_batch:34_chrom11_DELETE:005"
> xmlns="http
> ://www.hapmap.org"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 ...
>     <snps>
>         <snp
> lsid="urn:lsid:ncbi.nlm.nih.gov:dbSNP;refSNP:rs2461544:111">
 ...
>         </snp>
>
> I am trying to extract the following information: lsid,


lsid appears at more than one level.


> allele base,
> cooordinates chrom, start, and strand. I would ideally like to use a
> perl script to pull this data out and put it in MySQL, but I have had
> no luck with XML::Parser since the information I am looking for is
> embedded in the element's attributes.

I haven't had any trouble getting element attributes from XML files with
XML::Parser.  Can you show some of what you have tried so far?
Here is something trivial I whipped up that just shows how to get the
attributes for the allele:


use strict;
use Data::Dumper;
use XML::Parser;
my $p1 = new XML::Parser(Style =>'Subs');
open my $fh, "test.xml" or die $!;
$p1->parse($fh);

sub allele {
  my ($expat,$ele,%att) = @_;
  print Dumper \%att
};

__END__
$VAR1 = {
          'base' => 'C'
        };
$VAR1 = {
          'base' => 'T'
        };

no element found at line 73, column 0, byte 3851 at
/tools/GNU/perl/5.8.7_64/lib/site_perl/5.8.7/x86_64-linux/XML/Parser.pm
line 187


(That error is only there because the sample file you provided was
incomplete.)

Xho

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


------------------------------

Date: 12 Jun 2006 13:22:27 -0500
From: jgraber@ti.com
Subject: Re: Proposed Changes (was Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $))
Message-Id: <yvnwtbmb5ek.fsf@famous02.dal.design.ti.com>


Tad McClellan <tadmc@augustmail.com> writes:

> tadmc@augustmail.com <tadmc@augustmail.com> wrote:
> 
> In a recent post (news://yvn8xozx7j5.fsf@famous02.dal.design.ti.com)
> Joel Graber proposed some changes to the posting guidelines. I didn't
> have time to monitor the discussion then, but now I do...
> 
> ... so ... discuss!
> 
> 
> Below is the current text, and Joel's suggested replacement text.
> 
> 
> >     Speak Perl rather than English, when possible
> >         Perl is much more precise than natural language. Saying it in Perl
> >         instead will avoid misunderstanding your question or problem.
> > 
> >         Do not say: I have variable with "foo\tbar" in it.
> > 
> >         Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
> >         or I have $var = <DATA> (and show the data line).
> > 
> >     Ask perl to help you
> >         You can ask perl itself to help you find common programming mistakes
> >         by doing two things: enable warnings (perldoc warnings) and enable
> >         "strict"ures (perldoc strict).
> > 
> >         You should not bother the hundreds/thousands of readers of the
> >         newsgroup without first seeing if a machine can help you find your
> >         problem. It is demeaning to be asked to do the work of a machine. It
> >         will annoy the readers of your article.
> > 
> >         You can look up any of the messages that perl might issue to find
> >         out what the message means and how to resolve the potential mistake
> >         (perldoc perldiag). If you would like perl to look them up for you,
> >         you can put "use diagnostics;" near the top of your program.
> > 
> >     Do not re-type Perl code
> >         Use copy/paste or your editor's "import" function rather than
> >         attempting to type in your code. If you make a typo you will get
> >         followups about your typos instead of about the question you are
> >         trying to get answered.
> > 
> >     Provide enough information
> >         If you do the things in this item, you will have an Extremely Good
> >         chance of getting people to try and help you with your problem!
> >         These features are a really big bonus toward your question winning
> >         out over all of the other posts that you are competing with.
> > 
> >         First make a short (less than 20-30 lines) and *complete* program
> >         that illustrates the problem you are having. People should be able
> >         to run your program by copy/pasting the code from your article. (You
> >         will find that doing this step very often reveals your problem
> >         directly. Leading to an answer much more quickly and reliably than
> >         posting to Usenet.)
> > 
> >         Describe *precisely* the input to your program. Also provide example
> >         input data for your program. If you need to show file input, use the
> >         __DATA__ token (perldata.pod) to provide the file contents inside of
> >         your Perl program.
> > 
> >         Show the output (including the verbatim text of any messages) of
> >         your program.
> > 
> >         Describe how you want the output to be different from what you are
> >         getting.
> 
> 
> jgraber@ti.com <jgraber@ti.com> wrote:
> 
> JG> So here is a suggested cutdown to replace the 53 lines:
> JG> /Speak Perl/ .. /from what you are getting./
> JG>    
> JG>    ## start new,  49 lines:  saves 4 lines overall
> JG>    Ask perl to help you
> JG>    You can ask perl itself to help you find and understand
> JG>    common programming mistakes by doing three things:
> JG>         use strict;      # see perldoc strict
> JG>         use warnings;    # see perldoc warnings
> JG>         use diagnostics; # see perldoc diagnostics
> JG>    
> JG>    Provide enough information
> JG>    If you post like the example below, you will have an Extremely Good
> JG>    chance of getting people to try and help you with your problem!
> JG>    These features help your question win out over all the other posts.
> JG>    
> JG>    First make a short (less than 20-30 lines) and *complete* program
> JG>    that illustrates the problem you are having.  You will find that
> JG>    this step often solves your problem or leads you to an answer
> JG>    more reliably than posting to Usenet.
> JG>    
> JG>    Do not re-type Perl code
> JG>    Use copy/paste instead of re-typing Perl code, to avoid typos.
> JG>    People should be able to run your program
> JG>    by copy/pasting from your article.
> JG>    
> JG>     The following article demonstrates at least 8 good guidelines:
> JG>       * show incorrect output                 * show desired output
> JG>       * short/complete  * good subject line   * Speak Perl
> JG>       * input __DATA__  * use warnings/strict * cut/pasteable
> JG>    
> JG>    Subject: How do I change all 'a' to 'b' with a regexp?
> JG>    
> JG>    I want to change all 'a' to 'b' with a regexp.
> JG>    but only the first 'a' is getting changed.
> JG>       This is the incorrect output of my program:
> JG>    First line of text dbta
> JG>       What I wanted is this, note dbtb, not dbta.
> JG>    First line of text dbtb
> JG>    
> JG>    Here is my program you can copy/paste to run.
> JG>    
> JG>    #!/usr/local/bin/perl
> JG>     use warnings;
> JG>     use strict;
> JG>     while (<DATA>)    {  
> JG>         $_ =~ s/a/b/;
> JG>         print $_;      }
> JG>    __DATA__
> JG>    First line of text data
> JG>    
> JG>    However, the above may fail the faux pas "..cursory doc search",
> JG>    since the answer, s/a/b/g; is in 'perldoc perlop' near 's/PATTERN/'
> JG>    ## end new   

Thanks Tad.

To help prompt discussion,  my basic premise is that
"one example is worth a thousand words of syntax description"

While following examples blindly, without understanding them,
has been called "cargo cult programming",  
I think examples are particularly useful in this situation.   

Please comment in this thread if you agree with my
premise,  and/or agree that the above example is 
likely to positively affect the quality of posting by
the subset of new posters that actually read the guidelines first.

-- 
Joel


------------------------------

Date: 12 Jun 2006 11:30:01 -0700
From: jiehuang001@hotmail.com
Subject: Re: read a webpage with username/password
Message-Id: <1150137001.850003.158540@f6g2000cwb.googlegroups.com>

Hi, Paul:

Thank you very much. But as you will see, the following code does not
work. Any help would be deeply appreciated.

#! /Perl/bin/perl

use LWP;

my $url = 'http://www.dpgn.com/resultDetail.cfm?resultID=4543';
my $ua  = new LWP::UserAgent;
my $req = new HTTP::Request (GET => $url);

$req->authorization_basic ('jieacs', 'cancer');
my $request = $ua->request ($req);
die unless $request->code eq '200';
my $page = $request->content; 
print $page;



------------------------------

Date: Mon, 12 Jun 2006 20:26:13 +0100
From: David Dorward <dorward@yahoo.com>
Subject: Re: read a webpage with username/password
Message-Id: <e6kf9a$99m$1$8302bc10@news.demon.co.uk>

jiehuang001@hotmail.com wrote: 
> I know that I can use Get("url") > output.txt  to do that. But the
> problem is that to reach to the "url", it needs a username/password to
> login first. Of course, I know the username/password. My question is,
> how to pass the username/password from perl?

Depends how the server expects the username and password to be presented. It
could be as post data, or cookies, or http basic auth or ...

-- 
David Dorward       <http://blog.dorward.me.uk/>   <http://dorward.me.uk/>
                     Home is where the ~/.bashrc is


------------------------------

Date: Mon, 12 Jun 2006 15:07:50 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Running system commands
Message-Id: <g69r71up4zd.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 11 Jun 2006, vincente13@gmail.com wrote:

> It seems like i can do this
> system("ps -fu $USER | grep $INSTANCE | grep -v grep | awk {print \$2}
> ")

Just use sprintf!  It's clearer, too.

system sprintf('ps -fu %s | grep %s | grep -v grep | awk {print $2}', 
               $USER, 
               $INSTANCE);

Of course, what you are doing is not portable, probably wrong, and
better done with Proc::ProcessTable :)

Ted


------------------------------

Date: Mon, 12 Jun 2006 14:23:36 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Unable to connect to SQLite database file
Message-Id: <sfjjg.17$TH5.2361@news.uswest.net>

Sam wrote:

>> Doubting that perhaps I hadn't specified the path of the database
>> correctly, I removed the path and used this instead in the above code:
>>
>> my $database = 'newdb.db3';
>>
>> I got a "500 Internal Server Error ...", but the cgi-bin directory did
>> contain a database=newdb.db3 file. Seeing the 'database=' included in
>> the filename and browsing other source codes using "DBI:SQLite:dbname=
>> ..." I tried that instead. This time the script did create the database
>> file in the path I specified, but again gave the unhelpful "500
>> Internal Server Error - The server encountered an internal error or
>> misconfiguration and was unable to complete your request."
>>
>> I do feel I am getting nearer to the solution but am still a bit lost.

The DSN should be something like: "dbi:SQLite:dbname=dbfile"

You do know that you can install modules on your computer and run them 
there, before trying to run them on another host that doesn't provide 
shell access, right?  It'll make debugging CGI-based scripts much easier 
for you.. and us.

Try something from the DBD::SQLite tests.

Not tested, just simply a hack modified from the SQLite test cases, to 
get you going or to help point to where the error is coming from.

use DBI;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;

print header, start_html;

print "<pre>connecting...\n";
my $dbh = DBI->connect('dbi:SQLite:dbname=foo', '', '',
                { RaiseError => 1 , AutoCommit => 1 });
print "Got connected to dbname=foo\n";

print "creating table f...\n";
$dbh->do("CREATE TABLE f (f1, f2, f3)");
print "created table f.\n";

print "query from table f..\n";
my $sth = $dbh->prepare("SELECT f.f1, f.* FROM f");
$sth->execute();
print "query from table f successful.\n";

print "results from table f...\n";
my $names = $sth->{NAME};
print join(', ', @$names), "\n";
$sth->finish;
$dbh->disconnect;

print "finished\n</pre>", end_html;


------------------------------

Date: Mon, 12 Jun 2006 15:18:37 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Using tee with Perl's system command
Message-Id: <g69mzcip4he.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 10 Jun 2006, olson_ord@yahoo.it wrote:

> I want to call/run another program with a perl script - and I need
> to look at the current output on the screen and at the same time I need
> this output dumped to a file. Without using perl I would just use tee.
> However within perl it seems that its having some problem with the pipe
> symbol "|".

I would consider opening ls as a pipe:

open F, "ls|" or die "Couldn't open ls pipe: $!";
open W, ">out.txt" or die "Couldn't write to out.txt: $!";

while (<F>)
{
 print;
 print W $_;
}

In addition, opendir/readdir/stat ( see "perldoc -f readdir" and
others) are probably more precisely what you need.

In general, you should avoid using the shell to do *simple* things
that Perl can do (grep, ls, ps, awk, etc.).  You'll pay a penalty in
every way otherwise.

Ted


------------------------------

Date: 12 Jun 2006 14:06:12 -0700
From: olson_ord@yahoo.it
Subject: Re: Using tee with Perl's system command
Message-Id: <1150146372.663358.64590@y43g2000cwc.googlegroups.com>

Jim Gibson wrote:
> J=FCrgen fixed your problem with system. However, I would like to point
> out that another solution is to capture the output of the external
> program using backticks and then write the lines to the screen and also
> to a file from with your Perl program.
>

Thanks Jim for taking the time to respond. I thought of this solution
- but I want some way to know what the program is currently doing.
Executing it with backticks waits for the completion of the execution
before proceeding to dump output on the screen.=20
Regards,
O=2EO.



------------------------------

Date: 12 Jun 2006 14:09:43 -0700
From: olson_ord@yahoo.it
Subject: Re: Using tee with Perl's system command
Message-Id: <1150146583.817833.25360@c74g2000cwc.googlegroups.com>


Ted Zlatanov wrote:
> I would consider opening ls as a pipe:
>
> open F, "ls|" or die "Couldn't open ls pipe: $!";
> open W, ">out.txt" or die "Couldn't write to out.txt: $!";
>
> while (<F>)
> {
>  print;
>  print W $_;
> }
>
> In addition, opendir/readdir/stat ( see "perldoc -f readdir" and
> others) are probably more precisely what you need.
>
> In general, you should avoid using the shell to do *simple* things
> that Perl can do (grep, ls, ps, awk, etc.).  You'll pay a penalty in
> every way otherwise.
>
> Ted

Thanks Ted for taking the time to respond. Here ls is just used as an
example command - but I am actually calling one of my own executables
here. I just wanted to provide a working example.
	I think this code suggested also has the property that it would just
dump everything out after the execution. I don't want this because I
want to see where my code gets stuck - in case of a crash in one of
my test cases. 
Regards,
O.O.



------------------------------

Date: Mon, 12 Jun 2006 14:51:43 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Using tee with Perl's system command
Message-Id: <120620061451438858%jgibson@mail.arc.nasa.gov>

In article <1150146583.817833.25360@c74g2000cwc.googlegroups.com>,
<olson_ord@yahoo.it> wrote:

> Ted Zlatanov wrote:
> > I would consider opening ls as a pipe:
> >
> > open F, "ls|" or die "Couldn't open ls pipe: $!";
> > open W, ">out.txt" or die "Couldn't write to out.txt: $!";
> >
> > while (<F>)
> > {
> >  print;
> >  print W $_;
> > }
> >
> > In addition, opendir/readdir/stat ( see "perldoc -f readdir" and
> > others) are probably more precisely what you need.
> >
> > In general, you should avoid using the shell to do *simple* things
> > that Perl can do (grep, ls, ps, awk, etc.).  You'll pay a penalty in
> > every way otherwise.
> >
> > Ted
> 
> Thanks Ted for taking the time to respond. Here ls is just used as an
> example command - but I am actually calling one of my own executables
> here. I just wanted to provide a working example.
>  I think this code suggested also has the property that it would just
> dump everything out after the execution. I don't want this because I
> want to see where my code gets stuck - in case of a crash in one of
> my test cases. 

No. Opening the process and piping output to your Perl program and
printing it the way Ted has suggested should give you immediate
feedback on what the program is doing, except for possible buffering of
output by the external program.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9288
***************************************


home help back first fref pref prev next nref lref last post