[30673] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1918 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 12 18:09:39 2008

Date: Sun, 12 Oct 2008 15:09:06 -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           Sun, 12 Oct 2008     Volume: 11 Number: 1918

Today's topics:
    Re: FAQ 4.19 How do I validate input? sln@netherlands.com
    Re: FAQ 4.24 How do I reverse a string? <jurgenex@hotmail.com>
    Re: FAQ 4.24 How do I reverse a string? <brian.d.foy@gmail.com>
    Re: FAQ 4.24 How do I reverse a string? <jurgenex@hotmail.com>
    Re: FAQ 4.24 How do I reverse a string? sln@netherlands.com
    Re: FAQ 4.24 How do I reverse a string? <hansmu@xs4all.nl>
    Re: how to close STDIN <dontmewithme@got.it>
    Re: how to close STDIN <dontmewithme@got.it>
    Re: how to close STDIN <RedGrittyBrick@spamweary.invalid>
    Re: Inplace editing the elegant way sln@netherlands.com
    Re: Loading the shell environment? <someone@example.com>
    Re: Loading the shell environment? <No_4@dsl.pipex.com>
        new CPAN modules on Sun Oct 12 2008 (Randal Schwartz)
        Want true instantiated objects from XML <newsbot@cox.net>
    Re: Words to numbers <huxiankui@gmail.com>
    Re: Words to numbers sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 12 Oct 2008 21:39:17 GMT
From: sln@netherlands.com
Subject: Re: FAQ 4.19 How do I validate input?
Message-Id: <fgr4f4p4h96c33pl8vdagdl5quo0cmkfca@4ax.com>

On Sun, 12 Oct 2008 12:03:01 -0700, PerlFAQ Server <brian@stonehenge.com> wrote:

>This is an excerpt from the latest version perlfaq4.pod, which
>comes with the standard Perl distribution. These postings aim to 
>reduce the number of repeated questions as well as allow the community
>to review and update the answers. The latest version of the complete
>perlfaq is at http://faq.perl.org .
>
>--------------------------------------------------------------------
>
>4.19: How do I validate input?
>
>    (contributed by brian d foy)
>
>    There are many ways to ensure that values are what you expect or want to
>    accept. Besides the specific examples that we cover in the perlfaq, you
>    can also look at the modules with "Assert" and "Validate" in their
>    names, along with other modules such as "Regexp::Common".
>
>    Some modules have validation for particular types of input, such as
>    "Business::ISBN", "Business::CreditCard", "Email::Valid", and
>    "Data::Validate::IP".
>
>
>
>--------------------------------------------------------------------
>
>The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
>are not necessarily experts in every domain where Perl might show up,
>so please include as much information as possible and relevant in any
>corrections. The perlfaq-workers also don't have access to every
>operating system or platform, so please include relevant details for
>corrections to examples that do not work on particular platforms.
>Working code is greatly appreciated.
>
>If you'd like to help maintain the perlfaq, see the details in 
>perlfaq.pod.

Oh come on. ASSERT and validate? I can just imagine the overhead
via Perl these would take in an effort to more and more, make it look
and feel like C/C++. This makes me sick...

sln



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

Date: Sat, 11 Oct 2008 20:34:06 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <3mr2f4lntvp0dea05o434fudvjfi7vlqbp@4ax.com>

PerlFAQ Server <brian@stonehenge.com> wrote:
>4.24: How do I reverse a string?
>
>    Use "reverse()" in scalar context, as documented in "reverse" in
>    perlfunc.
>
>            $reversed = reverse $string;


Duuuh, isn't that rather obvious?

Honestly, this may be an SAQ, but IMNSHO it doesn't qualify as
frequently asked. And it is so trivial, I really don't see the point in
repeating the man page in the FAQ. We don't have an entry for "How do I
push an element onto an array?", either.

Therefore I suggest removing it.

jue


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

Date: Sun, 12 Oct 2008 09:58:43 -0400
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <121020080958437953%brian.d.foy@gmail.com>

In article <3mr2f4lntvp0dea05o434fudvjfi7vlqbp@4ax.com>, Jürgen Exner
<jurgenex@hotmail.com> wrote:

> PerlFAQ Server <brian@stonehenge.com> wrote:
> >4.24: How do I reverse a string?
> >
> >    Use "reverse()" in scalar context, as documented in "reverse" in
> >    perlfunc.
> >
> >            $reversed = reverse $string;
> 
> 
> Duuuh, isn't that rather obvious?

It's not been obvious to most people I teach. Most people only see it
as a list operator.

> Therefore I suggest removing it.

It's not hurting anyone where it is.


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

Date: Sun, 12 Oct 2008 09:00:13 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <7h74f4teoeieua93lafknmpsdd1sr1rb0l@4ax.com>

brian d  foy <brian.d.foy@gmail.com> wrote:
><jurgenex@hotmail.com> wrote:
>> PerlFAQ Server <brian@stonehenge.com> wrote:
>> >4.24: How do I reverse a string?
>> >    Use "reverse()" in scalar context, as documented in "reverse" in
>> >    perlfunc.
>> >
>> >            $reversed = reverse $string;
>> 
>> Duuuh, isn't that rather obvious?
>
>It's not been obvious to most people I teach. Most people only see it
>as a list operator.
>
>> Therefore I suggest removing it.
>
>It's not hurting anyone where it is.

It is cluttering the FAQ, therefore I suggested removing it /if/ it
doesn't provide any useful information. However apparently there are
indeed people to whom it is useful. 

Do others share Brian's experience/sentiment?

jue 


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

Date: Sun, 12 Oct 2008 18:18:57 GMT
From: sln@netherlands.com
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <sbf4f4h3shti71h7jd5l0jdja6pnqa8qav@4ax.com>

On Sun, 12 Oct 2008 09:58:43 -0400, brian d  foy <brian.d.foy@gmail.com> wrote:

>In article <3mr2f4lntvp0dea05o434fudvjfi7vlqbp@4ax.com>, Jürgen Exner
><jurgenex@hotmail.com> wrote:
>
>> PerlFAQ Server <brian@stonehenge.com> wrote:
>> >4.24: How do I reverse a string?
>> >
>> >    Use "reverse()" in scalar context, as documented in "reverse" in
>> >    perlfunc.
>> >
>> >            $reversed = reverse $string;
>> 
>> 
>> Duuuh, isn't that rather obvious?
>
>It's not been obvious to most people I teach. Most people only see it
>as a list operator.
>
>> Therefore I suggest removing it.
>
>It's not hurting anyone where it is.

I still find it disturbing strings can't be manipulated directly.
I bet there's alot of pressure to make that ability available.
When you need to do it, you just need to.

The fact is, this turn's off C programmers instead of attracting them.
Let me tell you right now, C programers don't use "substr()" in C, they
just don't. Perl's string manipulation functions are useless.

Just my opinion of course.

sln



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

Date: Sun, 12 Oct 2008 20:25:52 +0200
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: FAQ 4.24 How do I reverse a string?
Message-Id: <48f241ea$0$192$e4fe514c@news.xs4all.nl>

Jürgen Exner wrote:
> brian d  foy <brian.d.foy@gmail.com> wrote:
>> <jurgenex@hotmail.com> wrote:
>>> PerlFAQ Server <brian@stonehenge.com> wrote:
>>>> 4.24: How do I reverse a string?
>>>>    Use "reverse()" in scalar context, as documented in "reverse" in
>>>>    perlfunc.
>>>>
>>>>            $reversed = reverse $string;
>>> Duuuh, isn't that rather obvious?
>> It's not been obvious to most people I teach. Most people only see it
>> as a list operator.
>>
>>> Therefore I suggest removing it.
>> It's not hurting anyone where it is.
> 
> It is cluttering the FAQ, therefore I suggested removing it /if/ it
> doesn't provide any useful information. However apparently there are
> indeed people to whom it is useful. 
> 
> Do others share Brian's experience/sentiment?

I seem to remember this question was asked frequently
before it was added to the FAQ.

So I agree with Brian.

-- HansM



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

Date: Sun, 12 Oct 2008 11:56:22 +0200
From: Larry <dontmewithme@got.it>
Subject: Re: how to close STDIN
Message-Id: <dontmewithme-BE7230.11562212102008@news.tin.it>

In article <r5m7s5-ttb1.ln1@osiris.mauzo.dyndns.org>,
 Ben Morrow <ben@morrow.me.uk> wrote:

> Presumably the httpd child
> is receiving all the uploaded data and just throwing it away, and once
> it's finished it'll perform the wait(2).

hopefully. Do you think that may affect/screw up my web server? I mean 
the httpd child throwing the data away...


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

Date: Sun, 12 Oct 2008 14:57:15 +0200
From: Larry <dontmewithme@got.it>
Subject: Re: how to close STDIN
Message-Id: <dontmewithme-4E540A.14571512102008@news.tin.it>

In article <slrngf1mrd.6fv.hjp-usenet2@hrunkner.hjp.at>,
 "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:

> You can't send it to the script, since the script is already dead.

ok, so back to my question...is ok to close STDIN and exit in order to 
stop my script if a user fails to auth?

thanks


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

Date: Sun, 12 Oct 2008 14:19:20 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: how to close STDIN
Message-Id: <gcstgv$jnp$1@registered.motzarella.org>


Larry wrote:
> In article <r5m7s5-ttb1.ln1@osiris.mauzo.dyndns.org>,
>  Ben Morrow <ben@morrow.me.uk> wrote:
> 
>> Presumably the httpd child
>> is receiving all the uploaded data and just throwing it away, and once
>> it's finished it'll perform the wait(2).
> 
> hopefully. Do you think that may affect/screw up my web server? I mean 
> the httpd child throwing the data away...

No, it may waste resources though.

If you need to authenticate uploaders you might find it better to use 
the web-server's authentication and authorisation mechanisms (e.g. see 
Apache's .htaccess). That ought to prevent the situation you describe.


-- 
RGB


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

Date: Sun, 12 Oct 2008 18:06:40 GMT
From: sln@netherlands.com
Subject: Re: Inplace editing the elegant way
Message-Id: <gke4f4t822fk7ft7usmjf9gfkek2uaas2b@4ax.com>

On Thu, 9 Oct 2008 07:16:54 -0700 (PDT), jrpfinch <jrpfinch@gmail.com> wrote:

>I would like to develop a script that can inplace edit a large file
>(potentially 1Gb), omitting some lines according to a regex and
>replacing some lines according to another regex.  Here is an example
>of a script that does this with a couple of hardcoded patterns:
>
>{
>   local ($^I, @ARGV) = ('', ($full_path_to_config_file));
>   while (<>)
>   {
>      s/this/that/;
>      s/foo/bar/;
>      print unless ((/delete me/) or (/Delete Me Too/));
>   }
>}
>
>What is the best way to scale this for n patterns?  When I say best, I
>mean a good balance of speed and readability.  Can I put all the
>omission patterns in an array and all the search/replace patterns in
>another array and somehow wedge them into the example above?
>
>Any help appreciated.
>
>Jon

This is fine for simple line based parsing.
How would you handle replacements that span lines?

sln



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

Date: Sat, 11 Oct 2008 21:03:46 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Loading the shell environment?
Message-Id: <yGeIk.7942$T81.3373@newsfe10.iad>

Joe Smith wrote:
> T wrote:
> 
>> eval `/cae/Modules/${MODULE_VERSION}/bin/modulecmd bash load
>> myproject`
>>
>> and this works, I tried the equivlant in perl:
>>
>> eval `/cae/Modules/$ENV{'MODULE_VERSION'}/bin/modulecmd tcsh load
>> myproject`
>>
>> Does anyone know how to load the shell environment
>> in a Perl script? This script will run in crontab 
> 
> In bash, the syntax is something like:
> 
>    PATH=$PATH:/usr/local/bin:$HOME/bin
> 
> In perl, the equivalent would be:
> 
>    $ENV{PATH} = "$ENV{PATH}:/usr/local/bin:$ENV{HOME}/bin";
> or
>    $ENV{PATH} .= ":/usr/local/bin:$ENV{HOME}/bin";

Or:

      use Env qw/@PATH $HOME/;
      push @PATH, '/usr/local/bin', "$HOME/bin";



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Sun, 12 Oct 2008 12:48:01 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Loading the shell environment?
Message-Id: <5JqdnWSIOJNvfmzVnZ2dnUVZ8qrinZ2d@pipex.net>

> T wrote:
> 
> Does anyone know how to load the shell environment
> in a Perl script? This script will run in crontab 

It's a shell environment.  It's meant for loading into a shell.  So load 
it into a shell.

Write a simple script to load the env and then exec perl.

e.g:

==========
#!/bin/sh
#
mod load myproject
exec perl-command

==========

or a more generic one, where you give the real command as the parameters

==========
#!/bin/sh
#
mod load myproject
exec ${1+"$@"}
==========


-- 
              Just because I've written it doesn't mean that
                   either you or I have to believe it.


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

Date: Sun, 12 Oct 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Oct 12 2008
Message-Id: <K8LzqL.1IFz@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

App-ZofCMS-0.0105
http://search.cpan.org/~zoffix/App-ZofCMS-0.0105/
web framework and templating system for small-medium sites. 
----
DB-CouchDB-Schema-0.3.02
http://search.cpan.org/~zaphar/DB-CouchDB-Schema-0.3.02/
A Schema driven CouchDB module 
----
Device-USB-0.25
http://search.cpan.org/~gwadej/Device-USB-0.25/
Use libusb to access USB devices. 
----
Finance-Quote-1.13_02
http://search.cpan.org/~ecocode/Finance-Quote-1.13_02/
Get stock and mutual fund quotes from various exchanges 
----
Foorum-0.2.9
http://search.cpan.org/~fayland/Foorum-0.2.9/
forum system based on Catalyst 
----
HTML-ExtractContent-0.02
http://search.cpan.org/~tarao/HTML-ExtractContent-0.02/
An HTML content extractor with scoring heuristics 
----
HTML-ExtractContent-0.03
http://search.cpan.org/~tarao/HTML-ExtractContent-0.03/
An HTML content extractor with scoring heuristics 
----
KiokuDB-0.01_01
http://search.cpan.org/~nuffin/KiokuDB-0.01_01/
Object Graph storage engine 
----
KiokuDB-Backend-BDB-0.01
http://search.cpan.org/~nuffin/KiokuDB-Backend-BDB-0.01/
----
MIME-Structure-0.07
http://search.cpan.org/~nkuitse/MIME-Structure-0.07/
determine structure of MIME messages 
----
MooseX-Method-Signatures-0.05
http://search.cpan.org/~flora/MooseX-Method-Signatures-0.05/
Method declarations with type constraints and no source filter 
----
Net-FTP-Simple-0.0007
http://search.cpan.org/~wilco/Net-FTP-Simple-0.0007/
Simplified interface to a few common FTP tasks with Net::FTP. 
----
Perl-Dist-1.05_01
http://search.cpan.org/~adamk/Perl-Dist-1.05_01/
Perl Distribution Creation Toolkit 
----
Perl-Dist-1.05_02
http://search.cpan.org/~adamk/Perl-Dist-1.05_02/
Perl Distribution Creation Toolkit 
----
Perl-Dist-WiX-0.01_01
http://search.cpan.org/~adamk/Perl-Dist-WiX-0.01_01/
Experimental 4th generation Win32 Perl distribution builder 
----
SQL-DB-0.16
http://search.cpan.org/~mlawren/SQL-DB-0.16/
Perl interface to SQL Databases 
----
Search-GIN-0.01
http://search.cpan.org/~nuffin/Search-GIN-0.01/
----
Search-GIN-0.02
http://search.cpan.org/~nuffin/Search-GIN-0.02/
Generalized Inverted Indexing 
----
Template-Plugin-Handy-0.001
http://search.cpan.org/~karman/Template-Plugin-Handy-0.001/
handy vmethods for Template Toolkit 
----
Tk-Mirror-0.04
http://search.cpan.org/~knorr/Tk-Mirror-0.04/
Perl extension for a graphic user interface to up- or download local and remote directories 
----
Variable-Magic-0.23
http://search.cpan.org/~vpit/Variable-Magic-0.23/
Associate user-defined magic to variables from Perl. 
----
WWW-CDTV-0.03
http://search.cpan.org/~yusukebe/WWW-CDTV-0.03/
Get a weekly music ranking from CDTV ( Japanese TV Program ) 
----
WWW-Contact-0.02
http://search.cpan.org/~fayland/WWW-Contact-0.02/
Get contacts/addressbook from Web 
----
WWW-Google-Time-0.0101
http://search.cpan.org/~zoffix/WWW-Google-Time-0.0101/
get time for various locations via Google 
----
WWW-Mechanize-Plugin-AutoWrite-0.05
http://search.cpan.org/~potyl/WWW-Mechanize-Plugin-AutoWrite-0.05/
WWW::Mechanize plugin that writes the fetched pages to the disk. 
----
indirect-0.06
http://search.cpan.org/~vpit/indirect-0.06/
Lexically warn about using the indirect object syntax. 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Sun, 12 Oct 2008 14:01:14 -0700 (PDT)
From: "/usr/ceo" <newsbot@cox.net>
Subject: Want true instantiated objects from XML
Message-Id: <80797930-8c8d-4658-81e7-56b9b11d135d@8g2000hse.googlegroups.com>

I've had a need for this at points in the past, but was always able to
code around it (and still could even now), but I'd really like to be
able to do this, and I can't find anything out there that does this
exactly as I want.  (Which tends to make me believe what I want
wouldn't be as immediately useful as maybe I would think it to be,
but...?!)

Given an object defined as this:

package Person;

use strict;
use warnings qw( all );

sub new {
   my $proto = shift;
   my $class = ref $proto || $proto;
   my %attrs = @_;
   my $self = {};

   # Nevermind the error checking for attributes right now.

   $self->{__name} = $attrs{name};
   $self->{__age} = $attrs{age};

   bless $class, $self;

   return $self;
}

# RW attributes.

sub name { $s = shift; $s->{__name} = shift if @_; return $s-
>{__name} }
sub age { $s = shift; $s->{__age} = shift if @_; return $s->{__age} }

# Methods.

sub sayName { print "My name is: " . shift->{__name} . "\n" }
sub sayAge { print "I am " . shift->{__age} . " years old.\n" }

1;

I want to be able to read the following XML and create instances of
Person from each instance in the XML:

<xml>
<People>
   <Person name="John Doe" age="22" />
   <Person name="Jane Doe" age="23" />
   <Person name="Maxx Doogan" age="10" />
</People>
</xml>

So I get an array of Person objects which I can then write:

my @people; # Hold the array of Person object created from the XML
above.

for my $person (@people) {
   $person->sayName();
   $person->sayAge();
}

I've looked through SOAP::Lite (and SOAP::Serialize and
SOAP::Deserialize).  I'm a fairly frequent user of XML::Simple, but
Simple doesn't do the above (AFAIK).  SURELY *something* like this is
"out there" (read "CPAN") but I can't seem to find it; only things
close to it (like SOAP::SOM objects that require an xpath of sorts and
my methods are still not available through an instantiated method of
just the data [object attributes] in XML.)

Thanks!
/usr/ceo


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

Date: Sun, 12 Oct 2008 09:51:57 -0700 (PDT)
From: william <huxiankui@gmail.com>
Subject: Re: Words to numbers
Message-Id: <74661095-8442-452a-9fe3-d822b17b2a86@u28g2000hsc.googlegroups.com>

Thank you all for the suggestions. Nevertheless, I've accomplished the
number extraction with Perl script. I first build a library of
possible misspellings and convert them to correct ones. Then I use
perl to do a certain pattern search and convert the english numbers to
arabic numbers. Finally I can extract the numbers using kind of fuzzy
logic. As to the -9, because only positive numbers are needed in my
research design. So I use -9 to indicate all non-positive numbers or
cannot find the appropriate number.

Using perl to do natural language processing is really very
interesting. Thank you all again for you inputs.

William


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

Date: Sun, 12 Oct 2008 19:15:14 GMT
From: sln@netherlands.com
Subject: Re: Words to numbers
Message-Id: <h5j4f49bsvmgk3ogtunfaqgciiigs0d47e@4ax.com>

On Sun, 12 Oct 2008 09:51:57 -0700 (PDT), william <huxiankui@gmail.com> wrote:

>Thank you all for the suggestions. Nevertheless, I've accomplished the
>number extraction with Perl script. I first build a library of
>possible misspellings and convert them to correct ones. Then I use
>perl to do a certain pattern search and convert the english numbers to
>arabic numbers. Finally I can extract the numbers using kind of fuzzy
>logic. As to the -9, because only positive numbers are needed in my
>research design. So I use -9 to indicate all non-positive numbers or
>cannot find the appropriate number.
>
>Using perl to do natural language processing is really very
>interesting. Thank you all again for you inputs.
>
>William

-9-1-1



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

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 V11 Issue 1918
***************************************


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