[23805] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6008 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 19:36:09 2004

Date: Thu, 29 Jan 2004 16:35:39 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 29 Jan 2004     Volume: 10 Number: 6008

Today's topics:
        help with arrays to hash <jimwmct@yahoo.com>
    Re: help with arrays to hash <dwall@fastmail.fm>
    Re: help with arrays to hash <jimwmct@yahoo.com>
        HELP: from XML to mySQL <fede72bari@tiscali.it>
    Re: HELP: from XML to mySQL <bigiain@mightymedia.com.au>
    Re: HELP: from XML to mySQL <tadmc@augustmail.com>
    Re: HELP: from XML to mySQL <fede72bari@tiscali.it>
    Re: HELP: from XML to mySQL <fede72bari@tiscali.it>
    Re: HELP: from XML to mySQL <jwillmore@remove.adelphia.net>
    Re: HELP: from XML to mySQL <ceo@nospan.on.net>
    Re: HELP: from XML to mySQL <ceo@nospan.on.net>
    Re: HELP: from XML to mySQL <news4@earthsong.null.free-online.co.uk>
    Re: HELP: from XML to mySQL <fede72bari@tiscali.it>
    Re: HELP: from XML to mySQL <mirod@xmltwig.com>
    Re: How can I read file from end to first ? <uri@stemsystems.com>
    Re: How can I read file from end to first ? <bik.mido@tiscalinet.it>
    Re: How can I read file from end to first ? <carsten@welcomes-you.com>
        How to capture system output on NT? (Pea)
    Re: How to capture system output on NT? (Malcolm Dew-Jones)
    Re: How to capture system output on NT? <nobull@mail.com>
    Re: How to capture system output on NT? (Pea)
    Re: How to capture system output on NT? <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 29 Jan 2004 12:53:57 -0800
From: "jm" <jimwmct@yahoo.com>
Subject: help with arrays to hash
Message-Id: <401972d9$0$11450$61fed72c@news.rcn.com>

Looking for guidance.
I have multiple arrays with data, and each element is directly associated
with the
same element number in the other arrays.  I want to be able to access the
information
for each company by the account number in @acctnum.
Looks like I should be able to use hash of  hash, which I don't quite
understand.
I Looked at perldsc and it doesn't make sense to me how to accomplish this.
Tried various ways of using my %HOH and always get errors.
If this can be done, please point me in the right direction, or explain.


use strict;
use warnings;

my @acctnums = ("000101", "000102", "000103", "000104", "000105");

my @companies = ("Flower Mart", "Amigos", "Lacy's", "Good Dairy", "Western
Wear");

my @addresses = ("1100 Fashion Drive", "544 Grand Ave.", "636 Miller Ave.",
          "1536 Ocean View", "111 Camino Dr.");

my @cities = ("San Francisco", "San Mateo", "Belmont", "San Francisco",
"Burlingame");

my @phonenums = ("415-555-1234", "650-555-1234", "650-555-4567",
"415-555-9876", "650-555-5432");

my %acctnum = @acctnums;
my %company = @companies;
my %address = @addresses;
my %city = @cities;
my %phonenum = @phonenums;
my %HoH = (
   acctnum => {company => address},
  {address => city},
  {city => phonenum}
 );

thanks in advance
jm




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

Date: Thu, 29 Jan 2004 21:18:26 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: help with arrays to hash
Message-Id: <Xns947FA5E32C775dkwwashere@216.168.3.30>

jm <jimwmct@yahoo.com> wrote:

> Looking for guidance.
> I have multiple arrays with data, and each element is directly
> associated with the same element number in the other arrays.  I want to
> be able to access the information  for each company by the account
> number in @acctnum. Looks like I should be able to use hash of  hash,
> which I don't quite understand.
> I Looked at perldsc and it doesn't make sense to me how to accomplish
> this. Tried various ways of using my %HOH and always get errors.
> If this can be done, please point me in the right direction, or explain.
> 
> 
> use strict;
> use warnings;
> 
> my @acctnums = ("000101", "000102", "000103", "000104", "000105");
> 
> my @companies = ("Flower Mart", "Amigos", "Lacy's", "Good Dairy",
> "Western Wear");
> 
> my @addresses = ("1100 Fashion Drive", "544 Grand Ave.", "636 Miller
> Ave.", 
>           "1536 Ocean View", "111 Camino Dr.");
> 
> my @cities = ("San Francisco", "San Mateo", "Belmont", "San Francisco",
> "Burlingame");
> 
> my @phonenums = ("415-555-1234", "650-555-1234", "650-555-4567",
> "415-555-9876", "650-555-5432");

If you want to key on account number, try this:

    my %info;
    for my $i (0..$#acctnums) {
        $info{$acctnums[$i]} = {
            company => $companies[$i],
            address => $addresses[$i],
            city    => $cities[$i],
            phone   => $phonenums[$i],
        };
    }

This creates a hash for which the keys are account numbers and the values 
are references to anonymous hashes with their own key/value pairs, 
informally called a hash of hashes.  I hope that helps in making more sense 
out of perldsc.  (Your original code looks like you would have got there 
eventually.)

Then if you want to see the entire data structure,

    use Data::Dumper;
    print Dumper \%info;

-- 
David Wall


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

Date: Thu, 29 Jan 2004 14:23:42 -0800
From: "jm" <jimwmct@yahoo.com>
Subject: Re: help with arrays to hash
Message-Id: <401987e5$0$11446$61fed72c@news.rcn.com>


"David K. Wall" <dwall@fastmail.fm> wrote in message
news:Xns947FA5E32C775dkwwashere@216.168.3.30...
> jm <jimwmct@yahoo.com> wrote:
>
> > Looking for guidance.
> > I have multiple arrays with data, and each element is directly
> > associated with the same element number in the other arrays.  I want to
> > be able to access the information  for each company by the account
> > number in @acctnum. Looks like I should be able to use hash of  hash,
> > which I don't quite understand.
> > I Looked at perldsc and it doesn't make sense to me how to accomplish
> > this. Tried various ways of using my %HOH and always get errors.
> > If this can be done, please point me in the right direction, or explain.
> >
> >
> > use strict;
> > use warnings;
> >
> > my @acctnums = ("000101", "000102", "000103", "000104", "000105");
> >
> > my @companies = ("Flower Mart", "Amigos", "Lacy's", "Good Dairy",
> > "Western Wear");
> >
> > my @addresses = ("1100 Fashion Drive", "544 Grand Ave.", "636 Miller
> > Ave.",
> >           "1536 Ocean View", "111 Camino Dr.");
> >
> > my @cities = ("San Francisco", "San Mateo", "Belmont", "San Francisco",
> > "Burlingame");
> >
> > my @phonenums = ("415-555-1234", "650-555-1234", "650-555-4567",
> > "415-555-9876", "650-555-5432");
>
> If you want to key on account number, try this:
>
>     my %info;
>     for my $i (0..$#acctnums) {
>         $info{$acctnums[$i]} = {
>             company => $companies[$i],
>             address => $addresses[$i],
>             city    => $cities[$i],
>             phone   => $phonenums[$i],
>         };
>     }
>
> This creates a hash for which the keys are account numbers and the values
> are references to anonymous hashes with their own key/value pairs,
> informally called a hash of hashes.  I hope that helps in making more
sense
> out of perldsc.  (Your original code looks like you would have got there
> eventually.)
>
> Then if you want to see the entire data structure,
>
>     use Data::Dumper;
>     print Dumper \%info;
>
> -- 
> David Wall

Yes, that does exactly want I want!
I may have gotten there some day, I was starting to think towards a loop,
but...
You have done it.
Many thanks
jm




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

Date: Thu, 22 Jan 2004 20:52:56 +0100
From: "Federico Bari" <fede72bari@tiscali.it>
Subject: HELP: from XML to mySQL
Message-Id: <bup9ni$unp$1@lacerta.tiscalinet.it>

PLEASE HELP!

Hi all,

    i need a simple way to import tables saved in a xml document to a mySQL
databse. I found modules that easily do the opposite process (from mySQL to
XML), but I don't know how to popolate my mySQL database using datas stored
in an xml document. Please could somebody give me any suggestion? Thank you,
from italy

            Federico.




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

Date: Fri, 23 Jan 2004 12:42:48 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: HELP: from XML to mySQL
Message-Id: <bigiain-D32D0A.12424823012004@news.fu-berlin.de>

In article <bup9ni$unp$1@lacerta.tiscalinet.it>,
 "Federico Bari" <fede72bari@tiscali.it> wrote:

> PLEASE HELP!
> 
> Hi all,
> 
>     i need a simple way to import tables saved in a xml document to a mySQL
> databse. I found modules that easily do the opposite process (from mySQL to
> XML), but I don't know how to popolate my mySQL database using datas stored
> in an xml document. Please could somebody give me any suggestion? Thank you,
> from italy

I don't know how to do what you ask, but of the off chance that its not 
atually what you _want_, I'll suggest you might want to look at 
Sleepycats native XML database...

http://www.sleepycat.com/

Are you _sure_ you need to somehow try to jam XML data into SQL tables?

big

-- 
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto


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

Date: Thu, 22 Jan 2004 19:23:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: HELP: from XML to mySQL
Message-Id: <slrnc10tta.bef.tadmc@magna.augustmail.com>

Federico Bari <fede72bari@tiscali.it> wrote:

> PLEASE HELP!


There is no need to shout at us.


> I don't know how to popolate my mySQL database using datas stored
> in an xml document.


Use an XML parsing module to read the input.

Do stuff to the data.

Use the DBI to write the output.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 23 Jan 2004 09:18:59 +0100
From: "Federico Bari" <fede72bari@tiscali.it>
Subject: Re: HELP: from XML to mySQL
Message-Id: <buqlee$ibr$1@lacerta.tiscalinet.it>

 ... hi! Yes I need to have the database in mySQL server. It's a constraint
not a choice. Maybe the right question is: so why XML? I have to send around
italy a client program that will be used to make a medical census for people
having a spinal cord injoury. Each person will need weeks to fill the census
questions because these are a lot and quite difficoult. So this people must
have the possibility to fill the census off line and give us the datas just
at the end. So how store datas in clients program? Not with a Access
database (a lot of money for redistribuition licency) ... but .NET use XML
for this porpouses: stores data and send datas. It also give the possibility
with adapter and adapetr.update classes to update automatically a remote
database. But i need to do this using a secure channel. So ... mySQL
database server give this possbility ... make a secure connection using SSL.
But? BUT the Odbc of mySQL doesn't have SSL connection!!! incredible!??? Yes
 ... they make SSL connection for server and not for client (odbc)!!!!! So i
ave just this choice: store data in client PC using, XML, send at the end
datas by XML, save XML datas  in mySQL database. Thank you! Fede


"Iain Chalmers" <bigiain@mightymedia.com.au> ha scritto nel messaggio
news:bigiain-D32D0A.12424823012004@news.fu-berlin.de...
> In article <bup9ni$unp$1@lacerta.tiscalinet.it>,
>  "Federico Bari" <fede72bari@tiscali.it> wrote:
>
> > PLEASE HELP!
> >
> > Hi all,
> >
> >     i need a simple way to import tables saved in a xml document to a
mySQL
> > databse. I found modules that easily do the opposite process (from mySQL
to
> > XML), but I don't know how to popolate my mySQL database using datas
stored
> > in an xml document. Please could somebody give me any suggestion? Thank
you,
> > from italy
>
> I don't know how to do what you ask, but of the off chance that its not
> atually what you _want_, I'll suggest you might want to look at
> Sleepycats native XML database...
>
> http://www.sleepycat.com/
>
> Are you _sure_ you need to somehow try to jam XML data into SQL tables?
>
> big
>
> -- 
> 'When I first met Katho, she had a meat cleaver in one hand and
> half a sheep in the other. "Come in", she says, "Hammo's not here.
> I hope you like meat.' Sharkey in aus.moto




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

Date: Fri, 23 Jan 2004 09:21:23 +0100
From: "Federico Bari" <fede72bari@tiscali.it>
Subject: Re: HELP: from XML to mySQL
Message-Id: <buqlj2$ifu$1@lacerta.tiscalinet.it>

thank you very much. My hope was that there was a module to update mySQL
database using datas stored in xml file automatically, whitout re-write the
code every time different for heach database and table. nothing of similar?

Federico.

"Tad McClellan" <tadmc@augustmail.com> ha scritto nel messaggio
news:slrnc10tta.bef.tadmc@magna.augustmail.com...
> Federico Bari <fede72bari@tiscali.it> wrote:
>
> > PLEASE HELP!
>
>
> There is no need to shout at us.
>
>
> > I don't know how to popolate my mySQL database using datas stored
> > in an xml document.
>
>
> Use an XML parsing module to read the input.
>
> Do stuff to the data.
>
> Use the DBI to write the output.
>
>
> -- 
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: Fri, 23 Jan 2004 11:42:52 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: HELP: from XML to mySQL
Message-Id: <pan.2004.01.23.16.42.49.974118@remove.adelphia.net>

[Please don't top post - it's rude]
[re-ordered to proper format]
On Fri, 23 Jan 2004 09:21:23 +0100, Federico Bari wrote:
> "Tad McClellan" <tadmc@augustmail.com> ha scritto nel messaggio
> news:slrnc10tta.bef.tadmc@magna.augustmail.com...
>> Federico Bari <fede72bari@tiscali.it> wrote:
>>
>> > PLEASE HELP!
>>
>>
>> There is no need to shout at us.
>>
>>
>> > I don't know how to popolate my mySQL database using datas stored
>> > in an xml document.
>>
>>
>> Use an XML parsing module to read the input.
>>
>> Do stuff to the data.
>>
>> Use the DBI to write the output.

> thank you very much. My hope was that there was a module to update mySQL
> database using datas stored in xml file automatically, whitout re-write the
> code every time different for heach database and table. nothing of similar?

Try searching at http://search.cpan.org/.

You could use one of the XML paring module to write a CSV file and then
either use the database client shell to perform the update or use one of
the DBD modules (like DBD::CSV) and let Perl do the updating.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Garbage In -- Gospel Out. 




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

Date: Fri, 23 Jan 2004 19:27:08 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: HELP: from XML to mySQL
Message-Id: <4011755F.30301@nospan.on.net>

Federico Bari wrote:
 > [top posting fixed]
 >
> "Tad McClellan" <tadmc@augustmail.com> ha scritto nel messaggio
> news:slrnc10tta.bef.tadmc@magna.augustmail.com...
> 
>>Federico Bari <fede72bari@tiscali.it> wrote:
>>
>>
>>>PLEASE HELP!
>>
>>
>>There is no need to shout at us.
>>
>>
>>
>>>I don't know how to popolate my mySQL database using datas stored
>>>in an xml document.
>>
>>
>>Use an XML parsing module to read the input.
>>
>>Do stuff to the data.
>>
>>Use the DBI to write the output.
>>
>>
>>-- 
>>    Tad McClellan                          SGML consulting
>>    tadmc@augustmail.com                   Perl programming
>>    Fort Worth, Texas
> 
> 
> 
 > thank you very much. My hope was that there was a module to update mySQL
 > database using datas stored in xml file automatically, whitout 
re-write the
 > code every time different for heach database and table. nothing of 
similar?
 >
 > Federico.
 >

The question would be how would such a module work?  XML is essentially 
a free format.  It a way of representing data in a variety of ways.  It 
is essentially a "data structure."  To write an XML import function 
would require a standardization of the structure or layout of the data 
(rows, columns, attributes, data, etc.)  Or a "protocol" so to speak.

There are two possibilities that I see could perhaps help you in the 
short term:

(1) Standardize your XML data structure, use a Perl XML module to read 
your data and parse the XML (like XML::Simple), and run the parsed data 
through a "handler" that conforms to your standardized data structure. 
So you have a parser and a handler.  If your structure needs to change, 
you just update your handler and you can still import.

(2) Look into using something like XML-RPC or SOAP.  (Which is a fine 
example in and off itself of "structuring" XML into a standard protocol 
-- that's what I'm talking about.)  You could write a wrapper that uses 
your SSL gateway and calls an XML-RPC service once inside the door to 
update your database.  XML-RPC is absolutely brainless to implement and 
it quite powerful (and quite unsecure, but if you had an SSL front door, 
it could be made secure.)

See if these will help you.  Your problem is an interesting one.  It's 
hard not to feel from your description that it perhaps couldn't use some 
help in re-architecting, but I'll refrain from sounding too disparaging; 
I'm sure it was done as best as it could be conceived.

Chris
-----
Chris Olive
chris (-at-) technologEase (-dot-) com
http://www.technologEase.com
(pronounced "technlogies")



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

Date: Fri, 23 Jan 2004 19:27:47 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: HELP: from XML to mySQL
Message-Id: <TAeQb.27978$UR1.16466@newssvr33.news.prodigy.com>

Federico Bari wrote:
 > [top posting fixed]
 >
> "Tad McClellan" <tadmc@augustmail.com> ha scritto nel messaggio
> news:slrnc10tta.bef.tadmc@magna.augustmail.com...
> 
>>Federico Bari <fede72bari@tiscali.it> wrote:
>>
>>
>>>PLEASE HELP!
>>
>>
>>There is no need to shout at us.
>>
>>
>>
>>>I don't know how to popolate my mySQL database using datas stored
>>>in an xml document.
>>
>>
>>Use an XML parsing module to read the input.
>>
>>Do stuff to the data.
>>
>>Use the DBI to write the output.
>>
>>
>>-- 
>>    Tad McClellan                          SGML consulting
>>    tadmc@augustmail.com                   Perl programming
>>    Fort Worth, Texas
> 
> 
> 
 > thank you very much. My hope was that there was a module to update mySQL
 > database using datas stored in xml file automatically, whitout 
re-write the
 > code every time different for heach database and table. nothing of 
similar?
 >
 > Federico.
 >

The question would be how would such a module work?  XML is essentially 
a free format.  It a way of representing data in a variety of ways.  It 
is essentially a "data structure."  To write an XML import function 
would require a standardization of the structure or layout of the data 
(rows, columns, attributes, data, etc.)  Or a "protocol" so to speak.

There are two possibilities that I see could perhaps help you in the 
short term:

(1) Standardize your XML data structure, use a Perl XML module to read 
your data and parse the XML (like XML::Simple), and run the parsed data 
through a "handler" that conforms to your standardized data structure. 
So you have a parser and a handler.  If your structure needs to change, 
you just update your handler and you can still import.

(2) Look into using something like XML-RPC or SOAP.  (Which is a fine 
example in and off itself of "structuring" XML into a standard protocol 
-- that's what I'm talking about.)  You could write a wrapper that uses 
your SSL gateway and calls an XML-RPC service once inside the door to 
update your database.  XML-RPC is absolutely brainless to implement and 
it quite powerful (and quite unsecure, but if you had an SSL front door, 
it could be made secure.)

See if these will help you.  Your problem is an interesting one.  It's 
hard not to feel from your description that it perhaps couldn't use some 
help in re-architecting, but I'll refrain from sounding too disparaging; 
I'm sure it was done as best as it could be conceived.

Chris
-----
Chris Olive
chris (-at-) technologEase (-dot-) com
http://www.technologEase.com
(pronounced "technlogies")



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

Date: Fri, 23 Jan 2004 23:51:40 +0000
From: Andy Baxter <news4@earthsong.null.free-online.co.uk>
Subject: Re: HELP: from XML to mySQL
Message-Id: <pan.2004.01.23.23.51.39.770990@earthsong.null.free-online.co.uk>

At earth time Thu, 22 Jan 2004 20:52:56 +0100, the following transmission
was received from the entity known as Federico Bari:

> PLEASE HELP!
> 
> Hi all,
> 
>     i need a simple way to import tables saved in a xml document to a mySQL
> databse. I found modules that easily do the opposite process (from mySQL to
> XML), but I don't know how to popolate my mySQL database using datas stored
> in an xml document. Please could somebody give me any suggestion? Thank you,
> from italy
> 
>             Federico.

I remember seeing a module that would do something like this, and then
went looking for it again a while back and never found it - it fell into
the bermuda triangle of cpan search.

Had another look, and one of these might help:

DBD:AnyData, DBIx::DBStag

also remember that you can use the keyword 'and' in cpan searches to cut
down the number of hits. (It doesn't say this anywhere I've seen.)


-- 
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line. 



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

Date: Sat, 24 Jan 2004 02:46:43 +0100
From: "Federico Bari" <fede72bari@tiscali.it>
Subject: Re: HELP: from XML to mySQL
Message-Id: <busiqt$scf$1@lacerta.tiscalinet.it>

i have already given a look there without find anything of useful. I also
give a fast look to the two module you write about in your message but they
seem to convert database into xml and not xml to database!!!

"Andy Baxter" <news4@earthsong.null.free-online.co.uk> ha scritto nel
messaggio
news:pan.2004.01.23.23.51.39.770990@earthsong.null.free-online.co.uk...
> At earth time Thu, 22 Jan 2004 20:52:56 +0100, the following transmission
> was received from the entity known as Federico Bari:
>
> > PLEASE HELP!
> >
> > Hi all,
> >
> >     i need a simple way to import tables saved in a xml document to a
mySQL
> > databse. I found modules that easily do the opposite process (from mySQL
to
> > XML), but I don't know how to popolate my mySQL database using datas
stored
> > in an xml document. Please could somebody give me any suggestion? Thank
you,
> > from italy
> >
> >             Federico.
>
> I remember seeing a module that would do something like this, and then
> went looking for it again a while back and never found it - it fell into
> the bermuda triangle of cpan search.
>
> Had another look, and one of these might help:
>
> DBD:AnyData, DBIx::DBStag
>
> also remember that you can use the keyword 'and' in cpan searches to cut
> down the number of hits. (It doesn't say this anywhere I've seen.)
>
>
> -- 
> http://www.niftybits.ukfsn.org/
>
> remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
> bin unless notified with [html] or [attachment] in the subject line.
>




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

Date: Sun, 25 Jan 2004 15:37:46 +0100
From: Michel Rodriguez <mirod@xmltwig.com>
Subject: Re: HELP: from XML to mySQL
Message-Id: <bv0epk$gr1$1@news-reader2.wanadoo.fr>

Federico Bari wrote:

>     i need a simple way to import tables saved in a xml document to a mySQL
> databse. I found modules that easily do the opposite process (from mySQL to
> XML), but I don't know how to popolate my mySQL database using datas stored
> in an xml document. Please could somebody give me any suggestion? Thank you,
> from italy

Did you look at DBD::AnyData?




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

Date: Wed, 28 Jan 2004 08:10:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How can I read file from end to first ?
Message-Id: <x7vfmw3349.fsf@mail.sysarch.com>


use File::ReadBackwards ;

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 29 Jan 2004 16:10:48 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How can I read file from end to first ?
Message-Id: <s48i10h2o8jut93ucbccjiejvv483rlatk@4ax.com>

On Wed, 28 Jan 2004 16:54:49 +0900, "ya" <jwhan@cybermed.co.kr> wrote:

>I want to analyze Apache Log file with perl. 
>But It is to waste process that log file is readed from first line. 
>Because I want to analyze Today's Log.( Log file's logrotate is "monthly")
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>How can I read file from end to first ?

Anno Siegel gave you a relevant answer pointing you to a suitable
module, suitable as far as the subject line of you post and this last
sentence are concerned.

But from the description above it *seems* that you do *not* really
want to 'tac': you just want to skip lines until you reach "today's
log" and then you can well read sequentially as usual.

So why not something like

  /$today/ and last while <$log>;
  while (<$log>) {
      # analyze log
      # ...
  }

(where /$today/ is some regexp that mathches the beginning of today's
logs)?


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Thu, 29 Jan 2004 08:00:07 +0100
From: Carsten Aulbert <carsten@welcomes-you.com>
Subject: Re: How can I read file from end to first ?
Message-Id: <bvab1p$q2262$2@ID-213226.news.uni-berlin.de>



Michele Dondi wrote:

> But from the description above it *seems* that you do *not* really
> want to 'tac': you just want to skip lines until you reach "today's
> log" and then you can well read sequentially as usual.

Or (like 'awstats' is doing it for example):

after finishing a run, just remember the file position and write it to a 
file (e.g. $logfile.'.position'). Next run you just have to seek for that 
and start reading - of course, extra measures have to be taken when 
logrotation takes place.

HTH
CA


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

Date: 28 Jan 2004 08:46:41 -0800
From: taralish@yahoo.com (Pea)
Subject: How to capture system output on NT?
Message-Id: <f4bfa101.0401280846.485ff80b@posting.google.com>

Hello,
I have a script which copies files on NT from one server to another. 
I would like to do a test/confirmation of the copy.  Here is my
command which reads the file name from STDIN:

system ("copy /V $_ $destination");

On NT if the file is copied successfully it will read "1 file(s)
copied."  How can I get more descriptive output or read the output and
if it reads "1 file(s) copied.", print something that tells the file
name was copied to the destination.  I tried $| and it printed a '1'
with a good copy and an unsuccessful copy.  I also tried writing the
output to a file with >> but I have a feeling that reading that file
for errors is not the best way to do this.

I also tried adding "or die..." but that always said the file was
missing even though it was already copied.

any hints?
thanks!


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

Date: 28 Jan 2004 09:47:29 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: How to capture system output on NT?
Message-Id: <4017f5b1@news.victoria.tc.ca>

Pea (taralish@yahoo.com) wrote:
: Hello,
: I have a script which copies files on NT from one server to another. 
: I would like to do a test/confirmation of the copy.  Here is my
: command which reads the file name from STDIN:

: system ("copy /V $_ $destination");

: On NT if the file is copied successfully it will read "1 file(s)
: copied."  How can I get more descriptive output or read the output and
: if it reads "1 file(s) copied.", print something that tells the file
: name was copied to the destination.  I tried $| and it printed a '1'
: with a good copy and an unsuccessful copy.  I also tried writing the
: output to a file with >> but I have a feeling that reading that file
: for errors is not the best way to do this.

: I also tried adding "or die..." but that always said the file was
: missing even though it was already copied.

: any hints?
: thanks!

try
	$results = `copy /V $_ $destination`;

and on nt I think you can also capture the error similar to sh so


	$results = `copy /V $_ $destination 2>&1`;

should also get any error messages




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

Date: 28 Jan 2004 17:47:23 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to capture system output on NT?
Message-Id: <u9n08855jo.fsf@wcl-l.bham.ac.uk>

taralish@yahoo.com (Pea) writes:

> system ("copy /V $_ $destination");
> 
> On NT if the file is copied successfully it will read "1 file(s)
> copied."  How can I get more descriptive output or read the output and
> if it reads "1 file(s) copied.", print something that tells the file
> name was copied to the destination.  I tried $| and it printed a '1'
> with a good copy and an unsuccessful copy.  I also tried writing the
> output to a file with >> but I have a feeling that reading that file
> for errors is not the best way to do this.

Can you explain how your question is substancially different from the
FAQ: "Why can't I get the output of a command with system()?"

> I also tried adding "or die..." but that always said the file was
> missing even though it was already copied.

Note: system() is unual - it returns _false_ on _success_.

Note: The status of the child process is returned in a special global
variable.

> any hints?

For everything I've said above and much more information about the
system() function in Perl see the section of the Perl reference manual
dealing with system().

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 28 Jan 2004 18:18:16 -0800
From: taralish@yahoo.com (Pea)
Subject: Re: How to capture system output on NT?
Message-Id: <f4bfa101.0401281818.7d6bec5@posting.google.com>

yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in message news:<4017f5b1@news.victoria.tc.ca>...
>  
> : any hints?
> : thanks!
> 
> try
> 	$results = `copy /V $_ $destination`;
> 
> and on nt I think you can also capture the error similar to sh so
> 
> 
> 	$results = `copy /V $_ $destination 2>&1`;
> 
> should also get any error messages

The first one worked.  Thanks!
Tara


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

Date: Thu, 29 Jan 2004 02:31:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to capture system output on NT?
Message-Id: <dg_Rb.2290$AI.2100@nwrddc01.gnilink.net>

Pea wrote:
> I have a script which copies files on NT from one server to another.
> I would like to do a test/confirmation of the copy.  Here is my
> command which reads the file name from STDIN:
>
> system ("copy /V $_ $destination");
>
> On NT if the file is copied successfully it will read "1 file(s)
> copied."  How can I get more descriptive output or read the output and
> if it reads "1 file(s) copied.", print something that tells the file
> name was copied to the destination.  I tried $| and it printed a '1'
> with a good copy and an unsuccessful copy.  I also tried writing the
> output to a file with >> but I have a feeling that reading that file
> for errors is not the best way to do this.

Why don't you start by reading the documentation for the functions you are
using?
In this case you may want to pay particular attention to the third
paragraph:

<quote>
    [...] This is
    *not* what you want to use to capture the output from a command,
    for that you should use [...]
</quote>

Or maybe check the FAQ. It has an entry addressing exactly your question.

jue




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

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 6008
***************************************


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