[23292] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5512 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 16 14:07:27 2003

Date: Tue, 16 Sep 2003 11:05:07 -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           Tue, 16 Sep 2003     Volume: 10 Number: 5512

Today's topics:
    Re: boston perl classes with damian conway <dave@dave.org.uk>
    Re: date sorting module <mothra@nowhereatall.com>
    Re: Hash dereferencing and object-oriented Perl <stefan@unfunked.org>
    Re: Hash dereferencing and object-oriented Perl (Tad McClellan)
    Re: More on 5.8 and signals <grazz@pobox.com>
    Re: More on 5.8 and signals <eric@dmcontact.com>
    Re: Outlook Address Books and Perl? <nospam@thanksanyway.org>
        Pattern Matching in file with invisible char (M Pires)
    Re: Subtracting arrays of floats. <tassilo.parseval@rwth-aachen.de>
    Re: Subtracting arrays of floats. (Anno Siegel)
    Re: Subtracting arrays of floats. <tassilo.parseval@rwth-aachen.de>
    Re: Subtracting arrays of floats. <tassilo.parseval@rwth-aachen.de>
    Re: Subtracting arrays of floats. <tassilo.parseval@rwth-aachen.de>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 16 Sep 2003 17:21:52 +0100
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: boston perl classes with damian conway
Message-Id: <pan.2003.09.16.16.21.51.377384@dave.org.uk>

On Tue, 16 Sep 2003 04:58:06 -0700, Chris Marshall wrote:

> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7llsp2w17.fsf@mail.sysarch.com>...
>>
>> damian conway will be teaching these classes in boston:
> 
> Any chance he'll ever come to London ?

He's been to London at least twice in the last couple of years.

Dave...

-- 
  Drugs are just bad m'kay



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

Date: Tue, 16 Sep 2003 09:53:48 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: date sorting module
Message-Id: <3f673fa3$1@usenet.ugs.com>

Hi Sam,

"Sam" <samj@austarmetro.com.au> wrote in message
news:3f66c9a3$1@news.comindico.com.au...
> Hello
> I just came from cpan, after doing some searches and before I get a
module,
> wanted to ask if any one out there knows of a module that takes an array
of
> dates and sort them regardless of the date formate.

This might give you some ideas

use strict;
use warnings;
use DateTime;
my @new_dates;

my @dates =("Sat, 19 Jul 2003 15:53:45 -0500","1996-02-03","08-Feb-1998
14:15:29 GMT");


foreach my $new_date (@dates) {
    push(@new_dates, DateTime::Format::Mytest->parse_datetime($new_date) );
  }

print map {$_->datetime(), "\n"} sort @new_dates;



package DateTime::Format::Mytest;

  use DateTime::Format::HTTP;
  use DateTime::Format::Mail;


  use DateTime::Format::Builder (
    parsers => { parse_datetime => [
      sub { eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) } },
      sub { eval { DateTime::Format::Mail->parse_datetime( $_[1] ) } },
    ] }
  );




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

Date: Tue, 16 Sep 2003 16:29:00 +0100
From: Stefan <stefan@unfunked.org>
Subject: Re: Hash dereferencing and object-oriented Perl
Message-Id: <bk7a7u$l96$1@news8.svr.pol.co.uk>

Thanks for your response. I too find ${$hashref}{$key} hard to look at, 
harder than $hashref->{$key} in fact. But $$hashref{$key} to me looks 
nicer than either. I guess it's just personal preference.

The only reason I mentioned OO Perl is that the hash reference you're 
dealing with in a method is invariably just $self meaning it's simple 
enough for the additional curly braces to be omitted - $$hashref{$key} 
as opposed to ${$hashref}{$key}. I am of course aware that references 
are used elsewhere too.

I wish I knew why Mozilla isn't wrapping my messages properly.
Thanks again...

Stefan


Uri Guttman wrote:

>>>>>>"S" == Stefan  <stefan@unfunked.org> writes:
> 
> 
>   S> Hi...  For I while now I have been coding OO Perl using the
>   S> $self->{member} syntax to grab elements out of my blessed hash
>   S> reference. This works just fine, however it recently occurred to me
>   S> that since $self is always a simple scalar variable (containing a
>   S> reference), I could just use the $$self{member} syntax
>   S> instead. Personally, I find this easier to deal with - it's one
>   S> character less to type and occasionally I find it useful to use
>   S> @$self{member1, member2}, something which I still haven't figured
>   S> out how to do with ->.
> 
>   S> So my question... is there anything wrong with using this syntax?
>   S> The only reason I ask is that I have never seen an OO Perl module
>   S> which uses it... everyone seems to use the $self->{member}
>   S> version. Sorry if I'm being and idiot and missing something
>   S> blatantly obvious!
> 
> first off, the way you dereference a hash ref (or any ref) has nothing
> to do with OO perl. OO perl uses refs but you can use refs anywhere you
> want without any OO code at all.
> 
> the main way to dereference is to put the proper sigil in front of the
> ref value like %{$href} or ${$href}{$key}. but most (not you it seems)
> find the latter hard to visually parse and larry gave us the syntactic
> sugar of -> thus allowing $href->{$key}. it is your choice as to which
> deref style to use but the vast majority use -> when accessing single
> elements from array or hash refs.
> 
> uri
> 



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

Date: Tue, 16 Sep 2003 10:30:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Hash dereferencing and object-oriented Perl
Message-Id: <slrnbmeb3u.3jh.tadmc@magna.augustmail.com>

Stefan <stefan@unfunked.org> wrote:

> For I while now I have been coding OO Perl using the $self->{member} 
> syntax to grab elements out of my blessed hash reference. This works 
> just fine, however it recently occurred to me that since $self is always 
> a simple scalar variable (containing a reference), I could just use the 
> $$self{member} syntax instead. Personally, I find this easier to deal 
> with - 


You are likely in the minority on that point.


> it's one character less to type and occasionally I find it useful 
> to use @$self{member1, member2}, something which I still haven't figured 
> out how to do with ->.


You cannot take a slice with the arrow operator.


> So my question... is there anything wrong with using this syntax? 


Readability (for the majority).


> The 
> only reason I ask is that I have never seen an OO Perl module which uses 
> it... everyone seems to use the $self->{member} version. Sorry if I'm 
> being and idiot and missing something blatantly obvious!


Your tastes differ from most other's tastes. (nothing wrong with that)

Nothing wrong with using the one _you_ like, assuming it will be
only you who does the maintenance.


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


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

Date: Tue, 16 Sep 2003 15:44:41 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: More on 5.8 and signals
Message-Id: <JdG9b.18$Cs1.17@nwrdny02.gnilink.net>

Eric Frazier <eric@dmcontact.com> wrote:
> I am pretty desparate to get this working, and if anyone wants to earn
> some cash helping me fix things PLEASE call me at 250 655-9513. 
> 
> Erro was No child processes %! --------
> 
> So it looks like the parent got killed on that  error "No child process" 

That's because you're looping in the CHLD handler now --

>  sub REAPER_NEW {
>      logmsg "got - @_\n";
>      my $wpid = undef;
>      while ($wpid = waitpid(-1,WNOHANG)>0) {

This calls waitpid() until it fails, and the eventual failure 
clobbers $!.  It was EINTR after the SIGCHLD, but now it's ECHILD.  

You could retry accept() on either ECHILD or EINTR, I think.  Or
you could set a flag in the handler:

  my $reaped;

  $SIG{CHLD} = sub {
    $reaped = 1;
    1 while waitpid(-1, WNOHANG) > 0;
  };

  while (1) {
    my $con = $sock->accept or do {
      next if $!{EINTR} or $reaped;
      last;
    };

    # ...

  }
  continue {
    $reaped = 0;
  }

And on many systems, you can just set $SIG{CHLD} = "IGNORE" and the 
children will be reaped automatically.

-- 
Steve


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

Date: Tue, 16 Sep 2003 17:33:50 GMT
From: bob <eric@dmcontact.com>
Subject: Re: More on 5.8 and signals
Message-Id: <3F674987.5030408@dmcontact.com>

Hi Steve,

That worked for me! But using $SIG{CHLD} = 'IGNORE'; also worked.

I seem to now be having problems with keeping my database connection, 
but the server is staying live. I tried connecting at the top globaly, 
and I also tried connecting in the subs that get run by commands. Same 
result, after the first connect and close I loose my db connection.

But that is problem I will most likely be able to solve on my own, so 
thanks for your help...


Eric



Steve Grazzini wrote:
> Eric Frazier <eric@dmcontact.com> wrote:
> 
>>I am pretty desparate to get this working, and if anyone wants to earn
>>some cash helping me fix things PLEASE call me at 250 655-9513. 
>>
>>Erro was No child processes %! --------
>>
>>So it looks like the parent got killed on that  error "No child process" 
> 
> 
> That's because you're looping in the CHLD handler now --
> 
> 
>> sub REAPER_NEW {
>>     logmsg "got - @_\n";
>>     my $wpid = undef;
>>     while ($wpid = waitpid(-1,WNOHANG)>0) {
> 
> 
> This calls waitpid() until it fails, and the eventual failure 
> clobbers $!.  It was EINTR after the SIGCHLD, but now it's ECHILD.  
> 
> You could retry accept() on either ECHILD or EINTR, I think.  Or
> you could set a flag in the handler:
> 
>   my $reaped;
> 
>   $SIG{CHLD} = sub {
>     $reaped = 1;
>     1 while waitpid(-1, WNOHANG) > 0;
>   };
> 
>   while (1) {
>     my $con = $sock->accept or do {
>       next if $!{EINTR} or $reaped;
>       last;
>     };
> 
>     # ...
> 
>   }
>   continue {
>     $reaped = 0;
>   }
> 
> And on many systems, you can just set $SIG{CHLD} = "IGNORE" and the 
> children will be reaped automatically.
> 



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

Date: Tue, 16 Sep 2003 10:05:54 -0700
From: "Mark" <nospam@thanksanyway.org>
Subject: Re: Outlook Address Books and Perl?
Message-Id: <ZZqdnczS8eFx3_qiXTWc-w@speakeasy.net>


"James Willmore" <jwillmore@cyberia.com> wrote:
> http://search.cpan.org/
> search keyword: outlook
>
> first item thats shows is: mbx2mbox

Yes, but the several Perl modules that "read" an OE
address book, actually require that the data be exported
from OE first. OE only exports its address book as
comma-separated values (*.CSV). Unfortunately, this is
a useless format, since data fields in the OE address book
fields can (and often will) contain commas. The output
cannot be parsed reliably.

So I was hoping for a Perl module that can actually read
the OE address book's binary format directly.




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

Date: 16 Sep 2003 08:45:33 -0700
From: MIGUEL.PIRES@PORTUGALMAIL.PT (M Pires)
Subject: Pattern Matching in file with invisible char
Message-Id: <6efa7ec7.0309160745.e6d2726@posting.google.com>

Hi there,

First of all, I am sorry if this is a FAQ. I couldn't find anything in the
PerlDoc, so if I missed something please be kind enough to redirect me to
it!

I am currently working on a Perl script that will parse out values from an
"almost" text file.  The reason I say this is because there are "invisible"
chars in the file such as the ASCII SUB char ( 0x1A ). This chars confuse
the <HANDLE> and cause a premature EOF.

Is there a way around this?

Thx a lot!


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

Date: 16 Sep 2003 15:16:19 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Subtracting arrays of floats.
Message-Id: <bk79g3$psv$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Jonas Nilsson:

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:bk726u$ksd$1@mamenchi.zrz.TU-Berlin.DE...
> 
>> The Inline module makes simple things simple.  It knows a lot about
>> XS that the user doesn't have to know (at least in simple cases like
>> this one).  Here is how a similar function (named "distance" here) can
>> be set up using Inline.  We pass in two strings that contain the packed
>> doubles, plus the number of data points.  The latter is just for
>> convenience, we could determine the length of one of the strings and
>> use that.
> 
> Ok. Call me thick, but I'm not an expert, to say the least.
> 
> To compile C either in Inline module or as a separate XS-module i guess I
> need a C-compiler. So I don't have one... The nmake utility for Windows
> isn't a C-compiler or is it?

Not having a C compiler is a little problem now. I heard rumours that
there is a free version of VisualC available but I couldn't find it.
nmake is not a compiler, it's just the make tool from Microsoft (which
is needed as well).

> When I try to run/make code in one of the above ways I get DOS complaining
> about the lack of cl command. Is this a compiler?

Yes, this is the compiler you need.

> What exactly do I need to run this?
> I've got:
> 1. A computer
> 2. An operating system (Windows 2000)
> 3. perl5.6.1 from activestate
> 4. nmake15 (from windows support) for WinNT/Win95. I couldn't find one for
> Win2000.
> 5. The Inline module via ppm from
> http://ppm.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer
> 
> And nothing more (...well I've got a nice espresso machine, but I doubt it
> would influence much).

Quite. :-)

The thing that you are lacking is indeed the compiler. Since the code to
solve your problem already exists in this group, someone would just have
to make a PPM distribution out of it. Maybe I'll boot Windows later
today and can do that (either Anno's or my version, but probably a
healthy mix of both...I liked the pack() so much).

Hmmh, ActiveState's new automatic build-process could be abused for
that, I guess. Create a Perl/XS/Inline module and upload it to the CPAN.
ActiveState currently picks up every CPAN upload and tries to convert it
into a PPM distribution. This includes modules in need of a C compiler.
Once it has made it into the official PPM repositories, the module could
be deleted again from the CPAN. 

With a little bit of Makefile.PL trickery, one could possibly make them
compile Win32 applications for oneself. :-)

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 16 Sep 2003 15:37:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Subtracting arrays of floats.
Message-Id: <bk7ane$po5$1@mamenchi.zrz.TU-Berlin.DE>

Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
> > Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in
> comp.lang.perl.misc:

[...]

> >     /* build sum */
> >     double sum = 0.0;
> >     while ( n-- ) {
> >        sum += fabs( *xx++ - *yy++);
> >     }
> >     return( sum);
> > }
> > EOC
> > __END__
> 
> One minor thing: you use fabs() from math.h. Is Inline::C smart enough
> to automatically link against libm? It might be necessary to add a
> 
>     use Inline C => Config => 
>         LIBS => '-lm';

I don't know, maybe I just got lucky, but it found fabs() for me.  It may
well be that the library must be given in a different setup.

Anno
-- 

print sort( 'ke', 'erl ', 'hac', 'Just ', 'r,', 'er P', 'anoth'), "\n";



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

Date: 16 Sep 2003 16:11:51 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Subtracting arrays of floats.
Message-Id: <bk7co7$9s$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Anno Siegel:

> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
>> Also sprach Anno Siegel:
>> > Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in
>> comp.lang.perl.misc:
> 
> [...]
> 
>> >     /* build sum */
>> >     double sum = 0.0;
>> >     while ( n-- ) {
>> >        sum += fabs( *xx++ - *yy++);
>> >     }
>> >     return( sum);
>> > }
>> > EOC
>> > __END__
>> 
>> One minor thing: you use fabs() from math.h. Is Inline::C smart enough
>> to automatically link against libm? It might be necessary to add a
>> 
>>     use Inline C => Config => 
>>         LIBS => '-lm';
> 
> I don't know, maybe I just got lucky, but it found fabs() for me.  It may
> well be that the library must be given in a different setup.

Hmmh, right. My XS thing also works without it. I thought that maybe the
linker flags in Config.pm were copied but this doesn't happen:

[...]
cc -c  -I. -O3 -march=athlon -fno-strict-aliasing -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -O2   -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\"
-fpic "-I/usr/lib/perl5/5.8.0/i686-linux/CORE"   PairwiseDiff.c
Running Mkbootstrap for Math::PairwiseDiff ()
chmod 644 PairwiseDiff.bs
rm -f blib/arch/auto/Math/PairwiseDiff/PairwiseDiff.so
LD_RUN_PATH="" cc  -shared -L/usr/local/lib PairwiseDiff.o  -o
blib/arch/auto/Math/PairwiseDiff/PairwiseDiff.so

Anyway, one shouldn't complain when things unexpectedly work. :-)

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 16 Sep 2003 16:51:38 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Subtracting arrays of floats.
Message-Id: <bk7f2q$2ug$1@nets3.rz.RWTH-Aachen.DE>

[ posted and mailed ]

Also sprach Jonas Nilsson:

> When I try to use the Inline C i get from DOS:
> 'cl' is not recognized as an internal or external command, operable program
> or batch file. (and a lot more)

You are lucky. I just incorporated Anno's pack() trick into my module
and it compiled without any problems under Windows/VisualC (this is
rather the exception, not the rule). I made a .ppd for it which you can
now install even if no VisualC is around [ might line-wrap ]:

    C:\>  ppm install http://www-users.rwth-aachen.de/tassilo.parseval/Math-PairwiseDiff.ppd

I don't have WinNT/2000 but only WinME. It should nonetheless work for
you.

It comes with some rudimentary POD-documentation as well. This little
script demonstrates all you can do with it (and yes, it still ran under
Windows):

    #! /usr/bin/perl

    use strict;
    use Math::PairwiseDiff;
    use Data::Dumper;

    my ($ary1_d, $ary2_d);

    $ary1_d .= pack('d', rand() - 0.5) for 0 .. 100 ;
    $ary2_d .= pack('d', rand() - 0.5) for 0 .. 100 ;

    my $a1 = Math::PairwiseDiff->new($ary1_d);
    my $a2 = Math::PairwiseDiff->new($ary2_d);

    print Dumper [ $a1->to_ary ];
    print "Num of elements: ", scalar $a1->to_ary, "\n";

    print $a1->diff($a2), "\n";
    print $a2->diff($a1);

So I just added the to_ary() method that returns the packed doubles as a
list of real Perl scalars containing human-readable floating point
numbers. It now also works with arrays of different length.
Furthermore, you no longer have to pass the number of doubles in the
packed string to the constructor. It can figure that out itself.

This module is not generic enough to be added to the CPAN however.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 16 Sep 2003 17:04:20 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Subtracting arrays of floats.
Message-Id: <bk7fqk$3oj$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tassilo v. Parseval:
> [ posted and mailed ]

Or rather, posted and tried to mail. Naturally, the email address
bounced.

> Also sprach Jonas Nilsson:

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

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


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