[31418] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2670 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 11 09:09:38 2009

Date: Wed, 11 Nov 2009 06:09:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Nov 2009     Volume: 11 Number: 2670

Today's topics:
    Re: connect to localhost failed error with Mail::Sendma <hjp-usenet2@hjp.at>
    Re: connect to localhost failed error with Mail::Sendma <smallpond@juno.com>
    Re: connect to localhost failed error with Mail::Sendma <hjp-usenet2@hjp.at>
    Re: connect to localhost failed error with Mail::Sendma <ben@morrow.me.uk>
    Re: connect to localhost failed error with Mail::Sendma <himanshu.garg@gmail.com>
        Exiting threads via signal <timothy.hill@gmail.com>
    Re: good perl hosts <sysadmin@example.com>
    Re: good perl hosts <robin1@cnsp.com>
        regex replace hex with &#ddd; <john1949@yahoo.com>
    Re: regex replace hex with &#ddd; sln@netherlands.com
    Re: regex replace hex with &#ddd; <john1949@yahoo.com>
        Trying to process duplicate in flat file <nobody@nowhere.com>
    Re: Trying to process duplicate in flat file <rvtol+usenet@xs4all.nl>
    Re: Trying to process duplicate in flat file <tadmc@seesig.invalid>
    Re: Trying to process duplicate in flat file <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Nov 2009 21:49:58 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: connect to localhost failed error with Mail::Sendmail on Windows
Message-Id: <slrnhfjkfn.96i.hjp-usenet2@hrunkner.hjp.at>

On 2009-11-09 09:45, ++imanshu <himanshu.garg@gmail.com> wrote:
> On Nov 8, 11:03 pm, smallpond <smallp...@juno.com> wrote:
>> Installation instructions for Mail::Sendmail:
>>
>> "At the top of Sendmail.pm, set your default SMTP server(s),
>> unless you specify it with each message, or want to use the
>> default (localhost)."
>
> yes I wrongly assumed smtp to be so simple that the module alone could
> handle it without another server.

That doesn't make sense. A protocol specifies how two (or more) entities
talk to each other. In the case of a client/server protocol like SMTP,
how a client talks to a server. Since Mail::Sendmail implements an SMTP
client (it is used to send mail, not to receive it), it needs an SMTP
server to talk to.

> There were some EHLO, HELO strings
> in the pm file which reinforced my wrong assumption.

Of course the module contains these strings. It needs to send them to
the server.

	hp


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

Date: Tue, 10 Nov 2009 16:04:17 -0500
From: Steve C <smallpond@juno.com>
Subject: Re: connect to localhost failed error with Mail::Sendmail on Windows
Message-Id: <hdckh4$4rg$1@news.eternal-september.org>

Peter J. Holzer wrote:
> On 2009-11-09 09:45, ++imanshu <himanshu.garg@gmail.com> wrote:
>> On Nov 8, 11:03 pm, smallpond <smallp...@juno.com> wrote:
>>> Installation instructions for Mail::Sendmail:
>>>
>>> "At the top of Sendmail.pm, set your default SMTP server(s),
>>> unless you specify it with each message, or want to use the
>>> default (localhost)."
>> yes I wrongly assumed smtp to be so simple that the module alone could
>> handle it without another server.
> 
> That doesn't make sense. A protocol specifies how two (or more) entities
> talk to each other. In the case of a client/server protocol like SMTP,
> how a client talks to a server. Since Mail::Sendmail implements an SMTP
> client (it is used to send mail, not to receive it), it needs an SMTP
> server to talk to.
> 

It makes perfect sense.  If you see a module called Sendmail, you think
Hunh.  Maybe this module sends mail.
Don't beat up on the guy just for not knowing the guts of mail transport.
It's an easy mistake to make.




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

Date: Tue, 10 Nov 2009 22:49:21 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: connect to localhost failed error with Mail::Sendmail on Windows
Message-Id: <slrnhfjnv2.bkj.hjp-usenet2@hrunkner.hjp.at>

On 2009-11-10 21:04, Steve C <smallpond@juno.com> wrote:
> Peter J. Holzer wrote:
>> On 2009-11-09 09:45, ++imanshu <himanshu.garg@gmail.com> wrote:
>>> On Nov 8, 11:03 pm, smallpond <smallp...@juno.com> wrote:
>>>> Installation instructions for Mail::Sendmail:
>>>>
>>>> "At the top of Sendmail.pm, set your default SMTP server(s),
>>>> unless you specify it with each message, or want to use the
>>>> default (localhost)."
>>> yes I wrongly assumed smtp to be so simple that the module alone could
>>> handle it without another server.
>> 
>> That doesn't make sense. A protocol specifies how two (or more) entities
>> talk to each other. In the case of a client/server protocol like SMTP,
>> how a client talks to a server. Since Mail::Sendmail implements an SMTP
>> client (it is used to send mail, not to receive it), it needs an SMTP
>> server to talk to.
>
> It makes perfect sense.  If you see a module called Sendmail, you think
> Hunh.  Maybe this module sends mail.

That's what it does. It sends mail. So it's a client. Now you need
something which receives mail. This is called an SMTP server.

> Don't beat up on the guy just for not knowing the guts of mail transport.

He knows enough to recognize EHLO as an SMTP keyword.

	hp


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

Date: Tue, 10 Nov 2009 22:14:03 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: connect to localhost failed error with Mail::Sendmail on Windows
Message-Id: <b65ps6-6eo.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> On 2009-11-09 09:45, ++imanshu <himanshu.garg@gmail.com> wrote:
> > On Nov 8, 11:03 pm, smallpond <smallp...@juno.com> wrote:
> >> Installation instructions for Mail::Sendmail:
> >>
> >> "At the top of Sendmail.pm, set your default SMTP server(s),
> >> unless you specify it with each message, or want to use the
> >> default (localhost)."
> >
> > yes I wrongly assumed smtp to be so simple that the module alone could
> > handle it without another server.
> 
> That doesn't make sense. A protocol specifies how two (or more) entities
> talk to each other. In the case of a client/server protocol like SMTP,
> how a client talks to a server. Since Mail::Sendmail implements an SMTP
> client (it is used to send mail, not to receive it), it needs an SMTP
> server to talk to.

It's not a priori obvious that Mail::Sendmail can't (and shouldn't)
perform MX lookups and deliver the mail directly to the appropriate
mailhost. OTOH, I would say anyone who *doesn't* know this (and why)
should not be writing programs which send mail...

Ben



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

Date: Wed, 11 Nov 2009 01:42:06 -0800 (PST)
From: "++imanshu" <himanshu.garg@gmail.com>
Subject: Re: connect to localhost failed error with Mail::Sendmail on Windows
Message-Id: <1e016299-f429-44d4-a232-a3fc14f087f8@v15g2000prn.googlegroups.com>

On Nov 11, 4:14=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "Peter J. Holzer" <hjp-usen...@hjp.at>:
>
>
>
> > On 2009-11-09 09:45, ++imanshu <himanshu.g...@gmail.com> wrote:
> > > On Nov 8, 11:03=A0pm, smallpond <smallp...@juno.com> wrote:
> > >> Installation instructions for Mail::Sendmail:
>
> > >> "At the top of Sendmail.pm, set your default SMTP server(s),
> > >> unless you specify it with each message, or want to use the
> > >> default (localhost)."
>
> > > yes I wrongly assumed smtp to be so simple that the module alone coul=
d
> > > handle it without another server.
>
> > That doesn't make sense. A protocol specifies how two (or more) entitie=
s
> > talk to each other. In the case of a client/server protocol like SMTP,
> > how a client talks to a server. Since Mail::Sendmail implements an SMTP
> > client (it is used to send mail, not to receive it), it needs an SMTP
> > server to talk to.
>
> It's not a priori obvious that Mail::Sendmail can't (and shouldn't)
> perform MX lookups and deliver the mail directly to the appropriate
> mailhost. OTOH, I would say anyone who *doesn't* know this (and why)
> should not be writing programs which send mail...
>
> Ben

Thanks for the replies. The beating is well deserved :D

I understand that I need to go back to the books for this.

Thank You,
++imanshu


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

Date: Wed, 11 Nov 2009 04:08:50 -0800 (PST)
From: Prince Al <timothy.hill@gmail.com>
Subject: Exiting threads via signal
Message-Id: <cb25db8b-f0e1-47c5-bd75-4f63b14795bb@w19g2000yqk.googlegroups.com>

Hi,

I am trying to write some code that creates threads to run data load
jobs. There is also an extra thread created that watches for a
specific file to be created. When this file is found, the watcher
thread sends stop signals to all currently running threads. My code
appears to exit correctly, but I cannot seem to get the subroutine of
the SIG command to exit correctly.

We are running HP-UX and the version of Perl we have is 5.8.8 (with
thread support obviously). A cut down version of my code is below.

Thanks in advance for any help :)

Cheers

Tim

#!/opt/perl_5.8.8cu/bin/perl

use strict;
use warnings;
use threads;

my $system = "test";
my $hard_stop_file = "/tmp/$system"."_hard.stop";

if (-f $hard_stop_file) {
   unlink($hard_stop_file);
}

my $watcher_thread = threads->new(\&hard_stop_watcher);
$watcher_thread->detach();

foreach my $i (0..4) {
   threads->new(\&flock_test, $i);
}

while (scalar(threads->list()) > 0) {
   sleep 1;
}

sub flock_test {
   $SIG{'STOP'} = sub {
      print "I cannot get this to print!\n";
      threads->exit();
   };

   sleep 20;
}

sub hard_stop_watcher {
   while ( !-f $hard_stop_file) {
      sleep 1;
   }

   print "$hard_stop_file found...\n";

   foreach my $thr (threads->list) {
      print "killing $thr\n";
      $thr->kill('STOP')->detach();
   }

   threads->exit();
}



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

Date: Tue, 10 Nov 2009 20:08:26 -0800
From: Wanna-Be Sys Admin <sysadmin@example.com>
Subject: Re: good perl hosts
Message-Id: <_MqKm.10167$%j4.6763@newsfe18.iad>

Randal L. Schwartz wrote:

>>>>>> "Wanna-Be" == Wanna-Be Sys Admin <sysadmin@example.com> writes:
> 
> Wanna-Be> There are some that do offer that in a shared environment,
> 
> How could you offer mod_perl in a shared environment?  It'd be a
> shared
> interpreter!  I could load code into the CGI namespace that messes up
> your setup.
> 

The one's that offer it in a shared environment will run an Apache web
service for each user on their own port, and then they use a proxy
setup to make the requests over the default port 80 seamless.  It's not
completely uncommon to see, but most do not do this.  If it's used in a
shared environment with one web service, then yeah, it'll have all of
the scripts running as the same global web server user, which I'd not
trust at all.  In other words, as you said earlier, you'd have to have
each user (or any using mod_perl) to have their own Apache running, but
some (not many, though) shared providers do offer that.
-- 
Not really a wanna-be, but I don't know everything.


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

Date: Tue, 10 Nov 2009 23:51:15 -0700
From: Robin <robin1@cnsp.com>
To: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: good perl hosts
Message-Id: <4AFA5EE3.1060409@cnsp.com>

Sherm Pendley wrote:
> Robin <robin1@cnsp.com> writes:
> 
>> Does anybody know of any free web hosts that host perl cgi?
> 
> Dreamhost supports CGI and FastCGI for a reasonable price, and includes
> shell access so you can install your own modules.
> 
> And best of all, you can support the CamelBones Cocoa/Perl bridge by
> telling them I (sherm.pendley@gmail.com) sent you! :-)
> 
>     <http://www.dreamhost.com>
> 
> sherm--
thank you.
:-)
robin


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

Date: Tue, 10 Nov 2009 14:51:00 -0000
From: "John" <john1949@yahoo.com>
Subject: regex replace hex with &#ddd;
Message-Id: <hdbukj$dhj$1@news.albasani.net>

Hi

$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;

I'm trying to replace any character C0 to FF with &#ddd;

I cannot get the ord to evaluate.  I have appended the 'e'

Any idea what I'm doing wrong?

Regards
John







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

Date: Tue, 10 Nov 2009 07:10:15 -0800
From: sln@netherlands.com
Subject: Re: regex replace hex with &#ddd;
Message-Id: <9c0jf51labp1dctluerjbt3cc244blvcgv@4ax.com>

On Tue, 10 Nov 2009 14:51:00 -0000, "John" <john1949@yahoo.com> wrote:

>Hi
>
>$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;
>
>I'm trying to replace any character C0 to FF with &#ddd;
>
>I cannot get the ord to evaluate.  I have appended the 'e'
>
>Any idea what I'm doing wrong?
>
>Regards
>John
>
When its evaled it needs to be quoted.
Don't forget to escape the hex notation.

$x = "\xc0 \xff";
$x =~s |([\xc0-\xff])|'&#'.ord($1).';'|eg;
print $x;

-sln


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

Date: Tue, 10 Nov 2009 15:26:54 -0000
From: "John" <john1949@yahoo.com>
Subject: Re: regex replace hex with &#ddd;
Message-Id: <hdc0nu$gub$1@news.albasani.net>


<sln@netherlands.com> wrote in message 
news:9c0jf51labp1dctluerjbt3cc244blvcgv@4ax.com...
> On Tue, 10 Nov 2009 14:51:00 -0000, "John" <john1949@yahoo.com> wrote:
>
>>Hi
>>
>>$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;
>>
>>I'm trying to replace any character C0 to FF with &#ddd;
>>
>>I cannot get the ord to evaluate.  I have appended the 'e'
>>
>>Any idea what I'm doing wrong?
>>
>>Regards
>>John
>>
> When its evaled it needs to be quoted.
> Don't forget to escape the hex notation.
>
> $x = "\xc0 \xff";
> $x =~s |([\xc0-\xff])|'&#'.ord($1).';'|eg;
> print $x;
>
> -sln

Many thanks.  I completely messed up the second half.  But I see the 
solution now.

Regards
John





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

Date: Wed, 11 Nov 2009 00:19:14 GMT
From: nobody <nobody@nowhere.com>
Subject: Trying to process duplicate in flat file
Message-Id: <6qnKm.201786$Jp1.108459@en-nntp-02.dc1.easynews.com>

Given the following data in a flat file:

09020000251   Joe Smith           54 Abbey Road
05020033486   John Jones          98 New York Ave.
07020000279   George Washington   234 Washington Ave.
06020004293   Fred Flintstone     123 Bedrock Road
03020004472   Fred Jones          98 New York Ave.
06020004293   Wilma Flintstone    123 Bedrock Road


You can see that Fred and Wilma both share the same customer number and 
street address.  I'm traversing the file and looking for any duplicate 
customer numbers, such as Wilma and Fred.  If there is no duplicate, then 
just print the record and move on.  When I do encounter a duplicate I'm 
trying to print the records one after the other so the output looks like:

Name: Fred Flintstone
Address 123 Bedrock Road
Customer#: 06020004293

Name: Wilma Flintstone
Address 123 Bedrock Road
Customer#: 06020004293


Here's what I have so far which almost works, which I doubt is the best 
technique regardless.



#!/usr/bin/perl

use strict;
use warnings;

my $datafile = "$ARGV[0]";
my @file = ();
my @fields = ();
my $line;
my $custno;
my $name1;
my $addr1;

my $line2;
my $custno2;
my $name2;
my $addr2;

my $count;

open(HFILE, "<$datafile") || die "Cannot open $datafile: $!\n";

  while ( <HFILE> ) {
    push(@file, $_) if $_ =~ /[A-Za-z0-9]/;
  }

close(HFILE);

my @sortedFile = sort { $a cmp $b } @file;

foreach $line (@sortedFile) {
    
  $custno = substr($line, 0, 11);
  $name1 = substr($line, 14, 19);
  $addr1 = substr($line, 34, 20);

  #print "$custno\n";
  #print "$name1\n";
  #print "$addr1\n";


  $count = 0;

  foreach $line2 (@sortedFile) {

    $custno2 = substr($line2, 0, 11);

    if ($custno eq $custno2){
      $count++;
    }

    if ($count == 2) {
      print "$custno2\n";
      $count = 0;

      $custno2 = substr($line2, 0, 11);
      $name2 = substr($line2, 14, 19);
      $addr2 = substr($line2, 34, 20);

      print "$custno2\n";
      print "$name2\n";
      print "$addr2\n";

      $count++;
      last;

    }

  }
          
}





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

Date: Wed, 11 Nov 2009 02:10:04 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Trying to process duplicate in flat file
Message-Id: <4afa0eec$0$22903$e4fe514c@news.xs4all.nl>

nobody wrote:
> Given the following data in a flat file:
> 
> 09020000251   Joe Smith           54 Abbey Road
> 05020033486   John Jones          98 New York Ave.
> 07020000279   George Washington   234 Washington Ave.
> 06020004293   Fred Flintstone     123 Bedrock Road
> 03020004472   Fred Jones          98 New York Ave.
> 06020004293   Wilma Flintstone    123 Bedrock Road
> 
> 
> You can see that Fred and Wilma both share the same customer number and 
> street address.  I'm traversing the file and looking for any duplicate 
> customer numbers, such as Wilma and Fred.


  perl -MData::Dumper -aF'\s\s+' -nle 
'push@{$d{$F[0]}},[@F[1,2]]}{@{$d{$_}}>1or delete$d{$_}
  for keys%d;print Dumper\%d' flat.txt

$VAR1 = {
           '06020004293' => [
                              [
                                'Fred Flintstone',
                                '123 Bedrock Road'
                              ],
                              [
                                'Wilma Flintstone',
                                '123 Bedrock Road'
                              ]
                            ]
         };

-- 
Ruud


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

Date: Tue, 10 Nov 2009 23:18:21 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Trying to process duplicate in flat file
Message-Id: <slrnhfki3o.6b0.tadmc@tadbox.sbcglobal.net>

nobody <nobody@nowhere.com> wrote:


> my $datafile = "$ARGV[0]";

    perldoc -q vars

        What's wrong with always quoting "$vars"?

So then:

    my $datafile = $ARGV[0];


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 10 Nov 2009 22:18:06 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Trying to process duplicate in flat file
Message-Id: <03lkf516joos60ai0a5afikp4ok3dbccaf@4ax.com>

nobody <nobody@nowhere.com> wrote:
>Given the following data in a flat file:
>
>09020000251   Joe Smith           54 Abbey Road
>05020033486   John Jones          98 New York Ave.
>07020000279   George Washington   234 Washington Ave.
>06020004293   Fred Flintstone     123 Bedrock Road
>03020004472   Fred Jones          98 New York Ave.
>06020004293   Wilma Flintstone    123 Bedrock Road
>
>
>You can see that Fred and Wilma both share the same customer number and 
>street address.  I'm traversing the file and looking for any duplicate 
>customer numbers, such as Wilma and Fred.  If there is no duplicate, then 
>just print the record and move on.  When I do encounter a duplicate I'm 
>trying to print the records one after the other so the output looks like:
>
>Name: Fred Flintstone
>Address 123 Bedrock Road
>Customer#: 06020004293
>
>Name: Wilma Flintstone
>Address 123 Bedrock Road
>Customer#: 06020004293
>
>
>Here's what I have so far which almost works, which I doubt is the best 
>technique regardless.

So you don't really care if or how many customers are sharing the same
customer id. And each record is printed the same way, no matter if
duplicate or not. 
In that case, yes, your approach of simply sorting the lines seems quite
adequate.

>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>my $datafile = "$ARGV[0]";

Don't quote variables, there is no good reason for it.

>my @file = ();
>my @fields = ();
>my $line;
>my $custno;
>my $name1;
>my $addr1;
>
>my $line2;
>my $custno2;
>my $name2;
>my $addr2;

Don't use global variables unless there is a good reason for it. For
almost all these there is no good reason.

>my $count;
>
>open(HFILE, "<$datafile") || die "Cannot open $datafile: $!\n";
>
>  while ( <HFILE> ) {
>    push(@file, $_) if $_ =~ /[A-Za-z0-9]/;
>  }
>
>close(HFILE);
>
>my @sortedFile = sort { $a cmp $b } @file;

Sorting lexically is the default behaviour of sort() already, no reason
to mention it explicitely. 

>foreach $line (@sortedFile) {
>    
>  $custno = substr($line, 0, 11);
>  $name1 = substr($line, 14, 19);
>  $addr1 = substr($line, 34, 20);

There are other ways to split the line, but this works and looks ok to
me. 

>  #print "$custno\n";
>  #print "$name1\n";
>  #print "$addr1\n";

Are these lines relevant in any way?

>  $count = 0;
>  foreach $line2 (@sortedFile) {

What on earth are you doing with this inner loop? And what is $count
about? You don't use it for anything useful. 
Your output doesn't distinguish between the first occurence of a
customer ID and subsequent occurences. So don't bother about it, just
print each record in the sequence as it appears in the sorted array.

[snipped]

A different approach (just in case you do care if a customer ID is
duplicated or not) would be to read all customers into an HoA, using the
customer ID as the key for the hash.
And then just traverse the whole hash and print each array.

jue


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

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

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

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2670
***************************************


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