[25895] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8123 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 28 00:05:39 2005

Date: Fri, 27 May 2005 21:05:04 -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           Fri, 27 May 2005     Volume: 10 Number: 8123

Today's topics:
    Re: new how-to book about tit-fucking <rxdxv@talk21.com>
    Re: Regex - disincluding strings in a match <eric-amick@comcast.net>
        Scanning @array elements for similair content <rbutcher.nospam@hotmail.com>
    Re: Scanning @array elements for similair content <tadmc@augustmail.com>
        XP implementation bug? [was Re: too many open files?  H <derrell.spam.durrett@xilinx.killer.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 May 2005 18:58:02 -0400
From: Robert de Vincy <rxdxv@talk21.com>
Subject: Re: new how-to book about tit-fucking
Message-Id: <Xns966445E96DArdv@216.128.74.13>

Lister did write:

> On Fri, 27 May 2005 21:50:46 +0200 (CEST), "Agent 69"
> <69-no-spam@69.69.69.69.invalid> wrote:
> 
> 
> 
> Did you mean to say something or were you too busy tit fucking
> someone?

His breasts got in the way and he couldn't see the screen properly!

-- 
BdeV
"Bruce Campbell in EVIL DEAD 2 is sexually exciting."
 -- Alastair Foster, <dqg00uo8nilvdupiksn56r0gf0hu6d78si@4ax.com>


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

Date: Fri, 27 May 2005 22:17:24 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Regex - disincluding strings in a match
Message-Id: <3mkf91189gkpr7c1uf4ppuodr3lomtdlrc@4ax.com>

On Fri, 27 May 2005 23:11:17 +0200, Fabian Pilkowski
<pilkowsk@informatik.uni-marburg.de> wrote:

>* Steve Chiang schrieb:
>> 
>> How would one disinclue a string in a match?  For example, I want to match 
>> the next animal that comes after "dog", but don't want to match "dog":
>> 
>> cat cow dog monkey zebra
>> 
>> ... so I would want to match only "monkey".
>
>> Further, I am limited in that I cannot use back-references for 
>> this.
>
>You could use a technique called "zero-width positive look-behind" and
>is described in `perldoc perlre`. Unless you have perl installed on your
>system read this document at <http://perldoc.perl.org/perlre.html>.
>
>    my $string = "cat cow dog monkey zebra";
>    print $string =~ m/(?<=dog\s)\S*/g;
>    __END__
>    monkey

Almost--that will match the second "dog" in "dog dog". What you need is

print $string =~ m/(?<=dog\s)(?!dog)\S+/g;

-- 
Eric Amick
Columbia, MD


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

Date: Fri, 27 May 2005 23:41:04 GMT
From: "Randy" <rbutcher.nospam@hotmail.com>
Subject: Scanning @array elements for similair content
Message-Id: <keOle.1498106$6l.1423014@pd7tw2no>

Hello,

I have a text file that stores names and email addresses. This data is built
from a feedback form on my website. Here is the format of my textfile
entries:

Dan Smith,dan@email.com
Mike Roberts,mike@yahoo.com
Steve Anderson,steve@goto.com

and so on.

As you can see, it's pretty much a standard CSV textfile. Overtime, this
database has grown very big, and there are several duplicate email addresses
in the data. Until recently I have had to visually go through the data and
remove duplicate email addresses I can find, regardless of what is found in
the name field. I am seeking assistance on how I could write a script that
would scan each line, separate the names field from the email address field,
then scan and remove duplicates. So far all I have is the following:

#!/usr/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;

my @data, $data, $name, $email;

open (FH, "<data.txt") or die "Can't open file: $!";
  @data=<FH>;
close(FH);

foreach $data (@data) {
  chomp ($data);
  ($name,$email)=split(/\,/,$data);

\\ Missing scan for duplicates and removal code here \\
}

open (FH, ">data.txt") or die "Can't open file: $!";
  print FH @data;
close(FH);

Yes I am a newbie Perl programmer. I'm not very good at brainstorming an
approach to sorting/matching routines. I would very much appreciate some
help understanding and building the final element. Another complication is
what if there are two identical email addresses but one is all caps and the
other isn't. I'm not looking for someone to write me the code I need,
instead to point me in the right direction so that I actually learn
something and forward my Perl skills. Thankx everyone.

Robert




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

Date: Fri, 27 May 2005 21:13:29 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Scanning @array elements for similair content
Message-Id: <slrnd9fku9.e81.tadmc@magna.augustmail.com>

Randy <rbutcher.nospam@hotmail.com> wrote:

> I have a text file that stores names and email addresses.


> I am seeking assistance on how I could write a script that
> would scan each line, 


You have that already!

(though poorly done)


> separate the names field from the email address field,


You have that already too.


> then scan and remove duplicates. 


   perldoc -q duplicate

       How can I remove duplicate elements from a list or array?

(pay particular attention to the last sentence of the answer given there.)

You are expected to check the Perl FAQ *before* posting to 
the Perl newsgroup you know.


> use strict;


Very good, but you should also have:

   use warnings;

(and look in your server error logs for its output, or,
 even better, run your CGI program from the command line
 during early development, rather than in the CGI environment)


> open (FH, "<data.txt") or die "Can't open file: $!";
>   @data=<FH>;
> close(FH);
> 
> foreach $data (@data) {


It is bad practice to read an entire file into memory only to
process it line-by-line anyway.

Why not just read and process line-by-line?


>   chomp ($data);
>   ($name,$email)=split(/\,/,$data);


Whitespace is not a scarce resource, feel free to use as much of
it as you like to make your code easier to read.


> \\ Missing scan for duplicates and removal code here \\
> }


   my %emails;
   while ( my $data = <INPUT> ) {              # untested
      chomp $data;
      my($name, $email) = split(/\,/, $data);
      $emails{$email} = $name;
   }

   foreach my $adr ( sort keys %emails ) {
      print OUTPUT "$emails{$adr},$adr\n";
   }


> Yes I am a newbie Perl programmer. 


I was thinking that you are a newbie to programming itself.


> I would very much appreciate some
> help understanding and building the final element. 


Use a hash to eliminate duplicates.


> Another complication is
> what if there are two identical email addresses but one is all caps and the
> other isn't. 


You need to decide what to do, then we can help you write Perl
code that does that.

You could perhaps just normalize them all to a single case
before storing or searching the hash:

   perldoc -f uc
   perldoc -f lc


> I'm not looking for someone to write me the code I need,


Oops, too late.   :-)


> instead to point me in the right direction so that I actually learn
> something and forward my Perl skills.


A depressingly infrequent display of Good Attitude for this here group.

Good for you!  (and us)


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


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

Date: Fri, 27 May 2005 16:44:36 -0600
From: Derrell Durrett <derrell.spam.durrett@xilinx.killer.com>
Subject: XP implementation bug? [was Re: too many open files?  How to know?]
Message-Id: <d787sk$eoi21@xco-news.xilinx.com>

Derrell Durrett wrote:

> Derrell Durrett wrote:
>
>> I have a situation in which a program that executes on solaris, a 
>> RedHat flavor of Linux (32- and 64-bit), and Windows XP (32- and 
>> 64-bit) fails on 32-bit XP w/the $! value equivalent to the string 
>> "Too many open files."
>
When I replace the previous code w/File::Temp, I see the same problem.  
The XP OS complains after about 500 iterations that I've run out of file 
descriptors.  The error message isn't particularly informative: bldperl 
writestderr exitted with 16777215 and core dumped from signal 127, where 
writestderr is the following:

use strict;
use warnings;

print STDERR q[I'm freaking out!   ];
die "Still!\n";

and bldperl is a simple wrapper around perl.

Has anyone else seen this problem?  I can work around it using real 
files to capture stdout and stderr, but since there are often cases 
where I am trying to do this on multiple machines over a short amount of 
time in a shared network directory.  IO::File's tmpfile (if I understood 
the docs correctly) was using memory to create these files, not real 
files.  If it was doing it w/real files, at least I didn't have to think 
of algorithms that make the files just more likely to be unique.  In any 
case, I preferred that method, and for NT it worked.  For SunOS 5.8 it 
works.  For RedHat 7.2 (or whatever the Enterprise equivalent is that 
we're using now), it works.

I found (but lost and cannot find again) a mention that some file 
related module was not available for XP, and it sounded potentially 
related to this.

If anyone has had an experience w/XP similar to this, where the error 
"Too many open files" has appeared even though you're sure you're 
closing them (if because they go out of scope, if nothing else), I'd be 
interested in comparing notes.

Thanks,

Derrell

-- 
Derrell Durrett
Xilinx, Inc. / Software Productivity Tools
Longmont, Colorado / 720.652.3843
***remove bits about .processed meats and .death from e-mail to reply


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

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


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