[31485] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2744 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 30 18:09:51 2009

Date: Wed, 30 Dec 2009 15:09:12 -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           Wed, 30 Dec 2009     Volume: 11 Number: 2744

Today's topics:
        How to print hash recursively? <pengyu.ut@gmail.com>
    Re: How to print hash recursively? <tadmc@seesig.invalid>
    Re: How to print hash recursively? <jurgenex@hotmail.com>
    Re: How to print hash recursively? <pengyu.ut@gmail.com>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <spamtrap@shermpendley.com>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <nospam-abuse@ilyaz.org>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <spamtrap@shermpendley.com>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <spamtrap@shermpendley.com>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <nospam-abuse@ilyaz.org>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <nospam-abuse@ilyaz.org>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <nospam-abuse@ilyaz.org>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <ben@morrow.me.uk>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <hjp-usenet2@hjp.at>
    Re: How to put '#!/usr/bin/env perl -w' at the beginnin <hjp-usenet2@hjp.at>
        How to serialize a perl object in a .gz file <pengyu.ut@gmail.com>
    Re: Simple loop error (Seymour J.)
        WWW::Scripter or Javascript and perl <nathanabu@gmail.com>
    Re: WWW::Scripter or Javascript and perl <ben@morrow.me.uk>
    Re: WWW::Scripter or Javascript and perl <smallpond@juno.com>
    Re: WWW::Scripter or Javascript and perl <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Dec 2009 13:13:38 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How to print hash recursively?
Message-Id: <b00011f3-1815-4544-87b9-ee99353f6394@j4g2000yqe.googlegroups.com>

while ( ($k,$v) = each %hash ) {
    print "$k => $v\n";
}

The above code would not print the content of $v, if $v points to
complex data structure such as arrays, hash of arrays, etc.

I'm wondering if there is a convenient function that can print a hash
table recursively into the elements.


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

Date: Wed, 30 Dec 2009 15:24:12 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to print hash recursively?
Message-Id: <slrnhjnh1i.79g.tadmc@tadbox.sbcglobal.net>

Peng Yu <pengyu.ut@gmail.com> wrote:
> while ( ($k,$v) = each %hash ) {
>     print "$k => $v\n";
> }
>
> The above code would not print the content of $v, if $v points to
> complex data structure such as arrays, hash of arrays, etc.
>
> I'm wondering if there is a convenient function that can print a hash
> table recursively into the elements.


I think you are looking for:

   perldoc Data::Dumper


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"


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

Date: Wed, 30 Dec 2009 13:24:24 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to print hash recursively?
Message-Id: <a5hnj554ht2cn3503amgp9sphk2j5s8r6b@4ax.com>

Peng Yu <pengyu.ut@gmail.com> wrote:
>while ( ($k,$v) = each %hash ) {
>    print "$k => $v\n";
>}
>
>The above code would not print the content of $v, if $v points to
>complex data structure such as arrays, hash of arrays, etc.
>
>I'm wondering if there is a convenient function that can print a hash
>table recursively into the elements.

1: it is trivial to write your own
2: Did you check Data::Dumper?

jue


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

Date: Wed, 30 Dec 2009 14:02:11 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: Re: How to print hash recursively?
Message-Id: <fc436f21-991b-4d3d-983b-ebca0aad88ec@a21g2000yqc.googlegroups.com>

On Dec 30, 3:24=A0pm, Tad McClellan <ta...@seesig.invalid> wrote:
> Peng Yu <pengyu...@gmail.com> wrote:
> > while ( ($k,$v) =3D each %hash ) {
> > =A0 =A0 print "$k =3D> $v\n";
> > }
>
> > The above code would not print the content of $v, if $v points to
> > complex data structure such as arrays, hash of arrays, etc.
>
> > I'm wondering if there is a convenient function that can print a hash
> > table recursively into the elements.
>
> I think you are looking for:
>
> =A0 =A0perldoc Data::Dumper

If there are many keys in %hash, is there an option in Data::Dumper so
that only the first a few key value pairs are printed?


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

Date: Wed, 30 Dec 2009 13:10:24 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl  script?
Message-Id: <m28wck9vu7.fsf@shermpendley.com>

Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> On 2009-12-30, Sherm Pendley <spamtrap@shermpendley.com> wrote:
>> Peng Yu <pengyu.ut@gmail.com> writes:
>>
>>> Since my perl is installed in a nonstandard location, I have to use '/
>>> usr/bin/env perl'. I also what to use it with '-w'. I'm wondering how
>>> to do it.
>>
>> The "warnings" pragma is preferred over the -w switch now anyway:
>>
>>     use warnings;
>
> Wrong.  `use warning' is useful in a module.  It is mostly useless in
> a script.  One should always use -w in scripts.

You're entitled to your opinion, but it *is* an opinion - it's neither
right nor wrong, by definition.

sherm--


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

Date: Wed, 30 Dec 2009 21:09:03 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl  script?
Message-Id: <slrnhjngbf.u2i.nospam-abuse@powdermilk.math.berkeley.edu>

On 2009-12-30, Sherm Pendley <spamtrap@shermpendley.com> wrote:
>>> The "warnings" pragma is preferred over the -w switch now anyway:

>>>     use warnings;

>> Wrong.  `use warning' is useful in a module.  It is mostly useless in
>> a script.  One should always use -w in scripts.

> You're entitled to your opinion, but it *is* an opinion - it's neither
> right nor wrong, by definition.

And would not you like to share with us what was your point?

Ilya


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

Date: Wed, 30 Dec 2009 13:20:32 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <m24on89vdb.fsf@shermpendley.com>

"Dr.Ruud" <rvtol+usenet@xs4all.nl> writes:

> RedGrittyBrick wrote:
>> Ilya Zakharevich wrote:
>
>>> `use warning' is useful in a module.  It is mostly useless in
>>> a script.  One should always use -w in scripts.
>>
>> Can anyone provide a reference to where Ilya (or anyone else)
>> provides an explanation of this assertion?
>>
>> It doesn't seem to be in accord with `perldoc perllexwarn`. Am I
>> right to assume there is some disagreement on this point?
>
> I prefer -w in scripts too, because it enforces warnings on the
> included code.

And I prefer "use warnings" for the same reason - its scope is limited
to the code I'm actually working on, so I only have to see warnings
that are actually relevant to what I'm doing.

sherm--


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

Date: Wed, 30 Dec 2009 13:21:10 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <m2zl508grt.fsf@shermpendley.com>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

>>>>>> "Ruud" == Ruud  <rvtol+usenet@xs4all.nl> writes:
>
> Ruud> I prefer -w in scripts too, because it enforces warnings on the included
> Ruud> code.
>
> So you want to spend time debugging someone else's code? :)

I'd rather shave with a cheese grater. ;-)

sherm--


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

Date: Wed, 30 Dec 2009 21:04:14 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <slrnhjng2e.u2i.nospam-abuse@powdermilk.math.berkeley.edu>

On 2009-12-30, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Ruud" == Ruud  <rvtol+usenet@xs4all.nl> writes:
>
>Ruud> I prefer -w in scripts too, because it enforces warnings on the included
>Ruud> code.
>
> So you want to spend time debugging someone else's code? :)

First: as opposed to what?

Second: do not you choose to ignore the fact that a warning from
foreign code has a very good chance to be a consequence of ME "passing
wrong parameters" to that code code?

> I put "use warnings" on the code I write while I'm writing it.  I'm presuming
> the authors of other modules put use warnings on their code while they're
> writing it.
>
> Keep in mind that "use warnings" has value *only* while coding.

First: I do not see how this would favor `use warnings' over -w.  (See above.)

Second: I would not agree less.  Writing a good test suite increases
the developing time by what?  About 50%, maybe?

  [Some part of it goes into coding the test suite, some into
   debugging false positives from the test suite, and (probably most?)
   into debugging real problems; sigh...]

And writing a test suite which covers ALL the branches in the code
would, I presume, add another 1.5x slowdown to the code lifecycle.
(And, due to what follows, it still would not be bullet-proof.)  The
only recourse I see is to consider deployment as a part of development
cycle.

Third: we discuss the case when there is dependence on some 3rd
parties code.  The installed version of this code may be obsolete; it
may be also bleeding edge buggy.  I prefer to get some "stupidly
self-solving" bug reports (which point to problems in 3rd parties code)
to obscure bug reports forcing a remote debugging loop.

Hope this helps,
Ilya


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

Date: Wed, 30 Dec 2009 21:07:38 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <slrnhjng8q.u2i.nospam-abuse@powdermilk.math.berkeley.edu>

On 2009-12-30, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> And I think this is a good thing. Getting lots of warnings in code I
> haven't written and cannot change[1][2] is not very helpful. And most
> modules use "use warnings" anyway, so it's usually redundant (and you
> probably should be wary of those that don't use it).

??? Any module caring about backward compatibility would not `use warnings'.

> [1] Well, *I* can change it because I'm sysadmin on most of the systems
>     where my code runs. But that's far from universal.

But PERLLIB *is* universal.

> [2] I remember the bad old days of C programming where you could choose
>     between getting lots of warnings from system header files and turning
>     off many useful warnings.

This is not my experience with using -w.  At least not for a decade.

Yours,
Ilya


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

Date: Wed, 30 Dec 2009 21:13:53 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <slrnhjngkg.u2i.nospam-abuse@powdermilk.math.berkeley.edu>

On 2009-12-30, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>> The right solution is to add the "nonstandard" location to $PATH, so that 
>> env can find perl there.
>
> Using /usr/bin/env and relying on the PATH is not a good idea:
>
>  * Perl scripts are often called with a minimal PATH (cron jobs, CGI
>    scripts, etc.). Then the perl executable won't be found.
>  * The sysadmin may install a new perl executable in a directory which
>    appears earlier in the path - then the wrong executable will be
>    found.
>  * In some situations manipulation of the path may pose a security risk.
>
> In short, I think a script should be as self-contained as possible.
> Relying on the PATH often leads to trouble and can easily be avoided.

Cannot agree here.  Your arguments show that "it is has possible
drawbacks", not that it "is not a good idea".

There are VERY STRONG positive side to having a script in a form which
does not require you to explain to your grandmother how to exit vi... :-( :-)

Yours,
Ilya


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

Date: Wed, 30 Dec 2009 21:46:10 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <2aus07-fqq2.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2009-12-30, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> > And I think this is a good thing. Getting lots of warnings in code I
> > haven't written and cannot change[1][2] is not very helpful. And most
> > modules use "use warnings" anyway, so it's usually redundant (and you
> > probably should be wary of those that don't use it).
> 
> ??? Any module caring about backward compatibility would not `use warnings'.

I think you've lost that one. 5.005 is dead dead dead, as it should be.
Many (most?) people already consider 5.6 to be unsupportable.

> > [1] Well, *I* can change it because I'm sysadmin on most of the systems
> >     where my code runs. But that's far from universal.
> 
> But PERLLIB *is* universal.

But not easy to use correctly. That is, putting a directory in PERL5?LIB
is easy, but arranging for CPAN.pm to install them there and arranging
for modules in the system directories to *not* be loaded by accident
(except when you need them to be) is not entirely straightforward.

More importantly, messing around with third-party modules is a bad idea
unless you're planning to fork the distribution, which is a fairly major
step. None of the other modules you have installed will have been tested
against your patched version, and as soon as you upgrade you'll either
lose your changes or have a tricky merge on your hands.

> > [2] I remember the bad old days of C programming where you could choose
> >     between getting lots of warnings from system header files and turning
> >     off many useful warnings.
> 
> This is not my experience with using -w.  At least not for a decade.

This will be because most modules 'use warnings', and 'no warnings'
where they need to, which overrides -w.

Ben



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

Date: Wed, 30 Dec 2009 17:08:41 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <slrnhjmuoa.4kq.hjp-usenet2@hrunkner.hjp.at>

On 2009-12-30 08:44, Dirk Heinrichs <dirk.heinrichs@online.de> wrote:
> Ben Morrow wrote:
>> Quoth Tad McClellan <tadmc@seesig.invalid>:
>>> Wanna-Be Sys Admin <sysadmin@example.com> wrote:
>>> > Peng Yu wrote:
>>> >
>>> >> Since my perl is installed in a nonstandard location, I have to use '/
>>>          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> Please re-read the solution offered...
>
> The offered solution was simply wrong, so what Tad wrote is perfectly valid. 
> The right solution is to add the "nonstandard" location to $PATH, so that 
> env can find perl there.

Using /usr/bin/env and relying on the PATH is not a good idea:

 * Perl scripts are often called with a minimal PATH (cron jobs, CGI
   scripts, etc.). Then the perl executable won't be found.
 * The sysadmin may install a new perl executable in a directory which
   appears earlier in the path - then the wrong executable will be
   found.
 * In some situations manipulation of the path may pose a security risk.

In short, I think a script should be as self-contained as possible.
Relying on the PATH often leads to trouble and can easily be avoided.

	hp


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

Date: Wed, 30 Dec 2009 18:20:25 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to put '#!/usr/bin/env perl -w' at the beginning of a perl script?
Message-Id: <slrnhjn2uq.8j0.hjp-usenet2@hrunkner.hjp.at>

On 2009-12-30 15:26, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Ruud" == Ruud  <rvtol+usenet@xs4all.nl> writes:
>
>Ruud> I prefer -w in scripts too, because it enforces warnings on the included
>Ruud> code.
>
> So you want to spend time debugging someone else's code? :)
>
> I put "use warnings" on the code I write while I'm writing it.  I'm presuming
> the authors of other modules put use warnings on their code while they're
> writing it.
>
> Keep in mind that "use warnings" has value *only* while coding.  It has no
> practical value in production,

That assumes that coding and production are completely separate - that
at one poin in time coding is finished, the program is complete (and
bug-free) and then it will go into production and never be changed
again. 

This is - unfortunately - not the case for my code. Sometimes my code is
buggy, sometimes requirements change. Warnings in production code can be
a valuable tool in detecting those cases.

	hp



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

Date: Wed, 30 Dec 2009 14:52:43 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How to serialize a perl object in a .gz file
Message-Id: <e94ada65-9c88-4972-914d-404f39a81952@u41g2000yqe.googlegroups.com>

http://en.wikipedia.org/wiki/Serialization#Perl

The following example store the object in an unzipped file. I'm
wondering how to serialize a perl object in a .gz file.


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

Date: Tue, 29 Dec 2009 13:19:59 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: Simple loop error
Message-Id: <4b3a484f$2$fuzhry+tra$mr2ice@news.patriot.net>

In <hgvte5$ql0$1@reader1.panix.com>, on 12/24/2009
   at 02:21 PM, bks@panix.com (Bradley K. Sherman) said:

>Respond to what I wrote,

I did. You wrote, incorrectly, "So, in short, on your planet, in Perl,
'<=' does not test for equality, while here on Earth, it does." and that
is what I responded to.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Wed, 30 Dec 2009 12:54:00 -0800 (PST)
From: Nathan <nathanabu@gmail.com>
Subject: WWW::Scripter or Javascript and perl
Message-Id: <df7945fa-3211-4b7b-a1a0-eba4193ccbe8@d20g2000yqh.googlegroups.com>

I have a HTML, which has a button , which I suspect using JavaScript:
"
<p><input type="submit" id="submitButton" value="Submit" /></p></
form><script language="Javascript">runMeAndFinish();</script></body></
html>"

I tried to submit this form (click the submit button) which
WWW::Mechanize, but to no avail
$form->click_button( value => 'Submit');
didnt work, any other way didnt work as well, seems that maybe its
javascripted...
so , any idea how to use WWW::Scripter or any other way to click it??

thanks,


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

Date: Wed, 30 Dec 2009 21:39:49 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: WWW::Scripter or Javascript and perl
Message-Id: <5uts07-fqq2.ln1@osiris.mauzo.dyndns.org>


Quoth Nathan <nathanabu@gmail.com>:
> I have a HTML, which has a button , which I suspect using JavaScript:
> "
> <p><input type="submit" id="submitButton" value="Submit" /></p></
> form><script language="Javascript">runMeAndFinish();</script></body></
> html>"
> 
> I tried to submit this form (click the submit button) which
> WWW::Mechanize, but to no avail
> $form->click_button( value => 'Submit');
> didnt work, any other way didnt work as well, seems that maybe its
> javascripted...
> so , any idea how to use WWW::Scripter or any other way to click it??

Searching for WWW::Mechanize on search.cpan.org gives several helpful
results. I would probably start with W::M::Firefox, since WWW::Scripter
seems to be quite new. I have also used Selenium with success in the
past, though that's considerably harder to set up.

Otherwise: how are you trying to use WWW::Scripter, and how is it
failing for you?

Ben



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

Date: Wed, 30 Dec 2009 16:59:46 -0500
From: Steve C <smallpond@juno.com>
Subject: Re: WWW::Scripter or Javascript and perl
Message-Id: <hhgihh$81u$1@news.eternal-september.org>

Nathan wrote:
> I have a HTML, which has a button , which I suspect using JavaScript:
> "
> <p><input type="submit" id="submitButton" value="Submit" /></p></
> form><script language="Javascript">runMeAndFinish();</script></body></
> html>"
> 
> I tried to submit this form (click the submit button) which
> WWW::Mechanize, but to no avail
> $form->click_button( value => 'Submit');
> didnt work, any other way didnt work as well, seems that maybe its
> javascripted...
> so , any idea how to use WWW::Scripter or any other way to click it??
> 


So why not look at what the JS does?


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

Date: Wed, 30 Dec 2009 16:17:54 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: WWW::Scripter or Javascript and perl
Message-Id: <slrnhjnk68.7np.tadmc@tadbox.sbcglobal.net>

Steve C <smallpond@juno.com> wrote:
> Nathan wrote:
>> I have a HTML, which has a button , which I suspect using JavaScript:
>> "
>> <p><input type="submit" id="submitButton" value="Submit" /></p></
>> form><script language="Javascript">runMeAndFinish();</script></body></
>> html>"
>> 
>> I tried to submit this form (click the submit button) which
>> WWW::Mechanize, but to no avail
>> $form->click_button( value => 'Submit');
>> didnt work, any other way didnt work as well, seems that maybe its
>> javascripted...
>> so , any idea how to use WWW::Scripter or any other way to click it??
>> 
>
>
> So why not look at what the JS does?


Simply looking at the request that the JS builds ought to do it.

Hooking up the Web Scraping Proxy (wsp.pl) or similar will reveal
the request that is ultimately sent.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 2744
***************************************


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