[27574] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9106 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 30 14:05:49 2006

Date: Thu, 30 Mar 2006 11:05:05 -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           Thu, 30 Mar 2006     Volume: 10 Number: 9106

Today's topics:
    Re: A Problem With GD <markem@airmail.net>
    Re: file renamer... request feedback (Anno Siegel)
    Re: file renamer... request feedback <rvtol+news@isolution.nl>
    Re: Find duplicates in a dat file Tami@des.com
    Re: Find duplicates in a dat file <1usa@llenroc.ude.invalid>
    Re: NetServer::Generic  -- welcome message ?? <babacio@free.fr>
    Re: NetServer::Generic  -- welcome message ?? (Anno Siegel)
    Re: NetServer::Generic  -- welcome message ?? <babacio@free.fr>
        OT: Copyright protection (was Re: A Problem With GD) <RedGrittyBrick@SpamWeary.foo>
    Re: Where to put Settings-Variables? <zawrotny@sb.fsu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 30 Mar 2006 12:13:13 -0600
From: Mark Manning <markem@airmail.net>
Subject: Re: A Problem With GD
Message-Id: <122o7r8j03ptr7e@corp.supernews.com>

Yeah, I think he did.  :-)  Been a hectic week at work.  Lots of things 
happening.  We are wrapping up all projects for this launch.  Going to be 
unemployed for three months as the contract I am working on has gone into limbo 
while the contract is awarded to another company.  Once that is done we will be 
coming back to NASA again for the next launch.  Think I'll take a vacation and 
go see parts of the US I haven't been to in a long time.  Hope you have fun 
robic0 et al!  :-)

robic0 wrote:
> On Sat, 25 Mar 2006 10:52:03 -0500, "John W. Kennedy" <jwkenne@attglobal.net> wrote:
> 
> 
>>robic0 wrote:
>>
>>>19th century was between 1800-1899 wasn't it?
>>
>>No, from 1801 to 1900.
> 
> 
> So did you mean the 20th century?



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

Date: 30 Mar 2006 12:16:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: file renamer... request feedback
Message-Id: <4920g0Fm8m6mU1@news.dfncis.de>

Dr.Ruud <rvtol+news@isolution.nl> wrote in comp.lang.perl.misc:
> TOC schreef:
> 
> >     my $o = $_;
> >     $_ = lc $_;
> 
> Can be combined:     my $o = lc;
> (see `perldoc -f lc`)
> 
> 
> >                 s/^(.*)\.(.*)$/$1_.$2/
> 
> No need for the second capture group:
> 
>                   s/^(.*)\./$1_./
> 
> No need even for the first:
> 
>                   s/\.(?=[^.]*$)/_./
> 
> Test: echo 'abc.def.ghi' | perl -pe 'chomp; s/\.(?=[^.]*$)/_./'
> 
> (I haven't benchmarked them, but it feels 'just good' to avoid
> capturing.)

Your intuition is right on the mark there.  It isn't benchmarks that speak
for or against one alternative or the other but conceptual simplicity or,
almost equivalently, readability and general neatness.

From that point of view, I'd draw the line at your first alternative.  It
expresses directly what is going to happen.  The lookahead variant is
harder to understand.

If timing is really the issue, that's when readability and neatness go
overboard and we'll use what screams, to use one of Larry Wall's favorite
expressions.  But that applies only locally to hot spots found by profiling,
never to the style of a whole program, and never before the whole program
works correctly.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 30 Mar 2006 16:49:57 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: file renamer... request feedback
Message-Id: <e0h2cb.1q4.1@news.isolution.nl>

Anno Siegel schreef:
> Dr.Ruud:
>> TOC:

>>>                 s/^(.*)\.(.*)$/$1_.$2/
>>
>> No need for the second capture group:
>>
>>                   s/^(.*)\./$1_./
>>
>> No need even for the first:
>>
>>                   s/\.(?=[^.]*$)/_./
>>
>> Test: echo 'abc.def.ghi' | perl -pe 'chomp; s/\.(?=[^.]*$)/_./'
>>
>> (I haven't benchmarked them, but it feels 'just good' to avoid
>> capturing.)
>
> Your intuition is right on the mark there.  It isn't benchmarks that
> speak for or against one alternative or the other but conceptual
> simplicity or, almost equivalently, readability and general neatness.
>
> From that point of view, I'd draw the line at your first alternative.
> It expresses directly what is going to happen.  The lookahead variant
> is harder to understand.

I was tempted for a second to leave out the '^' from that first
alternative, and to use $& for the matched dot in the second (since its
penalty is rather small), but both felt just too pedantic.
:)

For me, the lookahead variant is not harder to understand, so I use it
freely in my code.


> If timing is really the issue, that's when readability and neatness go
> overboard and we'll use what screams, to use one of Larry Wall's
> favorite expressions.  But that applies only locally to hot spots
> found by profiling, never to the style of a whole program, and never
> before the whole program works correctly.

I fully agree.

Both alternatives could use a remark like
  # replace the very last <dot> by <underscore><dot>
to show what was meant to achieve. With many regular expressions it is
good to simply mention what they are supposed to do.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Thu, 30 Mar 2006 15:14:48 GMT
From: Tami@des.com
Subject: Re: Find duplicates in a dat file
Message-Id: <cpln22larub877b5e43a2f9e45mdhfq9ns@4ax.com>

On 30 Mar 2006 08:24:30 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

>Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
>> axel@white-eagle.invalid.uk <axel@white-eagle.invalid.uk> wrote:
>> > Tami@des.com wrote:
>> >>>If you concatenated all the files into a single file, this should work
>> 
>> > Or you could pipe the files into a perl script:
>> > 
>> > 	cat *.dat | myscript.pl
>> > 
>> > and read the data from standard input.
>> 
>> 
>> Or you could put the filenames as command line arguments
>> and read the data from the diamond operator.
>> 
>>    myscript.pl *.dat
>> 
>> (well, you could if you had a sensible shell.)
>
>The problem with concatenating all files together is that it tells
>you whether there are duplicate mail addresses, but not which users
>the duplicates belong to.  With the files in @ARGV, the $ARGV variable
>can be used to capture at least the file names the duplicates come from.
>Untested:
>
>    my %seen;
>    push $seen->{ $1}, $ARGV if /(.*@.*)/;
>    while ( my ( $addr, $files) = each %seen ) {
>        print "$addr found in files @$files\n" if @$files > 1;
>    }
>
>Anno
>     

Hi Anno

Ho  dear me I have got so confused with all this help over this script.

I have run most of what has been said in the replies BUT I still cannot get to work.

Some of the help scripts just sit there and do nothing.

I get "premature end of script headers" in most of the scripts that have been suggested.

I have run this from Fire Fox on my Apache server ASLO inside Perl Builder

I have got all my paths to perl correct and when I look in the log files that is all it
tells me.

Yes you are so correct about 
>but not which users
>the duplicates belong to

That is just what I want.

Now I'm confused (Only a dum blond ) do I put your script in with the other suggestions or
what.

just to let you know a bit more I have my data files like this

c:/1test/user/
xxx.dat
xxx.dat

etc etc

Thank you so much

Tami




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

Date: Thu, 30 Mar 2006 15:26:48 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Find duplicates in a dat file
Message-Id: <Xns97966A651548asu1cornelledu@127.0.0.1>

Tami@des.com wrote in news:cpln22larub877b5e43a2f9e45mdhfq9ns@4ax.com:

> On 30 Mar 2006 08:24:30 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote: 
> 
>>Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
>>> axel@white-eagle.invalid.uk <axel@white-eagle.invalid.uk> wrote:
>>> > Tami@des.com wrote:
>>> >>>If you concatenated all the files into a single file, this should
>>> >>>work 
>>> 
>>> > Or you could pipe the files into a perl script:
>>> > 
>>> >      cat *.dat | myscript.pl
>>> > 
>>> > and read the data from standard input.
>>> 
>>> 
>>> Or you could put the filenames as command line arguments
>>> and read the data from the diamond operator.
>>> 
>>>    myscript.pl *.dat
>>> 
>>> (well, you could if you had a sensible shell.)
>>
>>The problem with concatenating all files together is that it tells
>>you whether there are duplicate mail addresses, but not which users
>>the duplicates belong to.  With the files in @ARGV, the $ARGV variable
>>can be used to capture at least the file names the duplicates come
>>from. Untested:
>>
>>    my %seen;
>>    push $seen->{ $1}, $ARGV if /(.*@.*)/;
>>    while ( my ( $addr, $files) = each %seen ) {
>>        print "$addr found in files @$files\n" if @$files > 1;
>>    }
>>
>>Anno
>>     

 ...

> Some of the help scripts just sit there and do nothing.
> 
> I get "premature end of script headers" in most of the scripts that
> have been suggested. 

Those error messages in the server log might contain helpful 
information.

AFAIK, none of the proposed solutions, including mine, were set CGI 
scripts.
 
> I have run this from Fire Fox 

You don't run CGI scripts in the web browser.

> on my Apache server ASLO inside Perl Builder 

Why not try them from the command line, and make a note of any 
errors/warnings you get.

Sinan


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

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



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

Date: Thu, 30 Mar 2006 14:13:30 +0200
From: Babacio <babacio@free.fr>
Subject: Re: NetServer::Generic  -- welcome message ??
Message-Id: <m24q1gqget.fsf@baba.ba>


More precisely, I would appreciate any suggestion of a simple
way to run a forked/preforked tcp server, that would behave 
like the following one. (Any comment on the code is welcome
as well).

use IO::Socket;

my $server = IO::Socket::INET->new(LocalPort => 9101,
                                Type      => SOCK_STREAM,
                                Reuse     => 1,
                                Listen    => 10 )
    or die "$@\n";

while (my $client = $server->accept()) {
  print $client "Welcome! Say 'quit' to leave.\n";
  while(1) {  
    my $x = <$client>;
    last if $x =~ /^quit/i;
    $x =~ s/[\r|\n]//g; 
    print $client "You said $x!\n";
  }
}

close($server);

-- 
Ouah, ouah, ouah.


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

Date: 30 Mar 2006 12:54:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: NetServer::Generic  -- welcome message ??
Message-Id: <4922o3Fmis0hU1@news.dfncis.de>

Babacio  <babacio@free.fr> wrote in comp.lang.perl.misc:
> 
> More precisely, I would appreciate any suggestion of a simple
> way to run a forked/preforked tcp server, that would behave 
> like the following one. (Any comment on the code is welcome
> as well).
> use IO::Socket;
> 
> my $server = IO::Socket::INET->new(LocalPort => 9101,
>                                 Type      => SOCK_STREAM,
>                                 Reuse     => 1,
>                                 Listen    => 10 )
>     or die "$@\n";
> 
> while (my $client = $server->accept()) {
>   print $client "Welcome! Say 'quit' to leave.\n";

Why did you put this interaction outside the client loop?

>   while(1) {  
>     my $x = <$client>;
>     last if $x =~ /^quit/i;

I'd put that last, so the "quit" interaction is logged as well.

>     $x =~ s/[\r|\n]//g; 
>     print $client "You said $x!\n";
>   }
> }
> 
> close($server);

To make a plain forked server, there isn't much to add.  Just run
the client loop ("while ( 1 )...") in a forked process and exit after
the loop.  Add a sigchld handler against zombies and error checking
and you're basically done.  This is the loop (marginally tested)


    $SIG{ CHLD} = 'IGNORE'; # good enough on most systems

    while (my $client = $server->accept()) {
      if ( my $pid = fork ) {
          # parent does nothing here
      } else {
          print $client "Welcome! Say 'quit' to leave.\n";
          die "can't fork" unless defined $pid;
          while(1) { 
            my $x = <$client>;
            $x =~ s/[\r|\n]//g; 
            print $client "(pid $$) You said $x!\n";
            last if $x =~ /^quit/i;
          }
          exit;
      }
    }

If you need the ability for every client process to shut down the main
server, kill() the main process through an appropriate signal from the
child.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 30 Mar 2006 15:12:31 +0200
From: Babacio <babacio@free.fr>
Subject: Re: NetServer::Generic  -- welcome message ??
Message-Id: <m2zmj8oz40.fsf@baba.ba>

(Anno Siegel)

>> use IO::Socket;
>> 
>> my $server = IO::Socket::INET->new(LocalPort => 9101,
>>                                 Type      => SOCK_STREAM,
>>                                 Reuse     => 1,
>>                                 Listen    => 10 )
>>     or die "$@\n";
>> 
>> while (my $client = $server->accept()) {
>>   print $client "Welcome! Say 'quit' to leave.\n";
>
> Why did you put this interaction outside the client loop?

I don't want it to be printed out at each line, only at 
connection. (A "welcome message").

>>   while(1) {  
>>     my $x = <$client>;
>>     last if $x =~ /^quit/i;
>
> I'd put that last, so the "quit" interaction is logged as well.

Yes, that may be more elegant.

>>     $x =~ s/[\r|\n]//g; 
>>     print $client "You said $x!\n";
>>   }
>> }
>> 
>> close($server);
>
> To make a plain forked server, there isn't much to add.  Just run
> the client loop ("while ( 1 )...") in a forked process and exit after
> the loop.  Add a sigchld handler against zombies and error checking
> and you're basically done.  This is the loop (marginally tested)

Mmmh. OK. I may use this solution. Thanks a lot.

-- 
Ouah, ouah, ouah.


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

Date: Thu, 30 Mar 2006 19:34:42 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: OT: Copyright protection (was Re: A Problem With GD)
Message-Id: <BYSdndGaNt61vrHZRVnyig@bt.com>

robic0 wrote:
> On Sat, 25 Mar 2006 10:52:03 -0500, "John W. Kennedy" <jwkenne@attglobal.net> wrote:
> 
> 
>>robic0 wrote:
>>
>>>19th century was between 1800-1899 wasn't it?
>>
>>No, from 1801 to 1900.
> 
> 
> So did you mean the 20th century?

He really does mean the 19th century. The Berne convention was first 
adopted in 1886, over a hundred years before the US adopted it.


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

Date: 30 Mar 2006 17:00:21 GMT
From: Michael Zawrotny <zawrotny@sb.fsu.edu>
Subject: Re: Where to put Settings-Variables?
Message-Id: <slrne2o3l5.e37.zawrotny@localhost.localdomain>

Bernd Schneider wrote:

[ snip ]
>  So I decided to put some stuff into modules.
> 
>  The problem that I now come up with is:
>  Where do I put the variables?
> 
>  Before I just declared them as:
>  my $mysql_host = 'localhost';
[ snip ]

I would put them in a config file and use one of the many config file
parsing modules on CPAN (e.g. Config::Simple).


Mike

-- 
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University                | email:  zawrotny@sb.fsu.edu
Tallahassee, FL 32306-4380              | phone:  (850) 644-0069


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

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


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