[24495] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6675 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 10 11:05:51 2004

Date: Thu, 10 Jun 2004 08:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 10 Jun 2004     Volume: 10 Number: 6675

Today's topics:
    Re: change de current working directory of my session.. <nobull@mail.com>
    Re: Contructing a dir. tree (JR)
    Re: Contructing a dir. tree <uri@stemsystems.com>
    Re: Counting elements in a hash <nobull@mail.com>
    Re: Counting elements in a hash russell.brooks@perdue.com
        domain user <louisccc@hotmail.com>
    Re: Exit status from 'die' <bernie@rev.net>
    Re: Exit status from 'die' <bernie@rev.net>
    Re: Help me with threads issue ! <vetro@online.no>
    Re: Help me with threads issue ! <usenet@morrow.me.uk>
    Re: Help me with threads issue ! <vetro@online.no>
    Re: Help me with threads issue ! <usenet@morrow.me.uk>
    Re: Help me with threads issue ! ctcgag@hotmail.com
    Re: Invisible Array Loop Counter? <usenet@morrow.me.uk>
    Re: match aaa but not 123aaa <tadmc@augustmail.com>
    Re: Object oriented form parsing <1usa@llenroc.ude>
    Re: Object oriented form parsing <dwall@fastmail.fm>
        parsing file through an array (Andrea Spitaleri)
    Re: parsing file through an array (Anno Siegel)
    Re: parsing file through an array <usenet@morrow.me.uk>
    Re: parsing file through an array <jgibson@mail.arc.nasa.gov>
        startting perl (Sree)
    Re: startting perl <andre.wisniewski@gmx.de>
    Re: startting perl <ittyspam@yahoo.com>
    Re: startting perl <raisin@delete-this-trash.mts.net>
    Re: Variable hash names? <dkoleary@olearycomputers.com>
    Re: Variable hash names? <dkoleary@olearycomputers.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Jun 2004 12:28:34 +0100
From: Brian McCauley <nobull@mail.com>
To: david_cantin@hotmail.com
Subject: Re: change de current working directory of my session...
Message-Id: <u9k6yfejod.fsf@wcl-l.bham.ac.uk>

david_cantin@hotmail.com writes exactly the same thing three times:

> Is it possible to run a perl script that change my current "session"
> working dir?

I think you may have misunderstood the concept of "Frequently Asked
Question".  When a question is listed in the FAQ this means that
people exepcted to encounter that question frequently.  It does not
mean that when you encounter the question you should ask it multiple
times.

(BTW this is really a Unix FAQ but it is asked so often in a Perl
context that it's listed in the Perl FAQ too).

HTH :-)

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


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

Date: 10 Jun 2004 07:47:00 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Contructing a dir. tree
Message-Id: <b386d54b.0406100647.74eae891@posting.google.com>

Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040609153546.J8971@dishwasher.cs.rpi.edu>...
> On Wed, 9 Jun 2004, JR wrote:
> 
> > I'm not 100% sure I understand what you want, but try:
> >
> > #!/usr/local/bin/perl
> > use strict;
> 
> use warnings;
> 
> > my $directory  = 'foo/bar1/bar2/bar3/XYZ.txt';
> > my @arr        = split /\//, $directory;
>  
> > my @out        = ();
> 
> Why are you declaring a variable you never use?

You're right-it is unneccesary.  God help us.  I was originally going
to use an array, the way the o/p did, but instead decided to use a
scalar.

> 
> > my $info       = undef;
> 
> That's a completely worthless initialization.
> my $info;
> does the same thing.

I know it does.  It doesn't hurt anything either, to set it to undef;
in fact, it makes is completely clear to even the novice programmer
that it is, in fact, undefined.

> 
> > my $count      = 0;
> 
> That's an almost-completely worthless initialization
> my $count;

I know dude.  The reason I set it to zero is for the same reason I set
$info to undef.  Christ!

> will have the same effect sine all you're ever doing to count is
> incrementing it.  (An undef value increments to 1 without so much as a
> warning).
> 
> > $info = qq|Parent Folder: $_\n{\n   Some text here about "$arr[0]"\n|;
> > $info .= qq|   Child Folder: bar1\n|;
> > $info .= qq|   {\n|;
> >
> > my $indent = 6;
> > $info .= qq|\nFile element: Some text about "$arr[$#arr]"\n|;
> > $info .= "=" x 39, "\n";
> > print $info;
> 
> I'm not at all clear as to why you're building up this (potentially huge)

Potentially huge?  I wonder just how huge a directory path is likely
to be. Hmm, now I'm nitpicking just the way you have been.  Sorry
about that.

> scalar to be printed only once at the end.  Why are you not just printing
> each line of text as it comes?  Can you explain what benefit is to be
> gained by storing all this text in memory before printing?
> 
> Paul Lalli

The o/p used an array to capture the information; I used a scalar. 
Perhaps he needs to use the scalar or array, whichever, later in the
program.  I realize he could just print the thing, instead of storing
it and then printing it!  I'm just throwing out a script to the o/p
that he can either use or not, one that resebmles to some degree his
original script.

Rather than lambaste my script, why don't you show us what you have,
in the way of a solution?  That would be a far more useful way for you
to spend your time.  You are clearly a vastly superior programmer, so
put your talents to use.


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

Date: Thu, 10 Jun 2004 15:04:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Contructing a dir. tree
Message-Id: <x7vfhzbgjp.fsf@mail.sysarch.com>

>>>>> "JR" ==   <jrolandumuc@yahoo.com> writes:

  >> > my $info       = undef;
  >> 
  >> That's a completely worthless initialization.
  >> my $info;
  >> does the same thing.

  JR> I know it does.  It doesn't hurt anything either, to set it to undef;
  JR> in fact, it makes is completely clear to even the novice programmer
  JR> that it is, in fact, undefined.

you don't code for newbies, you code for regular programmers. if we all
coded for newbies, it would be an ugly world.

  >> > my $count      = 0;
  >> 
  >> That's an almost-completely worthless initialization
  >> my $count;

  JR> I know dude.  The reason I set it to zero is for the same reason I set
  JR> $info to undef.  Christ!

$DEITY!! don't you get it? redundant code like that initialization is
bad. as in why do it as you gain nothing from it? do you realize how
many places perl does things like that and if you explicitly coded them,
i shudder to think how bad the code would be.

  JR> Rather than lambaste my script, why don't you show us what you
  JR> have, in the way of a solution?  That would be a far more useful
  JR> way for you to spend your time.  You are clearly a vastly superior
  JR> programmer, so put your talents to use.

he did put his talents to use in trying to educate you. why don't you
try to put your talents to use by learning from him how to improve your
code.

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: 10 Jun 2004 12:28:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Counting elements in a hash
Message-Id: <u9n03bejpb.fsf@wcl-l.bham.ac.uk>

"Christian Winter" <thepoet_nospam@arcor.de> writes:

> my $count;
> $count += scalar @{$table{$_}} for(keys %table);

Or, more simply:

my $count = 0; # Want 0 not undef if %table empty
$count += @$_ for values %table;

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


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

Date: 10 Jun 2004 06:40:36 -0700
From: russell.brooks@perdue.com
Subject: Re: Counting elements in a hash
Message-Id: <43f48366.0406100540.a7e4100@posting.google.com>

Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040609154553.G8971@dishwasher.cs.rpi.edu>...
> On Wed, 9 Jun 2004 russell.brooks@perdue.com wrote:
> 
> > Hi,
> >   I've created a hash of an array.  There are a varying number of
> > elements in the arrays.  I need to count the number of elements, and
> > although I have read through the documentation, I have been unable to
> > find a clean way of doing this.
> >   For example,
> >
> > $table{28}[0] = 541;
> > $table{36}[0] = 1024;
> > $table{36}[1] = 2048;
> > $table{36}[2] = 4096;
> > $table{36}[3] = 8192;
> > $table{51}[0] = 77;
> >
> > What I'm trying to obtain is a count of values for each array in the
> > hash.  For example, the above example has 4 values associated with
> > array 36.
> >
> > scalar keys %table gives 3, which isn't what I need.
> > scalar keys $tables{28} is illegal since the arguments for keys must
> > be a hash, not a hash element.
> >
> > Is iterating through the hash the best option?
> 
> You've made this more complicated than it is.  $table{36} is an array
> reference.  You want to find the number of elements in the array
> referenced by $table{36}, correct?
> 
> $size = @{$table{36}};
> 
> The @{ } syntax dereferences the given array reference.  The assignment to
> a scalar evaluates the resulting array in a scalar context, which results
> in the size of that array.
> 
> Paul Lalli

Thanks for the response.  As you said, I was making it too complicated.

Russ


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

Date: Thu, 10 Jun 2004 16:13:36 +0200
From: "louis" <louisccc@hotmail.com>
Subject: domain user
Message-Id: <40c86e2a$0$8993$6c56d894@feed0.news.be.easynet.net>

Hi,

I've created an application in Perl but I have to build some security in it.
The application runs on a Linux-server with apache as web-server. The
Linux-server operates in an NT4-domain. The application is only vailable for
internal use (not on internet).
When the user starts his PC, he has to log on to the domain to get the
normal netwerk-facilities (mail, netwerkacces, ...)
Is there a way I can get this username (domain-user) to check who is asking
a web-page (executing of a perl script on the server). so I don't have to
ask the user a second time for a username and password and I create a single
sign-on.

            thanks

            Louis




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

Date: Thu, 10 Jun 2004 07:25:45 -0400
From: Bernard Cosell <bernie@rev.net>
Subject: Re: Exit status from 'die'
Message-Id: <g0hgc0l4nvl1cfsuae09sac7r18kd1312v@4ax.com>

On Wed, 9 Jun 2004 19:01:51 +0000 (UTC), Ben Morrow
<usenet@morrow.me.uk> wrote:

>
>Quoth Bernard Cosell <bernie@rev.net>:
>> I'm trying to use a __DIE__ handler to manage the 'departure' of my
>> program and I've noticed a bit of an oddity I'm not sure about to try
>> to get the exit status to be correct.
>> 
>> Given this scrap of code:
>> 
>> sub Report
>> {  print $_[0];
>>    exit $! ;
>
>What made you think $! contains the exit status? Try $?.

From perldoc -f die:

 die LIST
               Outside an "eval", prints the value of LIST to
               "STDERR" and exits with the current value of "$!"

So I assumed that since I caught a 'die' signal, that $! would be the
exit status that 'die' is about to give back to the OS.  Is that
incorrect??

BTW, I did get it to work.  The following little routine appears to be
a "die proxy":

  sub mydie
  {   my $exitstatus = ($! || -1) ;
      [do *MY* 'die processing']
      exit $exitstatus ;
  }

In the tests I ran, that routine gave me the identical results for
die/mydie.  Not perfectly intuitive but it seems to work..:o)

  /Bernie\


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

Date: Thu, 10 Jun 2004 09:11:16 -0400
From: Bernard Cosell <bernie@rev.net>
Subject: Re: Exit status from 'die'
Message-Id: <39ngc0ts3s6844l653t1t9hvthabqadg82@4ax.com>

On Thu, 10 Jun 2004 07:25:45 -0400, Bernard Cosell <bernie@rev.net>
wrote:

>On Wed, 9 Jun 2004 19:01:51 +0000 (UTC), Ben Morrow
><usenet@morrow.me.uk> wrote:

>>What made you think $! contains the exit status? Try $?.
>
>From perldoc -f die:
>
> die LIST
>               Outside an "eval", prints the value of LIST to
>               "STDERR" and exits with the current value of "$!"
>
>So I assumed that since I caught a 'die' signal, that $! would be the
>exit status that 'die' is about to give back to the OS.  Is that
>incorrect??

As I read the perldoc more carefully see that my routine:

>  sub mydie
>  {   my $exitstatus = ($! || -1) ;
>      [do *MY* 'die processing']
>      exit $exitstatus ;
>  }

Earns me a "close but no cigar" award, I think.  The discussion of
'die' goes on to say:

                .... If "$!" is "0", exits with the value of
               "($? >> 8)" (backtick `command` status).  If "($?
               >> 8)" is "0", exits with "255".

so I really need something like:
    my $exitstatus = ($! || ($? >> 8) || 255);

/Bernie\



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

Date: Thu, 10 Jun 2004 13:33:44 +0200
From: "Vetle Roeim" <vetro@online.no>
Subject: Re: Help me with threads issue !
Message-Id: <opr9dmeinh3hk3cf@quickfix.opera.com>

On Thu, 10 Jun 2004 08:41:58 +0000 (UTC), Ben Morrow <usenet@morrow.me.uk>  
wrote:

>     I've searched on google (including groups.google.com) for information
>>    on threading in Perl, and I'm under the impression that it has  
>>    improved alot lately.
>
> Perl ithreads now effectively perform a fork in userland, without using
> copy-on-write. This has removed the problems with 5005threads, sure, but
> it has also removed any point in using threads on an OS which can fork.
> The OS will *always* be able to do it faster.

   I discovered something interesting when testing forks.pm. Parts of my
   code totally unrelated to the part where I use a thread pool were
   significantly slower /with/ forks, than without!

   My code parses some stuff and enters into a database (DBI, MySQL).
   I timed the different parts of the code, and here are the results:

     forks:
       100 trials of parse (96.031ms total), 960us/trial
       100 trials of db (7.906s total), 79.061ms/trial

     threads:
       100 trials of parse (92.693ms total), 926us/trial
       100 trials of db (70.068ms total), 700us/trial

   Interesting, indeed.

-- 
Touch eyeballs to screen for cheap laser surgery!


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

Date: Thu, 10 Jun 2004 12:04:38 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Help me with threads issue !
Message-Id: <ca9iom$d3f$1@wisteria.csv.warwick.ac.uk>


Quoth "Vetle Roeim" <vetro@online.no>:
> On Thu, 10 Jun 2004 08:41:58 +0000 (UTC), Ben Morrow <usenet@morrow.me.uk>  
> wrote:
> 
> > I have to say I've never used forks; but did you use forks::shared as
> > well as forks? I would be inclined *not* to use forks myself, but
> > implement some other IPC mechanism as needed.
> 
>    Doh! I forgot about that one ... It worked perfectly when I included
>    forks::shared. :)
> 
>    Btw; if I read the POD for forks correctly, then this shouldn't work
>    (see the TODO section). Um... ?

Yeah, well... documentation is notoriously out-of-date wrt code,
especially TODO lists ;)

> > Perl ithreads now effectively perform a fork in userland, without using
> > copy-on-write. This has removed the problems with 5005threads, sure, but
> > it has also removed any point in using threads on an OS which can fork.
> > The OS will *always* be able to do it faster.
> 
>    I'm going to try to create some kind of thread/process pool, so the speed
>    of creating new threads/processes will hopefully not be much of an issue.
> 
>    I'll experiment a little bit with/without forks and see how things work
>    out. :)

I will say again:

On an OS with fork, don't use threads and don't use forks. Use fork
directly, or through something like Parallel::ForkManager. Do IPC
yourself via traditional mechanisms: pipes, sockets, SysV shared mem,
mmap.

ithreads are a useful alternative to fork on platforms that don't have
it. forks is a useful implementation of the threads API in terms of
forking and sockets, for programs that need to be portable to both
has-fork and has-ithreads. It doesn't sound to me like you need to be
bound by either of those, so don't be.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Thu, 10 Jun 2004 14:15:36 +0200
From: "Vetle Roeim" <vetro@online.no>
Subject: Re: Help me with threads issue !
Message-Id: <opr9docato3hk3cf@quickfix.opera.com>

On Thu, 10 Jun 2004 12:04:38 +0000 (UTC), Ben Morrow <usenet@morrow.me.uk>  
wrote:

[...]
>>    I'll experiment a little bit with/without forks and see how things  
>>    work out. :)
>
> I will say again:
>
> On an OS with fork, don't use threads and don't use forks.

   Aha.

> Use fork
> directly, or through something like Parallel::ForkManager. Do IPC
> yourself via traditional mechanisms: pipes, sockets, SysV shared mem,
> mmap.

   Well... ithreads fits very nicely into my solution. It didn't take
   me long to create my own working thread pool, where I send data to
   the different threads using Thread::Queue.

   I apologize if I seem slow, but what is wrong with ithreads? As far
   as I know they are slower to start than forking, and they're memory
   hungry, but other than that; are there any other problems I should be
   aware of?


> ithreads are a useful alternative to fork on platforms that don't have
> it. forks is a useful implementation of the threads API in terms of
> forking and sockets, for programs that need to be portable to both
> has-fork and has-ithreads. It doesn't sound to me like you need to be
> bound by either of those, so don't be.

   On the other hand; my program doesn't need to be portable. ;o)


-- 
Touch eyeballs to screen for cheap laser surgery!


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

Date: Thu, 10 Jun 2004 12:32:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Help me with threads issue !
Message-Id: <ca9kdl$edk$1@wisteria.csv.warwick.ac.uk>


Quoth "Vetle Roeim" <vetro@online.no>:
> On Thu, 10 Jun 2004 12:04:38 +0000 (UTC), Ben Morrow <usenet@morrow.me.uk>  
> wrote:
> 
> > Use fork
> > directly, or through something like Parallel::ForkManager. Do IPC
> > yourself via traditional mechanisms: pipes, sockets, SysV shared mem,
> > mmap.
> 
>    Well... ithreads fits very nicely into my solution. It didn't take
>    me long to create my own working thread pool, where I send data to
>    the different threads using Thread::Queue.

Fair enough.

>    I apologize if I seem slow, but what is wrong with ithreads? As far
>    as I know they are slower to start than forking, and they're memory
>    hungry, but other than that; are there any other problems I should be
>    aware of?

Not really. It just seems to me a terrible waste to implement fork in
userspace when the OS already does it perfectly well :).

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


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

Date: 10 Jun 2004 14:50:40 GMT
From: ctcgag@hotmail.com
Subject: Re: Help me with threads issue !
Message-Id: <20040610105040.940$Ir@newsreader.com>

"Vetle Roeim" <vetro@online.no> wrote:
> On Thu, 10 Jun 2004 08:41:58 +0000 (UTC), Ben Morrow
> <usenet@morrow.me.uk> wrote:
>
> >     I've searched on google (including groups.google.com) for
> >     information
> >>    on threading in Perl, and I'm under the impression that it has
> >>    improved alot lately.
> >
> > Perl ithreads now effectively perform a fork in userland, without using
> > copy-on-write. This has removed the problems with 5005threads, sure,
> > but it has also removed any point in using threads on an OS which can
> > fork. The OS will *always* be able to do it faster.
>
>    I discovered something interesting when testing forks.pm. Parts of my
>    code totally unrelated to the part where I use a thread pool were
>    significantly slower /with/ forks, than without!

Can you expand on the "completely unrelated" part?  Do you mean this code
is run after "use forks" statement, but before any forks are actually
made?

Xho

>
>    My code parses some stuff and enters into a database (DBI, MySQL).
>    I timed the different parts of the code, and here are the results:
>
>      forks:
>        100 trials of parse (96.031ms total), 960us/trial
>        100 trials of db (7.906s total), 79.061ms/trial
>
>      threads:
>        100 trials of parse (92.693ms total), 926us/trial
>        100 trials of db (70.068ms total), 700us/trial
>
>    Interesting, indeed.

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


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

Date: Thu, 10 Jun 2004 12:08:31 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <ca9ivv$d3f$2@wisteria.csv.warwick.ac.uk>


Quoth Joe Smith <Joe.Smith@inwap.com>:
> Paul Lalli wrote:
> 
> > On Tue, 1 Jun 2004, zzapper wrote:
> >>print join "",@t;
> > 
> > (on another note, there is no reason to join a sequence of elements with
> > the empty string.  (Non-interpolated) arrays are printed in that manner by
> > default.  (Unless of course you've changed $,)

 ..which can be a good reason, when you're not sure what $, is.

> 
> There is a reason: Efficiency.
> 
> If I recall correctly,
>    print @t;
> is like
>    print $_ for @t;

Not at all; it is (exactly) like

print join $, => @t;

If $, = '', then
    print @t;
is identical to
    print join '' => @t;
in every way.

> in that it has more overhead than
>    print "OneReallyLargeString";

In

my $str = join $, => @t;
print $str;

the print statement may have less overhead, yes; that is of course only
relevant if your printing the string far more often that you're creating
it (and benchmarks indicate your code is too slow, and profiling shows
that it's the print statements that are taking the time).

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.                                                   ben@morrow.me.uk


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

Date: Wed, 9 Jun 2004 22:52:35 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: match aaa but not 123aaa
Message-Id: <slrnccfmo3.i53.tadmc@magna.augustmail.com>

Ken Sington <ken_sington@nospam_abcdefg.com> wrote:
> Jay Tilton wrote:

>>     /(?<!123)YaaaY/

> now to find out what ?<! means...


It is actually a 4-character opening token (?<! and a 1-char close token )

See "zero-width negative look-behind assertion" in perlre.pod.


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


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

Date: 10 Jun 2004 14:04:15 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Object oriented form parsing
Message-Id: <Xns95046671DCA5Fasu1cornelledu@132.236.56.8>

Ben Morrow <usenet@morrow.me.uk> wrote in
news:ca896e$n3t$2@wisteria.csv.warwick.ac.uk: 

Thank you very much for the comments. Our block was hit by lightning last 
night just as I was responding to them. I don't know what that means :)

> 
> Quoth "A. Sinan Unur" <1usa@llenroc.ude>:
>> 
>> I have a pretty basic CGI application that has multiple forms with a 
>> number of common elements on them. 

 ...

>> I thought it might make sense to encapsulate the validation and 
>> untainting of input in a simple object. 

 ...

>> In addition, corresponding to each form that needs to be processed,
>> there is an object that handles the validation of all elements on
>> that form. For example:
>> 
>> package Ulti::Form::SubmitEditSession;
>> 
>> use Ulti::Param::Endowment;
>> use Ulti::Param::ExchangeRate;
>> use Ulti::Param::GroupSize;
>> use Ulti::Param::Matching;
>> use Ulti::Param::ParamName;
>> use Ulti::Param::PayoffMethod;
>> use Ulti::Param::Period;
>> use Ulti::Param::Role;
>> use Ulti::Param::SessionID;
> 
> Purely as a matter of taste, rather than having all these different
> classes I would have one class, Ulti::Param, with multiple
> constructors named after the parameter name. 

That makes a whole lot more sense. After all, the code above was beginning 
to look like Java rather than Perl.

> These would be called like: 
> 
>> sub validate {
>>     my ($self, $cgi) = @_;
>>     
>>     if(my $v =
>>     Ulti::Param::Period->new($cgi->param('practice_periods'))) 
> 
> if ( my $v = Ulti::Param->period($cgi->param('practice_periods') ) {
> 
> Similarly for the forms. I would also be strongly tempted to pass the
> whole CGI object and a param name in, so that the param could if
> necessary validate its consistency with the others on the form.

Got it.

>>     {
>>         $self->{'param'}->{'practice_periods'} = $v->value;
> 
> All those quotes and the second -> are unnecessary:

Yeah, I do know better, but thanks for pointing it out.

I am going to go with the changes you suggested.

SInan.

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Thu, 10 Jun 2004 14:52:14 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Object oriented form parsing
Message-Id: <Xns95046E947FA0Bdkwwashere@216.168.3.30>

A. Sinan Unur <1usa@llenroc.ude> wrote:

> I am testing out an idea and trying to see whether it makes sense.
> 
> I have a pretty basic CGI application that has multiple forms with
> a number of common elements on them. But depending on application
> state some elements may appear on a given form and others may not.
> 
> I thought it might make sense to encapsulate the validation and 
> untainting of input in a simple object.

Have you looked at CGI::FormBuilder? A quick look at the docs seems to 
show that it doesn't automatically untaint input, but it does have a 
hook for a validate() method.

I've been playing with a little module for setting up a quick form for 
searching a single database table (or view), where each field is an 
object, and a form/request is handled by an array of those objects. It's 
*very* crude at the moment, as I'm pretty new to OOP, but I may 
eventually use it for something real. (at the very least I'm getting 
some practice, anyway) If you're interested I can send you a copy -- 
it's only a few hundred lines.



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

Date: 10 Jun 2004 03:39:35 -0700
From: spiritelllo@interfree.it (Andrea Spitaleri)
Subject: parsing file through an array
Message-Id: <4de1519a.0406100239.6a902668@posting.google.com>

Hi
I have a file and I would like to remove from it the lines that match
the values from an array.
Here is the code that I unsuccessfully tried:
#!/usr/bin/perl

use warnings;
use strict;

open (FILE,"<$ARGV[0]") or die "$!";


my @h = ("H","N");

while (my $line=<FILE>){
    chomp $line;
    foreach my $i (@h){
	next if ($line=~ / +$i/);
	print "$line\n";
    }
}
and the file is something like that:
 2  C2             -0.4158    0.5051   -0.2805 C.3       1 UNK   
0.2800
 3  H3             -0.0655    0.8795    0.6861 H         1 UNK   
0.0000
 13  H13            -2.5997    0.4032   -0.4902 H         1 UNK   
0.0000
 14  N14            -2.0421   -0.8226    1.0724 N.2       1 UNK   
0.0476
 15  C15            -1.9418   -2.1366    1.4487 C.2       1 UNK   
0.0365
 1  O1             -0.4981    1.6455   -1.1635 O.3       1 UNK  
-0.6800
 2  C2             -0.4158    0.5051   -0.2805 C.3       1 UNK   
0.2800
 ...............
Swapping next with print "found $i" after the foreach I figured out
that the loop is working properly (it matches that array values) but
doesn't next.
What is it wrong????

thanks

regards

and


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

Date: 10 Jun 2004 11:23:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing file through an array
Message-Id: <ca9gcf$lr$1@mamenchi.zrz.TU-Berlin.DE>

Andrea Spitaleri <spiritelllo@interfree.it> wrote in comp.lang.perl.misc:
> Hi
> I have a file and I would like to remove from it the lines that match
> the values from an array.
> Here is the code that I unsuccessfully tried:
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> open (FILE,"<$ARGV[0]") or die "$!";
> 
> 
> my @h = ("H","N");
> 
> while (my $line=<FILE>){
>     chomp $line;
>     foreach my $i (@h){
> 	next if ($line=~ / +$i/);
> 	print "$line\n";
>     }
> }
> and the file is something like that:
>  2  C2             -0.4158    0.5051   -0.2805 C.3       1 UNK   
> 0.2800
>  3  H3             -0.0655    0.8795    0.6861 H         1 UNK   
> 0.0000
>  13  H13            -2.5997    0.4032   -0.4902 H         1 UNK   
> 0.0000
>  14  N14            -2.0421   -0.8226    1.0724 N.2       1 UNK   
> 0.0476
>  15  C15            -1.9418   -2.1366    1.4487 C.2       1 UNK   
> 0.0365
>  1  O1             -0.4981    1.6455   -1.1635 O.3       1 UNK  
> -0.6800
>  2  C2             -0.4158    0.5051   -0.2805 C.3       1 UNK   
> 0.2800
> ...............
> Swapping next with print "found $i" after the foreach I figured out
> that the loop is working properly (it matches that array values) but
> doesn't next.

If you look at your output closely, you'll find that it prints
every line twice, except those that match, which are printed only
once.  The reason is your inner loop.  It shouldn't print lines
before it is done, but only determine if there is a match.

BTW, there is no reason to chomp the lines if you immediately add
the "\n" back on.

    while (my $line=<FILE>){
        my $match;
        foreach my $i (@h){
            $match ||= $line=~ / +$i/;
            last if $match;
        }
        print $line unless $match;
    }

A better way is to construct a single regex that matches all unwanted
lines.

    / [HN]/ or print while <FILE>;

Anno


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

Date: Thu, 10 Jun 2004 12:16:08 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: parsing file through an array
Message-Id: <ca9je8$d3f$3@wisteria.csv.warwick.ac.uk>


Quoth spiritelllo@interfree.it (Andrea Spitaleri):
> Hi
> I have a file and I would like to remove from it the lines that match
> the values from an array.
> Here is the code that I unsuccessfully tried:
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> open (FILE,"<$ARGV[0]") or die "$!";

Better is:

open my $FILE, '<', $ARGV[0] or die "can't open $ARGV[0]: $!";

Better still is simply to use the magic filehandle ARGV.

> my @h = ("H","N");

I would have written

my @h = qw/H N/;

, but you may not like that.

> while (my $line=<FILE>){

Use $_: that's what it's there for.

while (<FILE>) {

or, if you're using ARGV,

while (<>) {

>     chomp $line;

Why? You're just going to stick it back on the end again when you print.

>     foreach my $i (@h){
> 	next if ($line=~ / +$i/);

This will next the for loop, not the while loop. You need to give the
while a label:

LINE: while (<>) {
    for my $i (@h) {
        next if / +\Q$i/;

Note the \Q: you should always use this if you mean to match a
variable's contents literally.

> 	print "$line\n";

This should go after the for loop.

>     }
> }

As Anno said, it would be better to construct a regex which matches all
the alternatives:

my @h  = qw/H A/;
my $re = join '|', map { qr/ +\Q$_/ } @h;

while (<>) {
    next if /$re/;
    print;
}

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Thu, 10 Jun 2004 07:38:00 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: parsing file through an array
Message-Id: <100620040738006176%jgibson@mail.arc.nasa.gov>

In article <4de1519a.0406100239.6a902668@posting.google.com>, Andrea
Spitaleri <spiritelllo@interfree.it> wrote:

> Hi
> I have a file and I would like to remove from it the lines that match
> the values from an array.
> Here is the code that I unsuccessfully tried:
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> open (FILE,"<$ARGV[0]") or die "$!";
> 
> 
> my @h = ("H","N");
> 
> while (my $line=<FILE>){
>     chomp $line;
>     foreach my $i (@h){
>  next if ($line=~ / +$i/);
>  print "$line\n";
>     }
> }

And to add to what Anno and Ben have already suggested (putting me in
august company, indeed), you may also use grep with the array of
strings to match:

my @h = qw/H N/;
while (my $line = <FILE>){
  print $line unless grep($line =~ / +\Q$_/,@h);
}

I am not claiming this is better or faster, just different. :)


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

Date: 10 Jun 2004 03:23:40 -0700
From: serverin2000@yahoo.com (Sree)
Subject: startting perl
Message-Id: <e9936b79.0406100223.9197686@posting.google.com>

Hi all,
  It would be appreciated if anyone can explain me how to start
writing program (i,e including downloading and installing the perl,how
to run the scripts).

   regards
    Sree


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

Date: Thu, 10 Jun 2004 12:55:31 +0200
From: "Andre Wisniewski" <andre.wisniewski@gmx.de>
Subject: Re: startting perl
Message-Id: <opr9dkmtkludlqzq@ares>

On 10 Jun 2004 03:23:40 -0700, Sree <serverin2000@yahoo.com> wrote:

> Hi all,
>   It would be appreciated if anyone can explain me how to start
> writing program (i,e including downloading and installing the perl,how
> to run the scripts).
>


Downloading and installing is very simple. Have a look at

http://www.activestate.com/



Andre

---

Fighting for peace is like f..ing for virginity


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

Date: Thu, 10 Jun 2004 08:58:16 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: startting perl
Message-Id: <20040610085024.Y8971@dishwasher.cs.rpi.edu>

On Thu, 10 Jun 2004, Sree wrote:

> Hi all,
>   It would be appreciated if anyone can explain me how to start
> writing program (i,e including downloading and installing the perl,how
> to run the scripts).

Depending on your operating system, you may already have Perl installed.
This is especially true if you're running on most any flavor of Unix or
Linux.   If you are, you can do a simple test by typing the following in
your shell:
perl -v

If you get output telling you the Perl version number, congratulations,
you have perl.   If you get an error message saying perl not found, then
either it's not installed or it's not in the path.

If you do not have perl already installed, there are a few options.  You
can build perl yourself from the source files, or you can download a
binary distribution for your system.  See http://www.perl.com/download.csp
for links to each.

Once you've gotten perl installed, you will (most likely) also have the
perl documentation installed.  This is the best place to get started.
From a command prompt, type:
perldoc perl

The output of this command will tell you several more files you should
read to help you get started.  When it tells you, for example, to "start
with perlintro", that means to type the following at your command prompt:
perldoc perlintro


Good luck, welcome to Perl, and don't hesitate to ask for help here when
you get stuck - after reading the FAQ found by typing at your command
prompt:
perldoc perlfaq
(which will lead you to which of perlfaq1 - perlfaq9 you want to read for
your question)

Paul Lalli


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

Date: Thu, 10 Jun 2004 08:34:43 -0500
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: startting perl
Message-Id: <MPG.1b321f6de27b861b989830@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <e9936b79.0406100223.9197686@posting.google.com>, 
serverin2000@yahoo.com says...
> Hi all,
>   It would be appreciated if anyone can explain me how to start
> writing program (i,e including downloading and installing the perl,how
> to run the scripts).
> 
>    regards
>     Sree
> 

If you are running some form of UNIX (or Linux, ??, etc...)
you may already have Perl installed. To see if you have Perl installed 
on your system you can try the following :

	perl -v

(this will cause Perl to display a message indicating its version 
information)

If you are using a PC then you can go to http://www.activestate.com
to get a copy of perl that you can download and install onto your PC.


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

Date: Thu, 10 Jun 2004 12:50:35 GMT
From: Doug O'Leary <dkoleary@olearycomputers.com>
Subject: Re: Variable hash names?
Message-Id: <vOYxc.3838$n%5.2574@fe07.usenetserver.com>

In article <wTOxc.25761$Sw.7744@attbi_s51>, Joe Smith wrote:
> Doug O'Leary wrote:
> 
>> %INVALID_TGT_GROUPS ( 'adm' => 1, 'bin' => 1 ...)
>> %VALID_HD_USERS     ( 'blfarrel' => 1, 'dekojis' => 1...)
>> %INVALID_HD_USERS   ( 'dkoleary' => 1, 'jarodrigue' => 1 ...)
> 
> Why don't you use a main hash that has several sub hashes?
> 
> %Registry = ( INVALID_TGT_GROUPS => { adm => 1, bin => 1, },
>                VALID_HD_USERS     => { blfarrel => 1, dekojis => 1, },
>                INVALID_HD_USERS   => { dkoleary => 1, jarodrigue => 1, },
>              );
> 
> foreach $hash ( keys %Registry) {
>    print "The hash $hash has the following entries:\n";
>    foreach $key ( sort keys %{$Registry{$hash}} ) {
>      print "  $key => $Registry{$hash}{$key},";
>    }
>    print "\n";
> }

I ended up doing exactly that - named differently, but similar
implementation.  Thanks for the reply.

-- 
--------
Senior UNIX Admin
O'Leary Computer Enterprises
dkoleary@olearycomputers.com (w) 630-904-6098 (c) 630-248-2749
resume:  http://www.olearycomputers.com/resume.html



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

Date: Thu, 10 Jun 2004 12:54:43 GMT
From: Doug O'Leary <dkoleary@olearycomputers.com>
Subject: Re: Variable hash names?
Message-Id: <nSYxc.3849$n%5.2374@fe07.usenetserver.com>

In article <40C7F3E7.1FB2747C@cadence.com>, Henry Salvia wrote:
> Doug O'Leary wrote:
>> 
>> Hey, all;
> 
> sub read_config {
> 	my($config) = @_ ;
> 	local(*IN) ;
> 	open IN, $config || die "Can't read $config - $!" ;
> 	my %BFH ;
> 	my $hkey ;
> 	while(<IN>) {
> 		next if /^#/ || /^$/ ;
> 		chomp ;
> 		if ( /\[\s*(\w+)\s*\]/ ) {
> 			$hkey = $1 ;
> 			next ;
> 		}
> 		next unless $hkey ;
> 		$BFH{$hkey}{$_} = 1 ;
> 	}
> 	close IN ;
> 	return \%BFH ;
> }
> 

Exactly what I ended up doing initially.  After moving forward
for a bit, I found a need for the config file to support entries like:

[SYSLOG_FACILITY]
facility = user
info     = info
alert    = warning

That was easy to work into the code, however.

Thanks for the reply.  I appreciate it.

Doug

-- 
--------
Senior UNIX Admin
O'Leary Computer Enterprises
dkoleary@olearycomputers.com (w) 630-904-6098 (c) 630-248-2749
resume:  http://www.olearycomputers.com/resume.html



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

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


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