[25975] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8194 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 23 06:05:33 2005

Date: Thu, 23 Jun 2005 03: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           Thu, 23 Jun 2005     Volume: 10 Number: 8194

Today's topics:
    Re: Email Address Validation <zen13097@zen.co.uk>
    Re: Email Address Validation chris-usenet@roaima.co.uk
    Re: How can I pick up those big numbers <tadmc@augustmail.com>
        ignoring SIGCHLD <moritz.karbach@desy.de>
    Re: ignoring SIGCHLD (Anno Siegel)
    Re: LWP::UserAgent and 404 page not found <iss025@bangor.ac.uk>
    Re: sort on third, then second field <jurgenex@hotmail.com>
    Re: sort on third, then second field <john@castleamber.com>
    Re: sort on third, then second field <1usa@llenroc.ude.invalid>
    Re: sort on third, then second field <john@castleamber.com>
    Re: sort on third, then second field <john@castleamber.com>
        Sorting on sub-hash values <someone@somewhere.com>
    Re: Sorting on sub-hash values (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Jun 2005 07:25:26 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Email Address Validation
Message-Id: <42ba63e6$0$23946$db0fefd9@news.zen.co.uk>

On Wed, 22 Jun 2005 16:08:51 +0100, Brian Wakem <no@email.com> wrote:
>  Dave Weaver wrote:
> 
> > On Wed, 22 Jun 2005 15:13:13 +0100, Brian Wakem <no@email.com> wrote:
> >> 
> >>  invalid_email_response() unless $FORM{'emailaddress'} =~
> >>  m/^[-a-zA-Z0-9_.]+\@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9_.]+[a-zA-Z]$/;
> > 
> > That code will reject perfectly valid email addesses, such as
> >  joe+bloggs@example.com
> >  my*name@example.com
> > and many others.
> 
>  I know, but for ease of implementation against effectiveness it is a
>  reasonable trade-off IMO.  I have a database of 1.4 million email addresses
>  and that regex matches *all* of them.

Just because it works with your sample, doesn't make it correct, 
and surely correctness is the most important thing?

Anyway, why use an incorrect solution when a correct one is an equal
number of lines of code? (and more readable code, at that).



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

Date: Thu, 23 Jun 2005 09:17:00 +0100
From: chris-usenet@roaima.co.uk
Subject: Re: Email Address Validation
Message-Id: <em7qo2-lak.ln1@news.roaima.co.uk>

Brian Wakem <no@email.com> wrote:
>  m/^[-a-zA-Z0-9_.]+\@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9_.]+[a-zA-Z]$/;

> [...] for ease of implementation against effectiveness it is a
> reasonable trade-off IMO.

I often use a fairly spam-proof address that includes spaces in the
username component. It's a perfectly valid email address - albeit one
that exim4 appears to reject by default :-(

My example? Somthing along the lines of this: "john d@e"@roaima.co.uk

Chris


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

Date: Wed, 22 Jun 2005 18:24:53 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How can I pick up those big numbers
Message-Id: <slrndbjsq5.186.tadmc@magna.augustmail.com>

* Tong * <sun_tong@users.sourceforge.net> wrote:

> Locate the string "&#8226;" by Perl


   my $position = index $big_string, '&#8226;';


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


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

Date: Thu, 23 Jun 2005 09:23:46 +0200
From: Moritz Karbach <moritz.karbach@desy.de>
Subject: ignoring SIGCHLD
Message-Id: <d9do24$3as6$1@claire.desy.de>

Hi,

since my last question "How to kill a forked child process..." [1], I have
learned a little bit more.

I have adjusted the run() function of my Command class following all the
hints you gave me and it works.

But now I have the problem, that in the dmesg appears something like:

> application bug: h1mcJobwrapper.(25668) has SIGCHLD set to SIG_IGN but
> calls wait().
> (see the NOTES section of 'man 2 wait'). Workaround activated.

But I never call Perl's wait() in my code! Nor do I call system's wait
explicitly.

Btw, I haven't found out yet what this is good for:

        $SIG{TTIN} = "IGNORE";
        $SIG{TTOU} = "IGNORE";
        setpgrp(0,0);

Btw2, if I'm redirecting STDERR of the forked child to STDOUT so that the
parent receives it as well, I have the a problem with executing shell
skripts that do something like

        #!/bin/bash
        somebinary &

The problem is, that the reading of the pipe

        my @output = <$fh_child>;
        close($fh_child);

blocks until somebinary has finished, although both the shell skript and the
sh -c interpreter called by Perl are done a lot earlier.


Nevertheless, here is the run function:

<code>
sub runFork # ()
{
        my $this = shift;
        my $fh_child; # pipe to the child process running the command

        $SIG{CHLD} = "IGNORE";

        #
        # fork the program branch
        #
        my $pid;
        $pid = open($fh_child,"-|");
        
        die "cannot fork: $!\n" unless defined($pid);
        
        if ( $pid == 0 )
        {
                #
                # child (command branch)
                #
                my @temp     = ($EUID, $EGID);
                my $orig_uid = $UID;
                my $orig_gid = $GID;
                $EUID = $UID;
                $EGID = $GID;
                
                # Drop privileges
                $UID  = $orig_uid;
                $GID  = $orig_gid;
                
                # Make sure privs are really gone
                ($EUID, $EGID) = @temp;
                
                die "Can't drop privileges"
                     unless $UID == $EUID  && $GID eq $EGID;
                
                $SIG{TTIN} = "IGNORE";
                $SIG{TTOU} = "IGNORE";          

                #open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
                
                setpgrp(0,0);

                exec($this->{command}) or die ("cannot run program: $!");
                exit;
        }

        #
        # parent
        #
        # fork once more for the watchdog for the timeout
        #
        my $wdog_id;

        if ( $this->{timeout} > 0 )
        {
                $wdog_id = fork;        
                die "cannot fork: $!\n" unless defined($wdog_id);

                if ( $wdog_id == 0 )
                { 
                        #
                        # child - watchdog branch
                        #
                        $SIG{TTIN} = "IGNORE";
                        $SIG{TTOU} = "IGNORE";

                        setpgrp(0,0);

                        sleep($this->{timeout});

                        #
                        # killing negative process id's also sends the signal to all
                        # other processes in the process-group of $pid
                        #
                        # In our case this would kill both the shell interpreter and
                        # the executable launched by the interpreter.
                        #
                        kill(9, -$pid);
                        
                        exit 0;
                }
        }

        #
        # read output of the command
        #
        # this blocks until the command is finished!
        #
        my @output = <$fh_child>;
        close($fh_child);
        $this->{output} = \@output;

        #
        # return value of the command
        #
        $this->{ret} = $?;
        my $sig = $this->{ret} & 127;

        #
        # if command succeeded, we don't need the watchdog any more: kill!
        #
        if ( defined($wdog_id) && $sig != 9 )
        {
                kill(9, $wdog_id);
        }

        return $this->{ret};
}
</code>

Cheers,

- Moritz

[1] <d8utj2$4tjhd$1@claire.desy.de>


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

Date: 23 Jun 2005 09:28:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ignoring SIGCHLD
Message-Id: <d9dvbm$8b6$1@mamenchi.zrz.TU-Berlin.DE>

Moritz Karbach  <moritz.karbach@desy.de> wrote in comp.lang.perl.misc:
> Hi,
> 
> since my last question "How to kill a forked child process..." [1], I have
> learned a little bit more.
> 
> I have adjusted the run() function of my Command class following all the
> hints you gave me and it works.
> 
> But now I have the problem, that in the dmesg appears something like:
> 
> > application bug: h1mcJobwrapper.(25668) has SIGCHLD set to SIG_IGN but
> > calls wait().
> > (see the NOTES section of 'man 2 wait'). Workaround activated.
> 
> But I never call Perl's wait() in my code! Nor do I call system's wait
> explicitly.

You don't, but close() does.  From perldoc -f close:

    Closing a pipe also waits for the process executing on the pipe
    to complete...

Anno


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

Date: Thu, 23 Jun 2005 10:36:37 +0100
From: "P.R.Brady" <iss025@bangor.ac.uk>
Subject: Re: LWP::UserAgent and 404 page not found
Message-Id: <42BA82A5.9080303@bangor.ac.uk>

Brian Wakem wrote:
> P.R.Brady wrote:
> 
> 
>>I'm using LWP::UserAgent (Active Perl v5.6.1.638)  in a web site
>>crawler, but there's a page I just can't read -
>>http://www.psychology.bangor.ac.uk/ gives '404 not found'  It is
>>similarly inaccessible for many of the web checkers out there (like
>>http://validator.w3.org/) but is okay with 'real' browsers like Internet
>>Explorer and Netscape.
>>There's a redirection there somewhere behind the scenes to index.php
>>(which can be read), but then that is so for our main web page
>>http://www.bangor.ac.uk/ as well and that redirects okay.
>>


[ ... snipped ...]

> 
> They seem to be doing a redirect based upon the language that your broswer
> declares itself to accept.  As you aren't doing this you get an error page.
> 
> Try:-
> 
> my $response = $browser->get($url, Referer => $referer, ACCEPT_LANGUAGE =>
> 'en');
> 

Thanks Brian, that certainly works,  Much appreciated.

Now do I have to alter my crawler to scan pages twice I wonder, once for 
English, once for Welsh?

Phil



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

Date: Thu, 23 Jun 2005 01:27:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: sort on third, then second field
Message-Id: <0eoue.1885$fw1.1111@trnddc02>

A. Sinan Unur wrote:
> jbl <jblno@spamhotmail.com> wrote in
> news:80hjb1do9eejijki2g2krvdnaro1ip7ogf@4ax.com:
>
>> I have tried several methods and this at least runs, but does
>> nothing. I am trying to get this to sort by date (third field) then
>> by description (second field)
>
> Then, you need to do it in one go. [...]

Actually no.
Reportedly perl sort() is stable as of version 5.6 or something like that 
(please don't quote me on the number) which means that you can sort by 
description first and then by date. Because of the stable sort elements with 
the same date will keep their relative ordering as it was established during 
the previous sorting by description.

jue 




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

Date: 23 Jun 2005 01:52:50 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: sort on third, then second field
Message-Id: <Xns967DD43D7ACEBcastleamber@130.133.1.4>

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

>     if(my @fields = ( /^(\d)\t(.+)\t(\d\d)-(\d\d)-(\d\d\d\d)$/ ) ) {

                                                      (\d{4})

> sub comparator2 {
>     my $r;
>     unless($r = ($a->[4] <=> $b->[4])) {
>         unless($r = ($a->[2] <=> $b->[2])) {
>             $r = ($a->[3] <=> $b->[3]);
>         }
>     }
>     
>     return $r ? $r : ($a->[1] cmp $b->[1]);
> }

ouch, what's wrong with:

@data = sort {

    	$a->[4] <=> $b->[4]    	    	# year
    	    	or
    	$a->[2] <=> $b->[2]    	    	# month
    	    	or
    	$a->[3] <=> $b->[3]    	    	# day
    	    	or
    	$a->[1] <=> $b->[1]    	    	# description

} @data;



-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Thu, 23 Jun 2005 03:08:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: sort on third, then second field
Message-Id: <Xns967DEB5C01F6Fasu1cornelledu@127.0.0.1>

John Bokma <john@castleamber.com> wrote in 
news:Xns967DD43D7ACEBcastleamber@130.133.1.4:

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
> 
>> sub comparator2 {

 ...

> ouch, what's wrong with:

<nice sort coderef snipped>

Nothing. My code flowed directly from my stream of consciousness. Yours is 
certainly easier on the eyes.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 23 Jun 2005 05:52:52 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: sort on third, then second field
Message-Id: <Xns967E8CB56029castleamber@130.133.1.4>

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

> <nice sort coderef snipped>
> 
> Nothing. My code flowed directly from my stream of consciousness.
> Yours is certainly easier on the eyes.

:-) Thanks. I never saw that unless construct, and had to look a few times 
:-).

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 23 Jun 2005 05:53:58 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: sort on third, then second field
Message-Id: <Xns967E8FAF5C49castleamber@130.133.1.4>

"Jürgen Exner" <jurgenex@hotmail.com> wrote:

> A. Sinan Unur wrote:
>> jbl <jblno@spamhotmail.com> wrote in
>> news:80hjb1do9eejijki2g2krvdnaro1ip7ogf@4ax.com:
>>
>>> I have tried several methods and this at least runs, but does
>>> nothing. I am trying to get this to sort by date (third field) then
>>> by description (second field)
>>
>> Then, you need to do it in one go. [...]
> 
> Actually no.
> Reportedly perl sort() is stable as of version 5.6 or something like
> that (please don't quote me on the number) which means that you can
> sort by description first and then by date. Because of the stable sort
> elements with the same date will keep their relative ordering as it
> was established during the previous sorting by description.

Thanks, that's interesting info to remember.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Thu, 23 Jun 2005 10:30:21 +0100
From: "IanW" <someone@somewhere.com>
Subject: Sorting on sub-hash values
Message-Id: <Udmdnd_Lzb6iHCffRVnyjg@giganews.com>

If I have a hash of hashes like this:

my %hash= ( 'bob' => { 'age' => 35,  'weight' => 160 },
    'john' => { 'age' => 22,  'weight' => 138 },
    'sue' => { 'age' => 31,  'weight' => 143 } );

and I want to sort people by their age, how would I go about it?

Thanks

Ian




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

Date: 23 Jun 2005 09:58:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting on sub-hash values
Message-Id: <d9e13b$8b6$2@mamenchi.zrz.TU-Berlin.DE>

IanW <someone@somewhere.com> wrote in comp.lang.perl.misc:
> If I have a hash of hashes like this:
> 
> my %hash= ( 'bob' => { 'age' => 35,  'weight' => 160 },
>     'john' => { 'age' => 22,  'weight' => 138 },
>     'sue' => { 'age' => 31,  'weight' => 143 } );
> 
> and I want to sort people by their age, how would I go about it?

What have you tried?  Given a name, how would you access the age
of that person?

Anno


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

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


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