[23085] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5306 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 1 14:06:14 2003

Date: Fri, 1 Aug 2003 11:05:08 -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, 1 Aug 2003     Volume: 10 Number: 5306

Today's topics:
        ccperl Mailing <erik.waibel@cubic.com>
    Re: ccperl Mailing <mikeflan@earthlink.net>
    Re: ccperl Mailing <erik.waibel@cubic.com>
    Re: how can I use modules without installation? <cwilbur@mithril.chromatico.net>
    Re: ip address to netbios name <vladimir@NoSpamPLZ.net>
    Re: mod_perl: my $var=1 if ... <kjetilskotheim@yahoo.com>
    Re: Need help with Symbol::delete_package <newspost@coppit.org>
        No Question - Just Posting some Code I'm Proud of <mikeflan@earthlink.net>
    Re: No Question - Just Posting some Code I'm Proud of <nobull@mail.com>
    Re: No Question - Just Posting some Code I'm Proud of (Greg Bacon)
    Re: No Question - Just Posting some Code I'm Proud of <usenet@dwall.fastmail.fm>
    Re: No Question - Just Posting some Code I'm Proud of <usenet@dwall.fastmail.fm>
    Re: No Question - Just Posting some Code I'm Proud of <nobull@mail.com>
        Parse Text File and Output to File <jlembo@rochester.rr.com>
    Re: Parse Text File and Output to File <trammell+usenet@hypersloth.invalid>
    Re: Parse Text File and Output to File <nobull@mail.com>
    Re: Pb $SIG{CHLD}=sub{wait()}; in Perl 5.8.0 <spp@monaco377.com>
    Re: Perl Project Logic Question <tylercruz@hotmail.com>
    Re: Substitution Question <krahnj@acm.org>
    Re: Wait for directory changes in Windows XP? <no@email.com>
    Re: Web development and Perl 6 <flavell@mail.cern.ch>
    Re: Web development and Perl 6 <jimbo@soundmiges.co.uk>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 01 Aug 2003 15:17:16 GMT
From: "Erik Waibel" <erik.waibel@cubic.com>
Subject: ccperl Mailing
Message-Id: <0wvWa.4648$Dm5.80877691@newssvr13.news.prodigy.com>

Hello,

I was wondering if there is a way to send an email (with or without an
attachment) using "ccperl5.0"?  I've seen the modules, but there
instructions aren't very informative.

-- 
Thanks,
Erik Waibel
----------
Perl Hacker v.1.0




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

Date: Fri, 01 Aug 2003 15:50:25 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: ccperl Mailing
Message-Id: <3F2A8CCD.B881354F@earthlink.net>


Sendmail.pm   (use Mail::Sendmail;)
worked for me (without an attachment) on a Win2000 box.
Just install the module from:
http://search.cpan.org/search?module=Mail::Sendmail

and use the "Another Example" that they supply.

I'd like to hear how to attached a file to the message.


Mike


Erik Waibel wrote:

> Hello,
>
> I was wondering if there is a way to send an email (with or without an
> attachment) using "ccperl5.0"?  I've seen the modules, but there
> instructions aren't very informative.
>
> --
> Thanks,
> Erik Waibel
> ----------
> Perl Hacker v.1.0



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

Date: Fri, 01 Aug 2003 17:05:06 GMT
From: "Erik Waibel" <erik.waibel@cubic.com>
Subject: Re: ccperl Mailing
Message-Id: <65xWa.4666$SW5.83025240@newssvr13.news.prodigy.com>

Mike,

The problem with this is that we need to only use the modules that come with
the standard ccperl5.0 install.  We have a program called "ClearCase", which
is a file managing program, and we run Perl scripts within this program
using ccperl5.0, which gets installed on a user's computer with the
ClearCase installation.  There are only a few mail modules that come with
the standard installation and I need to be able to only use these modules.
The instructions within the modules are confusing at best.

-- 
Thanks,
Erik Waibel
----------
Perl Hacker v.1.0
"Mike Flannigan" <mikeflan@earthlink.net> wrote in message
news:3F2A8CCD.B881354F@earthlink.net...
>
> Sendmail.pm   (use Mail::Sendmail;)
> worked for me (without an attachment) on a Win2000 box.
> Just install the module from:
> http://search.cpan.org/search?module=Mail::Sendmail
>
> and use the "Another Example" that they supply.
>
> I'd like to hear how to attached a file to the message.
>
>
> Mike
>
>
> Erik Waibel wrote:
>
> > Hello,
> >
> > I was wondering if there is a way to send an email (with or without an
> > attachment) using "ccperl5.0"?  I've seen the modules, but there
> > instructions aren't very informative.
> >
> > --
> > Thanks,
> > Erik Waibel
> > ----------
> > Perl Hacker v.1.0
>




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

Date: Fri, 01 Aug 2003 15:25:58 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: how can I use modules without installation?
Message-Id: <87el05tnee.fsf@mithril.chromatico.net>

"À±ÂùÈ£" <goodman@widewings.com> writes:

> hi~
> 
> I want to use module in linux.  but I can't install modules.

> I'm not administrator, I have normal user account.

Suggestion #1:  perldoc -q 'my own module'

Suggestion #2: talk to a system administrator.

Charlton


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

Date: Fri, 01 Aug 2003 15:15:18 GMT
From: lostriver <vladimir@NoSpamPLZ.net>
Subject: Re: ip address to netbios name
Message-Id: <auvWa.21859$s_6.239185@weber.videotron.net>

On Fri, 1 Aug 2003 17:13:53 +0300, Mike wrote:
> Greetings, I was wondering if it were possible to resolve an ip address to a
> netbios name.  The perl script would be running on a unix machine.
> 
> Any help would be appreciated.

You can always fork 'nmblookup -A' ( comes with samba ) from your perl script.

-- 
 .signature: No such file or directory


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

Date: Fri, 01 Aug 2003 17:29:28 +0200
From: Kjetil Skotheim <kjetilskotheim@yahoo.com>
Subject: Re: mod_perl: my $var=1 if ...
Message-Id: <oprs8fzexm85yxzq@nntp.uio.no>

On Thu, 31 Jul 2003 21:48:35 -0700, Keith Keller <kkeller- 
spammmm@wombat.san-francisco.ca.us> wrote:

> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> In article <oprs7if8d985yxzq@nntp.uio.no>, Kjetil Skotheim wrote:
>> I'm having trouble understanding something in mod_perl. The sub handler 
>> is:
>>
>> sub handler
>> {
>>
>> ...stuff deleted...
>>
>> my $var=1 if ...condition_A...;
>> $var=2 if ...condition_B...;   if($var){
>> ...someting....
>> }
>>
>> }
>>
>> The IF-block are entered sometimes when both condition_A and B
>> are false! How can that be? If I do the following instead then
>> everyting works ok:
>>
>> my $var; #lexical declaration without if
>> $var=1 if ...condition_A...;
>> $var=2 if ...condition_B...;
>>
>> I suspect that $var is preserved from the previous apache-request
>> on the same process. Can anyone confirm this?
>
> I'm not sure that's what's going on.  It would help to know what
> condition_A and condition_B were--there are probably variables
> surviving in the httpd process that are influencing the conditions
> in ways you aren't expecting, thus causing $var to be set.  Since
> we don't know what your conditions are, though, it's tough to tell.


Well, I tried not to be one of those who post articles
with just "help!" and then dumps tons of code.
My mod_perl app behaves different when I change this:

	my $var=1 if ...condition_A...;
	$var=2 if ...condition_B...;

Into this (which works as intended):

	my $var;
	$var=1 if ...condition_A...;
	$var=2 if ...condition_B...;

Thats all there is to know I think.
The conditions are simple "and"'s on other variables than $var.


>
> It would certainly help to post a test case with real code instead
> of condition_[AB], and perhaps to check your error_log.  If you
> find a real problem, I'd also recommend the mod_perl mailing list
> (findable from perl.apache.org).
>
>> Should "my $var=... if ..." be totally avoided in mod_perl?
>
> I personally don't think it's such a great style, but I don't
> know if it's something definitely to be avoided.
>
> - --keith
>
> - -- kkeller-mmmspam@wombat.san-francisco.ca.us
> (try just my userid to email me)
> alt.os.linux.slackware FAQ:  http://wombat.san-francisco.ca.us/cgi- 
> bin/fom
>
> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iEYEARECAAYFAj8p8RsACgkQhVcNCxZ5ID8WxACeJMM5HxMH+V1GkMeSO0Lql33v
> hSAAn3WjaMjs1sgXDXRl+IEKIqCFd6zI
> =5phS
> -----END PGP SIGNATURE-----
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


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

Date: Fri, 01 Aug 2003 17:58:18 GMT
From: David Coppit <newspost@coppit.org>
Subject: Re: Need help with Symbol::delete_package
Message-Id: <Pine.BSF.4.56.0308011348450.76650@www.provisio.net>

Okay, I guess I'm not clear. Let me start all over:

When running the following script,

  use Symbol;

  require Storable;
  Symbol::delete_package('Storable');

  # Delete everything just to be safe.
  map { delete $INC{$_} } keys %INC;

  require Storable;
  Storable::freeze([1,2,3]);

I get the following error:

  Undefined subroutine &Storable::freeze called at test.pl line 12.

I was expecting the freeze function to be available after require'ing
Storable the second time. (i.e. no error)

Here are some details of my configuration:

  $ perl -V
  Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
    Platform:
      osname=linux, osvers=2.4.18-11smp, archname=i386-linux-thread-multi
      uname='linux daffy.perf.redhat.com 2.4.18-11smp #1 smp thu aug 15 06:41:59 edt 2002 i686 i686 i386 gnulinux '

Thanks,
David


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

Date: Fri, 01 Aug 2003 15:39:46 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: No Question - Just Posting some Code I'm Proud of
Message-Id: <3F2A8A4E.C7CBEF6E@earthlink.net>


I'm just posting some code I wrote and asking for any advice
you might have.  It may not work perfectly, but it's got me
fooled into thinking it does.  Keep in mind I hadn't even
heard of Perl until about 50 days ago.

Believe it or not, I'm kinda proud of this code.  That's only
because I know how much improved it is over my first
draft.  If anybody has any suggestions, I want them.

_______________________________________

# This file takes a CSV file,
# removes offending characters from the name fields
# and gives the 6 digit names field unique names.
# It also shortens the long name field a little.

use strict;
use warnings;

my $rep = 1;
my $file = "bran2.csv";
my (@temp, $temp);
open WPIN,"<$file" or die "Can't create $file: $!";

while (<WPIN>) {
   my ($wp1, $deg1, $name1, $lat, $long, $date, $time, $name2) = split
/,/, $_, 8;
   push @temp, ($wp1, $deg1, $name1, $lat, $long, $date, $time, $name2);

}


# Replace bad characters
for (my $turn = 10; $turn <= $#temp; $turn+=8) {
    $temp[$turn] =~ tr/()#.:\/?'&!//d;
    $temp[$turn+5] =~ s/\(historical\)/\(hist\)/g;
    $temp[$turn+5] =~ s/\(abandoned\)/\(aban\)/g;
    $temp[$turn+5] =~ s/National Recreation Area/NRA/g;
    $temp[$turn+5] =~ s/Cemetery/Cem/g;
    $temp[$turn+5] =~ s/ North / N /g;
    $temp[$turn+5] =~ s/ North$/ N/g;
    $temp[$turn+5] =~ s/^North /N /g;
    $temp[$turn+5] =~ s/ South / S /g;
    $temp[$turn+5] =~ s/ South$/ S/g;
    $temp[$turn+5] =~ s/^South /S /g;
    $temp[$turn+5] =~ s/ East / E /g;
    $temp[$turn+5] =~ s/ East$/ E/g;
    $temp[$turn+5] =~ s/^East /E /g;
    $temp[$turn+5] =~ s/ West / W /g;
    $temp[$turn+5] =~ s/ West$/ W/g;
    $temp[$turn+5] =~ s/^West /W /g;
    $temp[$turn+5] =~ s/High School/HS/g;
    $temp[$turn+5] =~ s/Community College/College/g;
    $temp[$turn+5] =~ s/Campground/Campgr/g;
    $temp[$turn+5] =~ s/Post Office/PO/g;
    $temp[$turn+5] =~ s/Junior/Jr/g;
    $temp[$turn+5] =~ s/Mountain/Mtn/g;
}


# Rename duplicate name1's
for (my $turn = 10; $turn <= $#temp; $turn+=8) {
    next if ($temp[$turn] ne $temp[$turn-8]);
    $rep++;
    if (length $temp[$turn-8] > 3){
        substr ($temp[$turn-8], 4, 2, "0$rep") if ($rep < 10);
        substr ($temp[$turn-8], 4, 2, "$rep")if ($rep > 9);
        $rep = 1 if ($temp[$turn] ne $temp[$turn+8]);
    }
    else {
        $temp[$turn-8] =~ s/^(.{0,4})$/${1}0$rep/ if ($rep < 10);
        $temp[$turn-8] =~ s/^(.{0,4})$/${1}$rep/ if ($rep > 9);
        $rep = 1 if ($temp[$turn] ne $temp[$turn+8]);
    }
}

# print to the wpout.txt file
open WPOUT,">WPout.txt" or die "Can't create WPout.txt: $!";

foreach my $printout ( @temp ) {
    if ($printout =~ /\n$/) {print WPOUT ("$printout")}
    else {print WPOUT ("$printout,")}
}

close (WPOUT);

__END__

_______________________________________


If anybody feels like messing with this, here is some
good data to put in 'bran2.csv' to test it:

Datum,WGS84,WGS84,0,0,0,0,0
WP,DMS,Adkins,35.5143,-93.4256,12/31/1989,0:00:00,Adkins Cemetery
WP,DMS,Adkins,35.2233,-93.4800,12/31/1989,0:00:00,Aetna Gas Field
(historical)
WP,DMS,Adkins,36.0800,-93.4042,12/31/1989,0:00:00,Alabam School hist
WP,DMS,Adkins,36.3807,-93.1326,12/31/1989,0:00:00,Alexander Park
WP,DMS,Adkins,35.2546,-94.0115,12/31/1989,0:00:00,Anice hist
WP,DMS,Bakhom,33.4855,-94.3659,12/31/1989,0:00:00,Bakhoma Recreation
West
WP,DMS,Ba/ld ,35.1131,-94.4803,12/31/1989,0:00:00,Bald Knob
WP,DMS,B/??i,35.2700,-94.4352,12/31/1989,0:00:00,East Baldridge Mountain

WP,DMS,Bali,38.4356,-90.4107,12/31/1989,0:00:00,Barbs Northhampton House

WP,DMS,Basin ,36.1758,-93.2119,12/31/1989,0:00:00,Mountain Spring
WP,DMS,B&&t)e,35.3608,-93.4713,12/31/1989,0:00:00,Eastmore Springs
WP,DMS,Be!r(C,36.1751,-93.1059,12/31/1989,0:00:00,Bear West Springs


I thought I could replace:
    $temp[$turn+5] =~ s/ East / E /g;
    $temp[$turn+5] =~ s/ East$/ E/g;
    $temp[$turn+5] =~ s/^East /E /g;
with:
$temp[$turn+5] =~ s/([^|\s])East(\s)/$1E$2/g;

but it did not work for me  :-(

$temp[$turn+5] =~ s/(\s)East(\s)/$1E$2/g;
almost works, but not quite since it doesn't work if
"East" is the first thing in the string.


My next step is to push $lat and $long together and
print a file of records that have the same $lat . $long
Probably pretty easy, but I may have to do brute force
way if I don't get smart on hashes real soon.


Mike




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

Date: 01 Aug 2003 17:48:01 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: No Question - Just Posting some Code I'm Proud of
Message-Id: <u91xw5fhoe.fsf@wcl-l.bham.ac.uk>

Mike Flannigan <mikeflan@earthlink.net> writes:

> I'm just posting some code I wrote and asking for any advice
> you might have.  It may not work perfectly, but it's got me
> fooled into thinking it does.  Keep in mind I hadn't even
> heard of Perl until about 50 days ago.

With that in mind it is very good.  You are however not thinking in
Perl.  You are thinking in some other language and translating.

> 
> Believe it or not, I'm kinda proud of this code.  That's only
> because I know how much improved it is over my first
> draft.  If anybody has any suggestions, I want them.
> 
> _______________________________________
> 
> # This file takes a CSV file,
> # removes offending characters from the name fields
> # and gives the 6 digit names field unique names.
> # It also shortens the long name field a little.
> 
> use strict;
> use warnings;
> 
> my $rep = 1;
> my $file = "bran2.csv";
> my (@temp, $temp);

The variable $temp is never used as far as I can see.

Having two variables of the same name (@temp and $temp) can be
confusing.  I do it myself sometimes but I usually feel guilty.

@temp is not a good name for a variable - especially not a good name
for the longest lived variable in your whole program.

> open WPIN,"<$file" or die "Can't create $file: $!";

The word "create" should be "read".

Bareword filehandles and 2-argument open are no last-centuary :-).
(IMHO they should only be used where bacward compatability is an issue).

  open my $wpin,'<',$file or die "Can't read $file: $!";


> while (<WPIN>) {
>    my ($wp1, $deg1, $name1, $lat, $long, $date, $time, $name2) = split
> /,/, $_, 8;
>    push @temp, ($wp1, $deg1, $name1, $lat, $long, $date, $time, $name2);
> 
> }

Using 8 scalars to hold a list is a bad idea, use an array.

Abusing a 8*n element 1D array as a n x 8 element 2D array is a bad
idea, use a 2D array.

You also don't need to worry about the 8 if you do this.

You probably should chomp your incomming data.

 while (<$wpin>) {
     chmop;
     push @temp, [ split /,/ ];
 }


> # Replace bad characters
> for (my $turn = 10; $turn <= $#temp; $turn+=8) {
>     $temp[$turn] =~ tr/()#.:\/?'&!//d;
>     $temp[$turn+5] =~ s/\(historical\)/\(hist\)/g;
>     $temp[$turn+5] =~ s/\(abandoned\)/\(aban\)/g;
>     $temp[$turn+5] =~ s/National Recreation Area/NRA/g;
>     $temp[$turn+5] =~ s/Cemetery/Cem/g;
>     $temp[$turn+5] =~ s/ North / N /g;
>     $temp[$turn+5] =~ s/ North$/ N/g;
>     $temp[$turn+5] =~ s/^North /N /g;
>     $temp[$turn+5] =~ s/ South / S /g;
>     $temp[$turn+5] =~ s/ South$/ S/g;
>     $temp[$turn+5] =~ s/^South /S /g;
> }

If you'd used a 2D array could iterate of the _elements_ of a list
directly - would not need to faff about with array subscripts.

Why do you start at 10 not 2?  If you want to discard the top row (a
legend?) then I would take it out of @temp and put it in a diffent
variable.

You can relpace lots of =~ with for()
   
   $wibble =~ s/this/that/;
   $wibble =~ s/cat/dog/;

 ..becomes..

    for ( $wibble ) {
       s/this/that/;
       s/cat/dog/;
    }

You can use ORs in regular expressions;   

        s/ North / N /g;
        s/ North$/ N/g;
        s/^North /N /g;

  .. is nearly the same as ..
        s/(^| )North( |$)/$1N$2/g; 

But you may want to consider using \b instead

        s/\bNorth\b/N/g; 


So putting it together...

  my $legend = shift @temp;
  for ( @temp ) {
    $_->[2] =~ tr/()#.:\/?'&!//d;
    for ( $_->[7] ) {
      s/\(historical\)/\(hist\)/g;
      s/\bNorth\b/N/g;
      # etc....
    }
  } 
 
> # Rename duplicate name1's
> for (my $turn = 10; $turn <= $#temp; $turn+=8) {
>     next if ($temp[$turn] ne $temp[$turn-8]);
>     $rep++;
>     if (length $temp[$turn-8] > 3){
>         substr ($temp[$turn-8], 4, 2, "0$rep") if ($rep < 10);
>         substr ($temp[$turn-8], 4, 2, "$rep")if ($rep > 9);
>         $rep = 1 if ($temp[$turn] ne $temp[$turn+8]);
>     }
>     else {
>         $temp[$turn-8] =~ s/^(.{0,4})$/${1}0$rep/ if ($rep < 10);
>         $temp[$turn-8] =~ s/^(.{0,4})$/${1}$rep/ if ($rep > 9);
>         $rep = 1 if ($temp[$turn] ne $temp[$turn+8]);
>     }
> }

I'm not going to try to understand that.

> 
> # print to the wpout.txt file
> open WPOUT,">WPout.txt" or die "Can't create WPout.txt: $!";
> 
> foreach my $printout ( @temp ) {
>     if ($printout =~ /\n$/) {print WPOUT ("$printout")}
>     else {print WPOUT ("$printout,")}
> }
> 
> close (WPOUT);

  open my $wpout,'>',"WPout.txt" or die "Can't create WPout.txt: $!";

  for( $legend, @temp ) {
     print $wpout join(',', @$_),"\n";
  }

> I thought I could replace:
>     $temp[$turn+5] =~ s/ East / E /g;
>     $temp[$turn+5] =~ s/ East$/ E/g;
>     $temp[$turn+5] =~ s/^East /E /g;
> with:
> $temp[$turn+5] =~ s/([^|\s])East(\s)/$1E$2/g;
> 
> but it did not work for me  :-(

Look up what [] mean in regular expressions - then remove them when
you discover that [] is in no way related to what you were tring to
do.

> $temp[$turn+5] =~ s/(\s)East(\s)/$1E$2/g;
> almost works, but not quite since it doesn't work if
> "East" is the first thing in the string.

I've addressed this above.

> My next step is to push $lat and $long together and
> print a file of records that have the same $lat . $long
> Probably pretty easy, but I may have to do brute force
> way if I don't get smart on hashes real soon.

The time taken to figure ot hashes would be well spent.

Actually there was no reason to slurp the whole file - you could have
processed the file with only one line at a time in memory.  For a
small file this is not important.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 01 Aug 2003 17:27:39 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: No Question - Just Posting some Code I'm Proud of
Message-Id: <vil8obihhiap43@corp.supernews.com>

In article <3F2A8A4E.C7CBEF6E@earthlink.net>,
    Mike Flannigan  <mikeflan@earthlink.net> wrote:

: [...]
: 
: I thought I could replace:
:     $temp[$turn+5] =~ s/ East / E /g;
:     $temp[$turn+5] =~ s/ East$/ E/g;
:     $temp[$turn+5] =~ s/^East /E /g;
: with:
: $temp[$turn+5] =~ s/([^|\s])East(\s)/$1E$2/g;
: 
: but it did not work for me  :-(

You were close.  See below for that and other improvements.  Note that
mine inverts the order of the repeated locations in the output.

    #! /usr/local/bin/perl

    # This file takes a CSV file,
    # removes offending characters from the name fields
    # and gives the 6 digit names field unique names.
    # It also shortens the long name field a little.

    use strict;
    use warnings;

    my $file = "bran2.csv";
    my (@temp, $temp);

    open WPIN, "<", $file or die "$0: open $file: $!";

    while (<WPIN>) {
       my $fields = 8;
       my $count  = tr/,//;

       if ($count != $fields-1) {
          my $commas = $count == 1 ? "comma" : "commas";
          warn "$0: $file:$.: $count $commas -- bad line?\n";
       }

       chomp;
       push @temp => [ split /,/, $_, $fields ];
    }

    my %saw;
    for (@temp) {
        # Replace bad characters
        $_->[2] =~ tr/()#.:\/?'&!//d;

        for ($_->[-1]) {
           s/\(historical\)/(hist)/g;
           s/\(abandoned\)/(aban)/g;
           s/National Recreation Area/NRA/g;
           s/Cemetery/Cem/g;

           s/(\s*) \b North \b (\s*)/${1}N${2}/gx;
           s/(\s*) \b South \b (\s*)/${1}S${2}/gx;
           s/(\s*) \b East  \b (\s*)/${1}E${2}/gx;
           s/(\s*) \b West  \b (\s*)/${1}W${2}/gx;

           s/High School/HS/g;
           s/Community College/College/g;
           s/Campground/Campgr/g;
           s/Post Office/PO/g;
           s/Junior/Jr/g;
           s/Mountain/Mtn/g;
        }

        if ($saw{ $_->[2] }++) {
           $_->[2] =~ s{^ (.{0,4}) (..)? (.*) $} {
               $1 . sprintf("%02d", $saw{ $_->[2] }) . $3
           }ex;
        }
    }

    # print to the wpout.txt file
    open WPOUT, ">", "WPout.txt" or die "$0: open WPout.txt: $!";

    for (@temp) {
        print WPOUT join("," => @$_), "\n";;
    }

    close WPOUT or warn "$0: close WPout.txt: $!";

    __END__

: My next step is to push $lat and $long together and
: print a file of records that have the same $lat . $long
: Probably pretty easy, but I may have to do brute force
: way if I don't get smart on hashes real soon.

The trick there will be defining what you mean by the same latitude
and longitude.  If it's as simple as the text in their respective
records being identical, then you could do the following in your
processing loop:

    push @{ $latlon{ $_->[3], $_->[4] } }, [ @$_ ];

Then print matches with

    for (keys %latlon) {
        next unless @{ $latlon{$_} } > 1;

        my($lat,$lon) = split /$;/o;
        print "At $lat, $lon:\n";

        for (@{ $latlon{$_} }) {
            print "  - $_->[2]\n";
        }
    }

Hope this helps,
Greg
-- 
Amazon.com status as a dot-com questioned:
    http://www.dailyreckoning.com/jokes.cfm?jokeid=348


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

Date: Fri, 01 Aug 2003 17:44:46 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: No Question - Just Posting some Code I'm Proud of
Message-Id: <Xns93CA8BD544059dkwwashere@216.168.3.30>

Greg Bacon <gbacon@hiwaay.net> wrote:

>            s/(\s*) \b North \b (\s*)/${1}N${2}/gx;
>            s/(\s*) \b South \b (\s*)/${1}S${2}/gx;
>            s/(\s*) \b East  \b (\s*)/${1}E${2}/gx;
>            s/(\s*) \b West  \b (\s*)/${1}W${2}/gx;

How about

    s/\b(North|South|East|West)\b/substr($1,0,1)/eg;

?

I don't see a need to remember the spaces since you're not really doing 
anything with them.



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

Date: Fri, 01 Aug 2003 17:46:29 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: No Question - Just Posting some Code I'm Proud of
Message-Id: <Xns93CA8C1FA20D7dkwwashere@216.168.3.30>

Brian McCauley <nobull@mail.com> wrote:

> Mike Flannigan <mikeflan@earthlink.net> writes:
>  
>> # Rename duplicate name1's
>> for (my $turn = 10; $turn <= $#temp; $turn+=8) {
>>     next if ($temp[$turn] ne $temp[$turn-8]);
>>     $rep++;
>>     if (length $temp[$turn-8] > 3){
>>         substr ($temp[$turn-8], 4, 2, "0$rep") if ($rep < 10);
>>         substr ($temp[$turn-8], 4, 2, "$rep")if ($rep > 9);
>>         $rep = 1 if ($temp[$turn] ne $temp[$turn+8]);
>>     }
>>     else {
>>         $temp[$turn-8] =~ s/^(.{0,4})$/${1}0$rep/ if ($rep < 10);
>>         $temp[$turn-8] =~ s/^(.{0,4})$/${1}$rep/ if ($rep > 9);
>>         $rep = 1 if ($temp[$turn] ne $temp[$turn+8]);
>>     }
>> }
> 
> I'm not going to try to understand that.

I "cheated" and looked at the output.  Once you have the data in an 
array of arrays (call it @AoA), something like this

my %count;
for my $element (@AoA) {
    if (++$count{$element->[2]} > 1) {
        $element->[2] = substr($element->[2], 0, 4) .
            sprintf "%02d", $count{$element->[2]};
    }
}

will produce a similar output.  Not exactly, but close.  I suspect it 
*may* be close enough for the OP.


> Actually there was no reason to slurp the whole file - you could
> have processed the file with only one line at a time in memory. 
> For a small file this is not important.

Since you've already done the hard part....



use strict;
use warnings;

# I still use the 2-argument open() because I'm used to it :-)
open WPIN, "bran2.csv" or die "Can't create $file: $!";

# print to the wpout.txt file
open WPOUT, ">WPout.txt" or die "Can't create WPout.txt: $!";

my %count;
while (<WPIN>) {
    # no need to chomp() because we want the newline when we 
    # print out the data
    my @record = split/,/;
    for ($record[7]) {
        tr/()#.:\/?'&!//d;
        s/\b(North|South|East|West)\b/substr($1,0,1)/eg;
        s/\(historical\)/\(hist\)/g;
        s/\(abandoned\)/\(aban\)/g;
        s/National Recreation Area/NRA/g;
        s/Cemetery/Cem/g;
        s/High School/HS/g;
        s/Community College/College/g;
        s/Campground/Campgr/g;
        s/Post Office/PO/g;
        s/Junior/Jr/g;
        s/Mountain/Mtn/g;
    }
    if (++$count{$record[2]} > 1) {
        $record[2] = substr($record[2], 0, 4) .
            sprintf "%02d", $count{$record[2]};
    }
    print WPOUT join ',', @record;
}

close (WPOUT);


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

Date: 01 Aug 2003 19:00:40 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: No Question - Just Posting some Code I'm Proud of
Message-Id: <u9brv9dzqv.fsf@wcl-l.bham.ac.uk>

"David K. Wall" <usenet@dwall.fastmail.fm> writes:

> # I still use the 2-argument open() because I'm used to it :-)
> open WPIN, "bran2.csv" or die "Can't create $file: $!";

I still think the error message could be improved :-(

open WPIN, "<bran2.csv" or die "Can't read bran2.csv: $!";
                                      ^^^^

The reason I dislike the 2-argument open is because I think it's
illogical.  The file access mode and the file name are logically two
orthogonal arguments.  Merging them never made much sense.  I used
Perl for a long time before we got the 3-arg open and I always felt
vaguely uncomforatble without it.

I also dislike bareword filehandles because.... er... they're just not
nice.  They are, in fact, symrefs! (Waves hands in air and runs off
screeming).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 01 Aug 2003 16:35:15 GMT
From: "John M. Lembo" <jlembo@rochester.rr.com>
Subject: Parse Text File and Output to File
Message-Id: <7FwWa.143069$EQ5.33612@twister.nyroc.rr.com>

I am using Perl to parse a text file and output to another file.  The text
file has data on Unix virtual memory (vmstat) and I want to delete lines
that I don't want and output lines that I want to a new file.  The script I
have is giving me blank lines in the new file.

#!/usr/local/bin/perl
#program to read systemdata file
#and write to systemstats file
#
#
$file = '/users/rit0/g3/jml9810/metrics/systemdata';
open(INFO, $file);      #opens file systemstats
open(DATA, ">systemstats");#file to write data to
@lines = <INFO>;        #assigns lines to array

foreach $line (@lines)  #go through each line in file
{
        if ($line ^V)
        {
                $line =~ s/$line//;
        }

        DATA == $line;
        print DATA "\n";
}

close(INFO);            #closes file
close(DATA);

The data I am reading is vmstat as follows:

0308011610
Virtual Memory Statistics: (pagesize = 8192)
  procs    memory         pages                          intr        cpu
  r  w  u  act  free wire fault cow zero react pin pout  in  sy  cs  us  sy
id
  5 483 41  113K  43K  34K 958M  15M  36M  48K  17M 3716  88  1K 914   2   5
93
=== end at Fri Aug 1 12:10:01 EDT 2003 ===
0308011615
Virtual Memory Statistics: (pagesize = 8192)
  procs    memory         pages                          intr        cpu
  r  w  u  act  free wire fault cow zero react pin pout  in  sy  cs  us  sy
id
  5 496 35  114K  43K  33K 958M  15M  36M  48K  17M 3716  88  1K 914   2   5
93
=== end at Fri Aug 1 12:15:01 EDT 2003 ===

I want to output the date and memory data only to a new file and delete the
other lines.  Any help is appreciated.

-- 

Regards,

John M. Lembo
(585) 594-1753 (ET)
(585) 594-4028 Fax
jlembo@rochester.rr.com (Alt. email)




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

Date: Fri, 1 Aug 2003 16:47:29 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Parse Text File and Output to File
Message-Id: <slrnbil6d1.ahn.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Fri, 01 Aug 2003 16:35:15 GMT, John M. Lembo <jlembo@rochester.rr.com> wrote:
> #!/usr/local/bin/perl

use strict;
use warnings;

[snip]



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

Date: 01 Aug 2003 18:17:41 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Parse Text File and Output to File
Message-Id: <u9u191e1qi.fsf@wcl-l.bham.ac.uk>

"John M. Lembo" <jlembo@rochester.rr.com> writes:

> I am using Perl to parse a text file and output to another file.  The text
> file has data on Unix virtual memory (vmstat) and I want to delete lines
> that I don't want and output lines that I want to a new file.  The script I
> have is giving me blank lines in the new file.

This is FAQ: How do I [...] delete a line in a file [...]?

Please check the FAQ before you post.

 
> #!/usr/local/bin/perl
> #program to read systemdata file
> #and write to systemstats file

Try to get into the habit of writing your code in a fashion consitant
with strict and warnings then put "use strict" and "use warnings" at
the top of your script.  If you stick with Perl sooner or later you'll
start doing this[1].  The longer the you leave it the more you will
regret it.

> #
> #
> $file = '/users/rit0/g3/jml9810/metrics/systemdata';
> open(INFO, $file);      #opens file systemstats

Always check that open() succeded.  At the very least put "or die $!".

> open(DATA, ">systemstats");#file to write data to

The file handle DATA is special.  You _can_ treat it as a normal
handle but it will confuse people who are familar with Perl.

Comments should add something to the program.  Don't bother with
comments that just add noise.  If a statement is opviously opening a
file for output it is redundant to have a comment that say so too.


> @lines = <INFO>;        #assigns lines to array

Why do you slurp?

> 
> foreach $line (@lines)  #go through each line in file
> {
>         if ($line ^V)

What do to think that does and why?

What is actually does is is construct a string that is the same as
$line except with bits 3,4 and 5 of the first character inverted.  It
then tests if that string is true.  It will always be true.

>         {
>                 $line =~ s/$line//;

What do to think that does and why?

What it actually does is takes the contents of $line and compiles it
as a regular expression.  It then takes $line again and replaces the
first match with a null string.  For values of $line that contain no
regex metacharacters this is equivalent to

   $line = '';

For most other values of $line this is either an error or a no-op.

For a few value of $line is will do some really weird and worderfull
things.

>         }
> 
>         DATA == $line;

What do you think that does and why?  

What is actually does is convert the value of $line into a number and
tests to see if that number is with the same as the numeric value of
the string 'DATA' (i.e. zero).  It then throws away the result of this
comparison.

If you'd had warnings and strictures enabled Perl would have had a lot
to say about that line.

>         print DATA "\n";

So the only thing you are printing is a file full of blank lines!

> }
> 
> close(INFO);            #closes file

Comments should add something to the program.  Don't bother with
comments that just add noise.

> close(DATA);

Note:

  [1] Not all perl users eventually come arround to using strict and
      warnings.  Some turn into bitter and twisted trolls.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 01 Aug 2003 18:19:55 +0200
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <spp@monaco377.com>
Subject: Re: Pb $SIG{CHLD}=sub{wait()}; in Perl 5.8.0
Message-Id: <3f2a932c$0$14356$626a54ce@news.free.fr>

Stefan wrote:

> "Sébastien Cottalorda" <spp@monaco377.com> schreef in bericht
> news:3f2a7617$0$19516$626a54ce@news.free.fr...
>> Hi all,
>>
>> Since I migrate a Perl Socket application from perl 5.6.0 to 5.8.0, I
>> encoutered problem with the $SIG{CHLD} interrupt.
>>
>> Here is sample of my code (server side):
> 
> /--- snip code ---/
> 
>> When a connexion cames, it was taken by the son, and the father dies just
>> after the son has finished his job.
>>
>> If someone has a clue.
>>
>> Thanks in advance.
>>
>> Sébastien
> 
> 
> It might be related to the fact the different versions of Perl handle
> calls differently. Don't ask me about the underlaying details - try a
> Google/Groups search on "Perl EINTR" and/or "Perl EINTR accept".
> 
> In your code, you don't really check the status of the accept() call. If
> you do, you'll probably see that accept() return status-code 4 (EINTR). In
> my experience, that never happens the 1st time a connection is accepted.
> That may explain that the father dies after the son has completed.
> 
> Try adding some accept() status handling - this is a piece of code I use;
> 
>     use Errno 'EINTR';       # or use a constant value of 4
> 
>     ClientAccept: {
>        $client = $server->accept();
>        if ($! == EINTR) {
>           if ($client) {
>              print "Non-fatal Interrupted system call in accept()\n";
>           } else {
>              print "Interrupted system call - redo accept()\n";
>              redo ClientAccept;
>           }
>        }
> 
>        # --- rest of your server-code
>     }
> 
> Good luck,
> Stefan


Thanks Stefan.
I'll check your proposal.

Sébastien


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

Date: Fri, 01 Aug 2003 15:32:16 GMT
From: "Tyler Cruz" <tylercruz@hotmail.com>
Subject: Re: Perl Project Logic Question
Message-Id: <4KvWa.579182$3C2.14782007@news3.calgary.shaw.ca>

Hi,

That seems like a good idea, with only one fault I believe.. If I ever put
two of the same movie back to back (by accident perhaps) - nobody will be
able to guess it correctly.. I think, also, in the back of my mind, that I'm
somehow afraid of it not completely matching correctly..

Tyler

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns93CA42D4F4649sdn.comcast@206.127.4.25...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "Tyler Cruz" <tylercruz@hotmail.com> wrote in
> news:2RbWa.569437$3C2.14646011@news3.calgary.shaw.ca:
>
> > Now, a little problem. I will be updating the film once a week, so
> > once they get it, I have to temporarily suspend them from guessing
> > again, or they can just rack up free points. Thus, I was thinking of
> > adding a new colomn in my table in MySQL for 'namethatflickcorrect'
> > and it woudl have a Y or N. Y if they answered it correctly, and N if
> > not. And the form would not let them guess again if they have a Y.
> >
> > I keep the movie name and name for the image filename in flatfile
> > databases.
> >
> > Then when the administrator (me) adds a new movie, it would reset all
> > the members' namethatflickcorrect' to N. (loading/bandwidth issues?).
> > I'm not sure if I will archive the old Name that Flick answers/photos,
> > as I think it may be too much programming (not worth
> > it/overcomplicated)
> >
> > Anyhow, please let me know if my logic is correct, thanks.
>
> That sounds like a lot of work, resetting the flags.  And the timing has
> to be right, and you may have data sync issues.
>
> Instead, how about creating a 'last_flick_guessed' column, which would
> contain the name of the flick the user most recently guessed correctly.
> When processing a guess, the user's score would not be incremented if
> last_flick_guessed is the same as the name of the current flick quiz.
>
> - -- 
> Eric
> $_ =  reverse sort qw p ekca lre Js reh ts
> p, $/.r, map $_.$", qw e p h tona e; print
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPypCIWPeouIeTNHoEQJXbACfYLpwlOnHOgr8BSBVzllq17Cq8EwAoMaQ
> 0St4+auSHxQe4+VHv7svALs/
> =E/4W
> -----END PGP SIGNATURE-----




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

Date: Fri, 01 Aug 2003 16:45:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Substitution Question
Message-Id: <3F2A9985.BD22EFC3@acm.org>

Mike Flannigan wrote:
> 
> "John W. Krahn" wrote:
> >
> > You can leave out the length argument if you want to substitute the rest
> > of the string at position 4.
> >
> > substr( $temp, 4 ) = '01';
> 
> OK, as is often the case with posters, I lied a little bit.
> I need the length argument because not all the lines I am
> changing are 4 characters long.  If they are 4, 5 or 6
> characters I want:
> Adki01
> 
> 3 characters:
> Aki01
> 
> 2 characters:
> Ak01
> 
> etc.
> 
> I just figured out that substr ($temp, 4, 2, "01");
> returns an error if the field is less than 4 characters.
> "substr outside of string . . . "

You can use a negative number for the second argument which will do what
you want.

substr( $temp, -2, 2 ) = '01';

Or:

substr( $temp, -2, 2, '01' );

Or:

substr( $temp, -2 ) = '01';



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 1 Aug 2003 16:27:54 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: Wait for directory changes in Windows XP?
Message-Id: <bge0tr$n8m51$1@ID-112158.news.uni-berlin.de>


"Stephen" <usenet_removebeforesending_@fatkoala.co.uk> wrote in message
news:8lfkiv850jm82aboa14c4j6ovoqp35mf16@4ax.com...
> I am trying to write a Perl script that will watch a directory for MP2
> files created by some TV recording software, then trigger some other
> actions on each file that is created (eg convert them into MP3).
>
> I have looked at ChangeNotify and AdvNotify.  However, I think both of
> these will trigger action as soon as the recording software STARTS writing
> a file.
>
> I want to trigger action when it has FINISHED writing the file.
>
> In an Explorer window can see the file get opened and progressively
growing
> during the recording.  There is no published API to lock the file, etc.


You could use stat to monitor the size of the file every x seconds.  If it
doesn't change for a while then the program has probably finished writing to
it.

--
Brian Wakem





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

Date: Fri, 1 Aug 2003 17:27:32 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Web development and Perl 6
Message-Id: <Pine.LNX.4.53.0308011713580.31734@lxplus081.cern.ch>

On Fri, Aug 1, Charlton Wilbur inscribed on the eternal scroll:

> CGI scripting is terribly easy.

With the emphasis on "terribly", unfortunately...

> There are perhaps five hard problems
> specific to it, and they have all been solved, and they are all
> well-documented at the level a competent novice can understand.

And are unfortunately hidden beneath bushels of friendly chaff that's
been scattered liberally across the "free script archives" of the
world.

>  When
> someone has a persistent problem with one of them, it is either
> because of an unwillingness or inability to read the documentation
> once pointed out, or a problem with a fundamental aspect of
> programming or Perl.

I see several "fundamental" problems (from elementary problem solving
techniques right up to principles of reliable software engineering),
but very few of them are specific to Perl.  The only reason that they
_seem_ specific to Perl is often that the novice has not yet noticed
that CGI is not identical to Perl, nor vice versa - or thinks that
their elementary HTML problem ipso facto becomes a Perl problem when
they use Perl to generate their HTML.  Sigh.

> In neither of these cases is an exchange on
> Usenet likely to be all that helpful.

There's certainly truth in what you say.  But what to do?  If someone
with at least a vague competence doesn't step up to the plate, then
there's a sheer endless supply of clue-impaired dabblers who are only
too ready to fill the vacuum with their own confused answers.  If
those are the only answers that get seen, it's understandable that the
newcomer would believe them - and in many cases, go forth and
propagate them elsewhere.  It's very frustrating.

(Disclaimer: I'm only too keenly aware of my own imperfections in this
matter, but at least I think I know what I know, and I am aware of
what I don't know: and I try not to offer authoritative-looking
answers in areas where I know I'm weak.)

cheers


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

Date: Fri, 01 Aug 2003 17:16:25 +0100
From: jimbo <jimbo@soundmiges.co.uk>
Subject: Re: Web development and Perl 6
Message-Id: <1059754563.196812@ananke.eclipse.net.uk>

Garry Heaton wrote:

> It appears I drifted into the wrong newsgroup.

I think you drifted into the wrong mindset.  This isn't personal, this 
is impersonal.  Release your ego for a bit and get into the Perl spirit. 
  Although, using a Camel's brain is an upgrade for me, I must say.

> as most of the respondents here are more interested in distancing
> themselves from web developers

Not really.  Most folks here just rekon that a powerful programming 
language is used to write powerful programs.  From the command line 
throw-away to the mission critical application.  Easy to use; easy to 
implement; easy to appreciate.

> ... who, by definition, seem to be tarred as "clueless".

Well, unfortunately, 'web developers', by their very choice of taxonomy, 
have boxed themsleves into a hole.  If you want to ask a Perl question, 
fire away.  If they want to discuss other paradigms and standards, then 
Usenet demands an RTFM at least, if not a flame of wrath.  Let us not 
apologize  for seeking to keep the noise to a minimum.  Just ask those 
living beneath an airport flight path.

> I give up.

I hope not.  Perl is about more than CGI.  It is alot of fun.  It can do
many things in and of itself.  It has hooks into lots more.  It is
backed by an enthusiastic and bombastic and egotistical group of
dedicated professionals and enthusiasts.  Look beyond the RTFM's from
time to time and you'll see something magic about Perl and it's community.

jimbo
;-)



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

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


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