[23165] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5386 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 18 18:05:45 2003

Date: Mon, 18 Aug 2003 15:05:11 -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, 18 Aug 2003     Volume: 10 Number: 5386

Today's topics:
    Re: excel to csv (Tad McClellan)
    Re: excel to csv <jwillmore@cyberia.com>
    Re: excel to csv <jwillmore@cyberia.com>
    Re: excel to csv <REMOVEsdnCAPS@comcast.net>
        Find and Replace Howto (Anuradha)
    Re: Find and Replace Howto <noreply@gunnar.cc>
    Re: GetTextExtent (get RTF string's width/height) funct (James Willmore)
    Re: Help! Regular expression on html... (Peter Scott)
    Re: How to print out the value of a Cookie? (Charles DeRykus)
        mod_perl Perl Reference & refs to anonymous subs <valid-till-end-Aug@dpw.clara.co.uk>
    Re: Module::Build is yet more broken... (Sam Holden)
    Re: Order of evaluation of expressions <michael.p.broida@boeing.com>
    Re: Order of evaluation of expressions <REMOVEsdnCAPS@comcast.net>
    Re: Order of evaluation of expressions <REMOVEsdnCAPS@comcast.net>
    Re: Order of evaluation of expressions <REMOVEsdnCAPS@comcast.net>
    Re: perl 5.8.0 failed some locale tests on redhat 9 <rgarciasuarez@free.fr>
    Re: Perl equiv to PHP file() ? <noreply@gunnar.cc>
    Re: Perl equiv to PHP file() ? <amittai@amittai.com>
    Re: Perl equiv to PHP file() ? <noreply@gunnar.cc>
    Re: Perl equiv to PHP file() ? (Tad McClellan)
    Re: perl hacking for fun and pleasure <cpryce@pryce.net>
        Quick removal of the begging of a file? <ekulis@apple.com>
    Re: regex diffs between perl 5.6.1 and 5.8.0? <Patrick_member@newsguy.com>
    Re: regex diffs between perl 5.6.1 and 5.8.0? <uri@stemsystems.com>
        Regular Expression Help (Saya)
    Re: Regular Expression Help <shawn@magma.ca>
    Re: Regular Expression Help <abigail@abigail.nl>
    Re: Status counter (brice)
    Re: Strange problem with perl-oracle <alessandro.lagostena@tin.it>
    Re: Strange problem with perl-oracle (James Willmore)
    Re: XML to CSV Conversion <jwillmore@cyberia.com>
    Re: XML to CSV Conversion (trwww)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 18 Aug 2003 13:49:32 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: excel to csv
Message-Id: <slrnbk27ts.357.tadmc@magna.augustmail.com>

Josh <josh@nospam.pixael.com> wrote:

> i need a perl script to save an excel in csv


Then write one.

Post the code you have so far if you encounter problems, and we will
help you fix it.

You might start by searching for "Excel" and "CSV" at:

   search.cpan.org


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


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

Date: Mon, 18 Aug 2003 19:52:38 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: excel to csv
Message-Id: <20030818155210.749a5661.jwillmore@cyberia.com>

On Mon, 18 Aug 2003 15:55:43 +0200
"Josh" <josh@nospam.pixael.com> wrote:
> anybody knows a script to save an excel in csv?
> 
> i need it for a php script

If you need this for a PHP script, then wht not post to a PHP group?
Why are you mixing languages?  This is an annoying pet peeve I have.

My suggestion is pick one and stick with it's functionality.  I
believe this has been done successfully in both languages - pick one. 

If you still have a burning desire or some company restriction that
requires you to write in Perl for this task, have a look at the
Spreadsheet::WriteExcel module.  This should do what you're asking to
do.

HTH

Jim


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

Date: Mon, 18 Aug 2003 19:59:06 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: excel to csv
Message-Id: <20030818155839.24372110.jwillmore@cyberia.com>

On Mon, 18 Aug 2003 15:55:43 +0200
"Josh" <josh@nospam.pixael.com> wrote:
> anybody knows a script to save an excel in csv?
> 
> i need it for a php script

If you need this for a PHP script, then wht not post to a PHP group?
Why are you mixing languages?  This is an annoying pet peeve I have.

My suggestion is pick one and stick with it's functionality.  I
believe this has been done successfully in both languages - pick one. 

If you still have a burning desire or some company restriction that
requires you to write in Perl for this task, have a look at the
Spreadsheet::WriteExcel module.  This should do what you're asking to
do.

HTH

Jim




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

Date: Mon, 18 Aug 2003 15:54:49 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: excel to csv
Message-Id: <Xns93DBAC1EB2F10sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Josh" <josh@nospam.pixael.com> wrote in news:bhr2b9$275ib$1@ID-
203386.news.uni-berlin.de:

> "J. Gleixner" <glex_nospam@qwest.net> ha scritto nel messaggio
> news:mH60b.17$LC5.11341@news.uswest.net...
>> Josh wrote:
>> > hi all
>> >
>> > anybody knows a script to save an excel in csv?
>> >
>> > i need it for a php script
>> Then why ask in a perl newsgroup?  If you want a PHP answer, try a PHP
>> newsgroup.
> 
> i need a perl script to save an excel in csv
> 
> 

Perhaps Visual Basic, or VBA, would be a better tool for doing this?  Why 
do you have your heart set on Perl?

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP0E9LmPeouIeTNHoEQKqRgCfanTcjHrwN0Slmef16m63YN5TL/8An2II
jIJqdJCdyjJwzHp57FzMjcnq
=nRhz
-----END PGP SIGNATURE-----


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

Date: 18 Aug 2003 13:56:45 -0700
From: anuu_radhaa@yahoo.com (Anuradha)
Subject: Find and Replace Howto
Message-Id: <ca2bbf98.0308181256.cb44e60@posting.google.com>

Hi,

  I am newbie to Perl and would like to know if this possible doing in
Perl.

I have huge number of .4gl files. I need to find and replace the
string which contains mySchema.TO_CHAR( to CHAR( .

This can be accomplished in one-liner. While the problem I am facing
is
mySchema.TO_CHAR() is overloaded with arguments. I need to replace
ones which does not have ',' to TO_CHAR(). Here also care should be
taken that
TO_CHAR ( SUBSTR()) can also be done. so while searching it should
handle this also.

Any idea if this can be done in Perl or better do it manually.

Let me know and thanks for reading this query.

Anu


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

Date: Mon, 18 Aug 2003 23:11:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Find and Replace Howto
Message-Id: <bhrfer$2fmv5$1@ID-184292.news.uni-berlin.de>

Anuradha wrote:
> I have huge number of .4gl files. I need to find and replace the 
> string which contains mySchema.TO_CHAR( to CHAR( .
> 
> This can be accomplished in one-liner. While the problem I am
> facing is mySchema.TO_CHAR() is overloaded with arguments. I need
> to replace ones which does not have ',' to TO_CHAR(). Here also
> care should be taken that TO_CHAR ( SUBSTR()) can also be done. so
> while searching it should handle this also.
> 
> Any idea if this can be done in Perl or better do it manually.

I'm convinced it can be done in Perl, and if the number of files is 
"huge", it is probably advisable.

     http://www.perldoc.com/perl5.8.0/pod/perlintro.html#Files-and-I-O

     http://www.perldoc.com/perl5.8.0/pod/perlre.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 18 Aug 2003 14:46:35 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: GetTextExtent (get RTF string's width/height) function in Win32 Perl?
Message-Id: <e0160815.0308181346.778f8f21@posting.google.com>

"Russ Johnson" <russ.johnson@earthlink.net> wrote in message news:<5A70b.181$kd3.53@newsread2.news.atl.earthlink.net>...
> Microsoft Visual C++ and Borland (Inprise) Delphi have GetTextExtent (and
> similar functions) to determine the width and height of a string of RTF
> text. How can I do this in Perl (for Win32)?
> 
> Thank you for any information you can provide.

There are seveeral Perl modules that may fit the bill.  Check out:
http://search.cpan.org/search?query=RTF&mode=module

There may be a module there you could use.  As far as I know (and I
could be wrong), there's no 'native' way that Perl deals with RTF -
you have to use a module or 'roll your own' parser.

HTH

Jim


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

Date: Mon, 18 Aug 2003 19:36:59 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Help! Regular expression on html...
Message-Id: <vV90b.770185$3C2.17633639@news3.calgary.shaw.ca>

In article <8534bdeda79eade6682da761aea664bf@news.teranews.com>,
 merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>>>>> "Calle" == Calle Dybedahl <calle@lysator.liu.se> writes:
>
>Calle> #!/usr/bin/perl
>
>Calle> use strict;
>Calle> use warnings;
>
>Calle> use XML::LibXML;
>
>Calle> my $parser = XML::LibXML->new;
>       $parser->recovering(1); # or else <a href="/cgi/foo?a=b&c=d"> fails

ITYM $parser->recover(1); ?

>Calle> foreach my $doc (@ARGV) {
>Calle>     my $tree = $parser->parse_html_file($doc);
>Calle>     my $root = $tree->getDocumentElement;
>
>Calle>     foreach my $link ($root->findnodes("//a")) {
>Calle> 	$link->removeChildNodes;
>Calle> 	$link->appendTextNode("(link)");
>Calle>     }
>Calle>     print $tree->toStringHTML;
>Calle> }
>
>Otherwise, nice solution!  Who needs XSLT, when you've got Perl and
>LibXML!

-- 
Peter Scott
http://www.perldebugged.com


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

Date: Mon, 18 Aug 2003 18:44:57 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: How to print out the value of a Cookie?
Message-Id: <HJtw2x.MHn@news.boeing.com>

In article <BVzVa.78$xq3.40414@news.uswest.net>,
marmot101 <marmot101@yahoo.com> wrote:
>Hi, All,
>
>Using CGI, I get a response from server which plant a Cookie in client
>machine. Now I can get this Cookie, but I don't know how to print out the
>value of this Cookie? I checked online manual, but seems none method works.
>....
># How to print out value of Cookie here?
># print "Cookie = ", $cookie_jar{'Stamp'}->value;   # doesn't work
>}

Perhaps the as_string method...?

    print $cookie_jar->as_string

--
Charles DeRykus


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

Date: Mon, 18 Aug 2003 20:42:31 +0100
From: RA Jones <valid-till-end-Aug@dpw.clara.co.uk>
Subject: mod_perl Perl Reference & refs to anonymous subs
Message-Id: <TLls9PCnwSQ$EwnK@nildram.co.uk>

The source for this question is 'Perl Reference' at 
<http://perl.apache.org/docs/general/perl_reference/perl_reference.html>.


Under the section 'my() Scoped Variable in Nested Subroutines - The 
Poison', the following is quoted:

nested.pl
#!/usr/bin/perl

use strict;

sub print_power_of_2 {
   my $x = shift;

   sub power_of_2 {
     return $x ** 2;
   }

   my $result = power_of_2();
   print "$x^2 = $result\n";
}

print_power_of_2(5); # produces 25
print_power_of_2(6); # also produces 25!

The solution is to use a reference to an anonymous subroutine in place 
of power_of_2, which deals with the problem of variables not staying 
shared.

But isn't this 'problem' caused in the first place by print_power_of_2 
not handing on to power_of_2 the value originally handed to it, and 
letting power_of_2 take $x into its own local variable?

For example the following seems much simpler, and doesn't need to use a 
reference to an anonymous subroutine:

sub print_power_of_2 {
   my $x = shift;

   sub power_of_2 {
    my $x =shift;
    return $x ** 2;
   }

   my $result = power_of_2($x);
   print "$x^2 = $result\n";
}

print_power_of_2(5); # produces 25
print_power_of_2(6); # now correctly produces 36

Is there a penalty incurred by doing it this apparently simpler way?
-- 
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)co(dot)uk



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

Date: 18 Aug 2003 21:59:25 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Module::Build is yet more broken...
Message-Id: <slrnbk2j1t.dl5.sholden@flexal.cs.usyd.edu.au>

On Mon, 18 Aug 2003 13:37:31 +0000 (UTC),
	Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> [A complimentary Cc of this posting was sent to
> Sam Holden
><sholden@cs.usyd.edu.au>], who wrote in article <slrnbk05g0.ah8.sholden@flexal.cs.usyd.edu.au>:
>> > The beauty of Makefile.PL user interface (as opposed to the - faulty -
>> > packager's interface) is that it was shell-, OS-, filesystem-,
>> > etc-independent.  Now comes Build - and the invocation has the ./file
>> > syntax, which is system-dependent!
>> 
>> Surely it could just say:
>> 
>> perl Build.PL
>> perl Build test
>> perl Build install
> 
> Why do you think so?  `perl Build' being different from `perl
> Build.PL' - this depends on the (undocumented and quite probably
> subject to change soon) order of executable extensions for the Perl
> scripts.  Moreover, who guaranties that there is no F<Build> on the
> PATH before '.'?

I'm saying that if the module works so that executing Build.PL 
creates a perl script called Build in the current directory (which is
implied by the "./Build test" command you mentioned) then after running 
perl Build.PL you can just run "perl Build test" instead of "./Build test".

The only thing that matters with respect to the PATH and "perl Build test"
is that "perl" is in the PATH, which is implied by the execution of
"perl Build.PL" or even "perl Makefile.PL".

The command "perl Build test" tells perl to run the script in the file
"Build" in the current working directory and set @ARGV to be ('test').
Is there *any* platform on which this is not true? Assuming the
existance of a command line interface (which is assummed by the current
Makefile.PL I would suspect).

-- 
Sam Holden



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

Date: Mon, 18 Aug 2003 19:41:30 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Order of evaluation of expressions
Message-Id: <3F412BEA.DC9CA189@boeing.com>

Abigail wrote:
> 
> Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote
> ~~  mjd@plover.com (Mark Jason Dominus) wrote in news:bhok6j$70f$1@plover.com:
> ~~ > Is this:
> ~~ >
> ~~ >         @s = qw(a b);
> ~~ >         $z = shift(@s) . shift(@s);
> ~~ >         print $z;
> ~~ >
> ~~ > guaranteed to print "ab"?
> ~~ >
> ~~  Yes.  Unlike C, Perl's order-of-evaluation is well-defined.
> 
> Where is its order of evaluation documented? Where in the documentation
> does it say that:
>     @a = (3, 4, 5);
>     $z = shift (@a) + shift (@a) * shift (@a);
>     print $z;
> results in 23 being printed?

	Unless I'm missing something in your comment, it seems the question
	boils down to "what precedence do subroutine/function calls have?"

	I don't see "calls" specifically in the operator precedence listing at
	the top of "perldoc perlop", but I think the highest priority "terms"
	is what the function calls are in this case.  Each function call was
	evaluated in order left to right as "terms" of the larger expression,
	THEN the multiply was done, THEN the addition was done.

	This seems to fit the "perldoc perlop" description.

		Mike


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

Date: Mon, 18 Aug 2003 15:40:48 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Order of evaluation of expressions
Message-Id: <Xns93DBA9BE6F487sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Michael P. Broida" <michael.p.broida@boeing.com> wrote in
news:3F412BEA.DC9CA189@boeing.com: 

>      Unless I'm missing something in your comment, it seems the
>      question boils down to "what precedence do subroutine/function
>      calls have?" 

No, not really.  Precedence is different than order of evaluation.  In C, 
for example, precedence is well-defined, but order of evaluation is 
famously undefined.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP0E55WPeouIeTNHoEQKsYACg0X/4yuCnTu7pD7cqw0j6Kid9DQsAoN89
L0ZfvJcELWdN3q4IhNZl8Rfl
=FGbJ
-----END PGP SIGNATURE-----


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

Date: Mon, 18 Aug 2003 15:46:00 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Order of evaluation of expressions
Message-Id: <Xns93DBAAA01895Dsdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Abigail <abigail@abigail.nl> wrote in
news:slrnbk10md.srs.abigail@alexandra.abigail.nl: 

> Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote on MMMDCXXXIX
> September MCMXCIII in
> <URL:news:Xns93DAD6841E7E9sdn.comcast@206.127.4.25>: ~~  -----BEGIN
> PGP SIGNED MESSAGE----- ~~  Hash: SHA1
> ~~  
> ~~  mjd@plover.com (Mark Jason Dominus) wrote in
> news:bhok6j$70f$1@plover.com: ~~  
> ~~ > Is this:
> ~~ > 
> ~~ >         @s = qw(a b);
> ~~ >         $z = shift(@s) . shift(@s);
> ~~ >         print $z;
> ~~ > 
> ~~ > guaranteed to print "ab"?
> ~~ > 
> ~~  
> ~~  Yes.  Unlike C, Perl's order-of-evaluation is well-defined.
> 
> 
> Where is its order of evaluation documented? Where in the
> documentation does it say that:
> 
>     @a = (3, 4, 5);
>     $z = shift (@a) + shift (@a) * shift (@a);
>     print $z;
> 
> results in 23 being printed?

Well, I don't know.  I could have sworn that I either read it in some 
authoritative place, or I heard some authority state it.  But searching 
through the docs, and searching online, I can't find anything to back up 
my statement.  I withdraw it.

Thanks for your nice warm fuzzy tone, Abigail.

I also should have noticed who was posing the question.  MJD knows much 
more about Perl, especially its internals, than I do.  If I had noticed 
that he was the one who had asked the question, I wouldn't have responded 
with my quick, unresearched answer; MJD certainly has as many or more 
resources and history of Perl knowledge as myself.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP0E7HWPeouIeTNHoEQJ7hACeNY/pVLoGaPyX5PTTrlD0fymLMlwAoIsL
KIJXOu+HZbq2hmjlHs5PL2js
=UYis
-----END PGP SIGNATURE-----


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

Date: Mon, 18 Aug 2003 15:50:55 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Order of evaluation of expressions
Message-Id: <Xns93DBAB75A394Fsdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

nobull@mail.com wrote in
news:4dafc536.0308180938.72123045@posting.google.com: 

> I'd like to see the "language spec" (whatever that may be) make a
> statement one way or the other.
> 
> Making it defined will reduce the scope for optomisations in Ponie.
> 
> Making it undefied will break a lot of existing code.
> 
> Not an easy choice.

In my humble opinion, as a long-time C and Perl programmer, the language 
ought to specify order of evaluation.  Imho, it is one of C's great 
weaknesses and sources of confusion that it does not define the OOE.  This 
is a huge confusion for many new programmers, and a continually recurring 
theme on comp.lang.c (at least, it had been for years when I stopped 
reading c.l.c a couple years ago).

If Perl does not currently guarantee OOE, I would vote that it should.  The 
potential gain in local platform-dependent optimization is not worth the 
non-portability and confusion.  My two cents.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP0E8RGPeouIeTNHoEQKGvQCfb09TbFi7fGlIen1zJpfHVYvl61AAoIsu
fop/Vi2oQzOCniaux9OIwpk8
=p2Pn
-----END PGP SIGNATURE-----


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

Date: 18 Aug 2003 21:57:29 GMT
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: perl 5.8.0 failed some locale tests on redhat 9
Message-Id: <slrnbk2jaf.6sr.rgarciasuarez@dat.local>

trwww wrote in comp.lang.perl.misc :
> I have some failed tests when running 'make test' for perl 5.8.0 on
> redhat 9. Below are the failed tests and messages, and below that is
> the output of ./myconfig per
> http://www.perldoc.com/perl5.8.0/INSTALL.html#Reporting-Problems

That's probably due to the fact that your locale is an UTF8 one (type
"locale" to know about). Under a non-UTF8 locale this should succeed.

Nota : RedHat 9 comes with a version of perl that is more recent that is
5.8.0 (it incorporates developement patches to be released with perl
5.8.1.)


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

Date: Mon, 18 Aug 2003 20:10:04 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl equiv to PHP file() ?
Message-Id: <bhr4r8$29agi$1@ID-184292.news.uni-berlin.de>

Amittai Aviram wrote:
> Does Perl have an equivalent to the PHP function file()?  file()
> reads a file into an array.  More importantly for me, you can pass
> a URL to file(), and it will read into the array the HTML output of
> that file as served through HTTP:
> 
> $output = file(''http://www.mysite.com/test.pl'')
> 
> This will read the HTML output of the test.pl executable and put
> each line of it into a successive element of the $output array.

     use LWP::Simple;
     @output = split /\n/, get('http://www.mysite.com/test.pl');

http://search.cpan.org/author/GAAS/libwww-perl-5.69/lib/LWP/Simple.pm

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 18 Aug 2003 14:32:34 -0400
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Re: Perl equiv to PHP file() ?
Message-Id: <bhr646$29rt4$1@ID-124651.news.uni-berlin.de>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bhr4r8$29agi$1@ID-184292.news.uni-berlin.de...
> Amittai Aviram wrote:
> > Does Perl have an equivalent to the PHP function file()?  file()
> > reads a file into an array.  More importantly for me, you can pass
> > a URL to file(), and it will read into the array the HTML output of
> > that file as served through HTTP:
> >
> > $output = file(''http://www.mysite.com/test.pl'')
> >
> > This will read the HTML output of the test.pl executable and put
> > each line of it into a successive element of the $output array.
>
>      use LWP::Simple;
>      @output = split /\n/, get('http://www.mysite.com/test.pl');
>
> http://search.cpan.org/author/GAAS/libwww-perl-5.69/lib/LWP/Simple.pm
>

GREAT!  Thank you so much, Gunnar!  One follow-up question ...

The getstore($url, $file) actually looks exactly like what I want, since it
gets the HTML document and "stores it in the file."  But I'm not clear about
the code context.  Should you first define $file as a file handle?  Do you
need to open the file first before calling getstore?  And then close it
afterwards?  This may seem obvious to many here, but the documentation left
it unclear and perhaps the info would be helpful to other newbies, as well
as to me.  Thanks again for the help.

Amittai





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

Date: Mon, 18 Aug 2003 20:48:56 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl equiv to PHP file() ?
Message-Id: <bhr746$2a8pn$1@ID-184292.news.uni-berlin.de>

Amittai Aviram wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message 
> news:bhr4r8$29agi$1@ID-184292.news.uni-berlin.de...
> 
>>     use LWP::Simple;
>>     @output = split /\n/, get('http://www.mysite.com/test.pl');
>> 
>> http://search.cpan.org/author/GAAS/libwww-perl-5.69/lib/LWP/Simple.pm
> 
> GREAT!  Thank you so much, Gunnar!  One follow-up question ...
> 
> The getstore($url, $file) actually looks exactly like what I want, 
> since it gets the HTML document and "stores it in the file."

Well, you said array...

> But I'm not clear about the code context.  Should you first define 
> $file as a file handle?  Do you need to open the file first before 
> calling getstore?  And then close it afterwards?

To be able to give you a reliable answer to that question, I did what
you should have done before asking: I tested. ;-)

$file is just the path to the file, and you don't need to open/close
it separately. This should do it:

     use LWP::Simple;
     getstore('http://www.mysite.com/test.pl', $file);

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 18 Aug 2003 13:47:24 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl equiv to PHP file() ?
Message-Id: <slrnbk27ps.357.tadmc@magna.augustmail.com>

Amittai Aviram <amittai@amittai.com> wrote:

> you can pass a URL to file(),
> and it will read into the array the HTML output of that file as served
> through HTTP:


Your Question is Asked Frequently:

   perldoc -q HTML

      How do I fetch an HTML file?


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


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

Date: Mon, 18 Aug 2003 15:10:37 -0500
From: cp <cpryce@pryce.net>
Subject: Re: perl hacking for fun and pleasure
Message-Id: <180820031510377251%cpryce@pryce.net>

In article <iv3ujv41n315ou09629gfh96aep93gf00n@4ax.com>, hudson
<scripts_you_know_the_drill_@hudsonscripting.com> wrote:

> OK...let's forget about this and just talk about perl hacking for fun
> and pleasure ;-)
> 
> much better........all this nonsense and bad karma is getting everyone
> nowhere fast

Then start up rec.perl.hacking. And leave this news group to a
professional discussion about Perl. I make a living programming in
Perl. Sometimes this news group is essential to getting that job done.

Some of the people who are trying to help you learn how to have fun
with Perl make their living using Perl. Some of us have had to fight
tooth and nail with project managers against misconception that Perl is
not a "professional" programming language, and that Open Source
projects are synonimous with "poor programming." 

When you post sloppy code "for fun and pleasure", you make my job
harder.  The "bad Karma" you are experiencing is other programmers
fighting to keep their craft professional.

Your poor code posting immediately becomes a part of an archive
available to anyone with google and the sense to search the archives
first for the answers to their questions.

-- 
cp


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

Date: Mon, 18 Aug 2003 12:40:48 -0700
From: Ed Kulis <ekulis@apple.com>
Subject: Quick removal of the begging of a file?
Message-Id: <BB6679D0.7F7B%ekulis@apple.com>

Hi,

I'd like to use perl to chop the head off a file in Unix that an application
is writing to without disturbing the file.  (Apps we use are Oracle,
PeopleSoft, Vantive, Unix scripting)

We've got some immense trace files and I'd like to remove say the first 50%
of the lines of a 200 meg file while an has the file open and the app is
writing to it. That way we can manage the filesystem space while retaining
the recent interesting information.

cat /dev/null > file
    sometimes works to zero the entire file while it's being written to
because I think that the Unix inode stays the same so it won't make any
difference to the apps open state. I'm not clear on the details of the file
open states.

I don't want to do anything to the app configuration or startup. I'd like to
know if there are any Perl functions/techniques that could say move the
beginning of file pointer to the mid file some where.

Is there a clever way to get the size of a file and remove the beginning of
it?

-ed



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

Date: 18 Aug 2003 14:03:48 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: Re: regex diffs between perl 5.6.1 and 5.8.0?
Message-Id: <bhrevk062d@drn.newsguy.com>

In article <3f3e07c1.393636538@news.erols.com>, Jay Tilton says...
>
>Patrick Flaherty <Patrick_member@newsguy.com> wrote:
>: In article <3f3c9ebc.301200988@news.erols.com>, Jay Tilton says...
>: >Patrick Flaherty <Patrick_member@newsguy.com> wrote:
>: >
>: >: Back in 5.6.1, the following succeeded in stripping out all x1a garbage
>chars
>: >: from a set of files:
>: >: 
>: >:   perl -p0777 -i.bu -e 's/\X1a+$//g' house.lis
>: >:
>: >: I run the same thing under 5.8.0 and it has no effect.
>: >                            
>: >Case matters.  "\X1a" is not the same thing as "\x1a".
>: >"\X" in a regex has its own special meaning.
>: 
>: Actually my original code _is_ a lower-case x.  The upper case in the above
>was
>: some stuff I was experimenting with.  So I don't think this is the problem I'm
>: having.
>
>Then I'm stumped.  As far as that code goes, there should be no
>difference between 5.6.1 and 5.8.0.
>
>The only reason I can see that the code would not strip \x1a
>characters from the ends of lines is if the lines have no \x1a at
>their ends.
>
>It's time for a more rigorous regression test and a hard look at your
>data file.
>
>As a complete WAG, you might investigate binmode(), which became
>significant on all platforms with Perl 5.8.0.
>

Hi Jay,

  Well that's very interesting.

Yes the 1a's are there.  This is a file copied from VMS to Windows over
PATHworks (file sharing software spanning VMS and Windows).  The 1a's are a (to
us) well-known artifact of differences in the file systems on VMS and Windows.

I check the 1a's by going into Emacs and then going to the bottom of the file. A
whole bunch of ctrl-Z's (that aren't there when you open the file on VMS). 
Moreover I can use Emacs (on Windows) and open the file with hexl-find-file and
indeed the ctrl-Z's correspond to 1a's.

MAYBE A FACTOR: the 5.8 (Perl) that I'm trying to use is on Citrix servers
(where various flavors of low-level funkiness can happen for programmers).

Did an experiement.  The one-liner still doesn't work on Citrix and with Perl
5.8.  However the following in a script _does work_ (!):

local $^I = '.bu';
local @ARGV = glob '*.TXT';
my $prev_filename;
while (<>) {
    if ($ARGV ne $prev_filename) {
	print "$ARGV\n";
	print STDOUT "$ARGV\n";
    }
    s/\x1a+$//g;
    print;
    $prev_filename = $ARGV;
}

(This adds printing the filename into the first line of the contents since there
are about 900 of these files that I'm going to then import into iSilo and load
onto my Palm).

Obviously I'll use the script for the time being but it would be interesting to
get to the bottom of why the one-liner (the direct command-line invocation)
doesn't work.

I, unfortunately, can't do Perl installs onto our Citrix servers.  However I can
probably ask the systems guys to put varying versions of Perl into some other
location, leaving the environment variables pointing to the main location
untouched).

  pat



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

Date: Mon, 18 Aug 2003 21:24:25 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: regex diffs between perl 5.6.1 and 5.8.0?
Message-Id: <x7ekzi4q2e.fsf@mail.sysarch.com>

>>>>> "PF" == Patrick Flaherty <Patrick_member@newsguy.com> writes:

  >> : >:   perl -p0777 -i.bu -e 's/\X1a+$//g' house.lis
  >> : >:
  >> : >: I run the same thing under 5.8.0 and it has no effect.
  >> : >                            
  >> : >Case matters.  "\X1a" is not the same thing as "\x1a".
  >> : >"\X" in a regex has its own special meaning.
  >> : 

  PF> Yes the 1a's are there.  This is a file copied from VMS to Windows
  PF> over PATHworks (file sharing software spanning VMS and Windows).
  PF> The 1a's are a (to us) well-known artifact of differences in the
  PF> file systems on VMS and Windows.

  PF> local $^I = '.bu';
  PF> local @ARGV = glob '*.TXT';
  PF> my $prev_filename;
  PF> while (<>) {
  PF>     if ($ARGV ne $prev_filename) {
  PF> 	print "$ARGV\n";
  PF> 	print STDOUT "$ARGV\n";
  PF>     }
  PF>     s/\x1a+$//g;
  PF>     print;
  PF>     $prev_filename = $ARGV;
  PF> }

then it might be the one liner issue on the windoze platform. could you
have used the wrong quotes? one liners and quotes and stuff are
broken^Wannoying on windoze. since the script worked, it is pointing to
the one liner as the culprit. the 'shell' you use maybe breaking the -e
string with the hex value.

uri

-- 
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: 18 Aug 2003 12:24:56 -0700
From: vahu@novonordisk.com (Saya)
Subject: Regular Expression Help
Message-Id: <9e9517bf.0308181124.19a9c3d5@posting.google.com>

Hi, 
here is the scenario:

I have a variable containing the following:
<table cellpadding="0" cellspacing="0">
	<tr>
	<td class="footer">Ottiliavej 9</td>
	<td class="footer">telefon 092323</td></tr>
	<tr><td class="footer">DK-2500 Valby</td>
	<td class="footer">fax 092323</td>
	</tr>
</table>

A regular expression that gives me the text(sometext) between the <td
 ...>sometext</td>
tags ?
I have tried all of my own knowledge og regular expression (which by
the way is very little). Any help will be appeciated.

Thx 
Saya


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

Date: Mon, 18 Aug 2003 15:39:09 -0400
From: Shawn Corey <shawn@magma.ca>
Subject: Re: Regular Expression Help
Message-Id: <LmWdnUIpHP6PttyiXTWJjQ@magma.ca>


/<td[^>]*>(.*?)<\/td/ && my $text = $1;

Saya wrote:
> Hi, 
> here is the scenario:
> 
> I have a variable containing the following:
> <table cellpadding="0" cellspacing="0">
> 	<tr>
> 	<td class="footer">Ottiliavej 9</td>
> 	<td class="footer">telefon 092323</td></tr>
> 	<tr><td class="footer">DK-2500 Valby</td>
> 	<td class="footer">fax 092323</td>
> 	</tr>
> </table>
> 
> A regular expression that gives me the text(sometext) between the <td
> ...>sometext</td>
> tags ?
> I have tried all of my own knowledge og regular expression (which by
> the way is very little). Any help will be appeciated.
> 
> Thx 
> Saya



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

Date: 18 Aug 2003 21:12:33 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regular Expression Help
Message-Id: <slrnbk2ga1.336.abigail@alexandra.abigail.nl>

Saya (vahu@novonordisk.com) wrote on MMMDCXXXIX September MCMXCIII in
<URL:news:9e9517bf.0308181124.19a9c3d5@posting.google.com>:
^^  Hi, 
^^  here is the scenario:
^^  
^^  I have a variable containing the following:
^^ <table cellpadding="0" cellspacing="0">
^^  	<tr>
^^  	<td class="footer">Ottiliavej 9</td>
^^  	<td class="footer">telefon 092323</td></tr>
^^  	<tr><td class="footer">DK-2500 Valby</td>
^^  	<td class="footer">fax 092323</td>
^^  	</tr>
^^ </table>
^^  
^^  A regular expression that gives me the text(sometext) between the <td
^^  ...>sometext</td>
^^  tags ?
^^  I have tried all of my own knowledge og regular expression (which by
^^  the way is very little). Any help will be appeciated.

    #!/usr/bin/perl

    use strict;
    use warnings;

    use Regexp::Common;

    $_ = <<'--';
    <table cellpadding="0" cellspacing="0">
            <tr>
            <td class="footer">Ottiliavej 9</td>
            <td class="footer">telefon 092323</td></tr>
            <tr><td class="footer">DK-2500 Valby</td>
            <td class="footer">fax 092323</td>
            </tr>
    </table>
    --

    while (m!$RE{balanced}{-begin => '<td'}{-end => '</td>'}{-keep}!g) {
        print "$1\n";
    }
    __END__
    <td class="footer">Ottiliavej 9</td>
    <td class="footer">telefon 092323</td>
    <td class="footer">DK-2500 Valby</td>
    <td class="footer">fax 092323</td>


This will take of nested elements as well. However, it won't deal 
with cases like:

    <td><img src = 'foo.gif' alt = '</td>'></td>


Abigail
-- 
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'


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

Date: 18 Aug 2003 12:03:28 -0700
From: bricemason@hotmail.com (brice)
Subject: Re: Status counter
Message-Id: <50404b7a.0308181103.60b7b2e4@posting.google.com>

Hello again,

I actually ended up using code similar to the following. I ran a
search on the Term::ProgressBar module in Google groups and stumbled
upon this code snippet:

#!/usr/bin/perl -w

use strict;

for(0..99999){
	print "\r";
	print "Processing line $_";
}

brice

> 
> Take a look at Term::ProgressBar;
> 
>   my $bar = Term::ProgressBar->new({name => 'Processing...', count => 10});
>   for ( 1 .. 10 ) {
>       $bar->update();
>   }


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

Date: Mon, 18 Aug 2003 19:02:29 GMT
From: "alessandro.lagostena" <alessandro.lagostena@tin.it>
Subject: Re: Strange problem with perl-oracle
Message-Id: <9p90b.14554$zN5.436845@news1.tin.it>



Ron Reidy wrote:
> 
> [snip]
> 
>> You must install a Solaris patch to run this version of the Java runtime.
>> Please see the README and release notes for more information.
> 
> 
> Did you read the README file(s)?  Have you searched metalink (I think 
> the problem is answered in both places)?
The problem is that i not know what is and where is thie file
> 
>>  I think that the errors appears when the program try to connect at 
>> the DB
> 
> 
> Why don't you know?  Have you used the bebugger and stepped through the 
> code?
Yes  and the message appears the line

my $dbh = DBI->connect( "dbi:$DRIVER:$istance",
                                         $username,
                                         $password,
                         {AutoCommit => 0,
                          RaiseError => 1,
                          PrintError => 0 ,
                          LongReadLen=> 512000 } )
> 
>>
>> I have compared the 2 box but seams equals , objvius a difference are 
>> present but i not know where find it
>>
>> Can someone have some sudgestion about this probelm ?
>>
>> Thanks for the support
>>
>> Regards LAGO
>>
> 
> 
Thanks for the support regards LAGO



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

Date: 18 Aug 2003 14:41:10 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Strange problem with perl-oracle
Message-Id: <e0160815.0308181341.2e023348@posting.google.com>

"alessandro.lagostena" <alessandro.lagostena@tin.it> wrote in message news:<9W20b.13097$zN5.386357@news1.tin.it>...
> You must install a Solaris patch to run this version of the Java runtime.
> Please see the README and release notes for more information.
>   I think that the errors appears when the program try to connect at the DB
> 
> I have compared the 2 box but seams equals , objvius a difference are 
> present but i not know where find it
> 
> Can someone have some sudgestion about this probelm ?

The DBI module provides a 'trace' method to see the communications
between the script and the server.

DBI->(4,'tracefile.txt');

The '4' is the level and 'tracefile.txt' is the file that will hold
the trace - which is very verbose if set to '4' (see the DBI
documentation for more options and settings).

This will aid in troubleshooting the issue - as well as reading the
README.

HTH

Jim


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

Date: Mon, 18 Aug 2003 19:58:37 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: XML to CSV Conversion
Message-Id: <20030818155810.44fe12fa.jwillmore@cyberia.com>

On 18 Aug 2003 06:53:19 -0700
anamalay@hotmail.com (Ravi) wrote:
> Does anyone have a perl script handy to show me how to convert an
> XML document to CSV format ?

Someone has gone to the trouble of creating the XML::CSV module just
for this purpose.

HTH

Jim


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

Date: 18 Aug 2003 14:53:40 -0700
From: toddrw69@excite.com (trwww)
Subject: Re: XML to CSV Conversion
Message-Id: <d81ecffa.0308181353.700b6342@posting.google.com>

anamalay@hotmail.com (Ravi) wrote in message news:<2c6dd813.0308180553.382c295b@posting.google.com>...
> Hi All,
> 
> Does anyone have a perl script handy to show me how to convert an XML
> document to CSV format ?
> 

Here is a way, using XML::XPath:

[trwww@waveright perl]# cat xml2csv.pl
#!/usr/bin/perl
use warnings;
use strict;
use XML::XPath;

my($xp) = XML::XPath->new( join('', <DATA>) );
my(@records) = $xp->findnodes( '/records/record' );
my($firstTime) = 0;

foreach my $record ( @records ) {
  my(@fields) = $xp->find( './child::*', $record )->get_nodelist();
  unless ( $firstTime++ ) {
    print( join( ',', map { $_->getName() } @fields ), "\n");
  }

  print( join( ',', map { $_->string_value() } @fields ), "\n");

}

__DATA__
<records>
  <record>
    <id>1</id>
    <name>George Foo</name>
    <phone>555.666.7777</phone>
  </record>
  <record>
    <id>2</id>
    <name>Betty Bar</name>
    <phone>666.777.8888</phone>
  </record>
</records>

[trwww@waveright perl]# perl xml2csv.pl
id,name,phone
1,George Foo,555.666.7777
2,Betty Bar,666.777.8888

If your data has commas in it, then you can run $_->string_value()
through a filter that escapes the comma.

enjoy,

Todd W.


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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.  

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


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