[19234] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1429 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 2 14:26:40 2001

Date: Thu, 2 Aug 2001 11:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996775812-v10-i1429@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 2 Aug 2001     Volume: 10 Number: 1429

Today's topics:
    Re: Perl Journal Update <Trevor.Jenkins@suneidesis.com>
    Re: Regex Question... (JR)
    Re: Regular expression issue <tom.melly@ccl.com>
    Re: Script works on PWS but not IIS? <skoehler@upb.de>
        serial ports/modems and chat2.pl <ronan.oconnor@materna.nl>
    Re: Splitting a text list into smaller lists? (Yves Orton)
    Re: The perlish way to write this? <a@b.c>
    Re: The perlish way to write this? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: which module to mirror between servers? (J.H.M. Dassen (Ray))
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 02 Aug 2001 17:53:04 +0000
From: Trevor Jenkins <Trevor.Jenkins@suneidesis.com>
Subject: Re: Perl Journal Update
Message-Id: <3B699380.1BCB7EC4@suneidesis.com>

David Marshall wrote:
> 
> The Perl Journal (http://www.tpj.com) is being reformulated as a
> quarterly supplement to Sys Admin magazine.  The first supplement will be
> "polybagged" with the October 2001 issue.
> 
> On the "Subscribe" page at http://www.tpj.com is a link by which you can
> subscribe to Sys Admin.
> 
> You can also subscribe to Sys Admin at http://www.enews.com (my
> employer), for a few bucks less.

What happens to those of us whose subscriptions to TPJ had not expired
when the debacle with publication occured? Will we still get issues or
must we take out an (extra) subscription in order to et what we've
already paid for?

Regards, Trevor

British Sign Language is not inarticulate handwaving; it's a living
language.
Support the campaign for formal recognition by the British government
now!

-- 

<>< Re: deemed!


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

Date: 2 Aug 2001 10:01:43 -0700
From: tommyumuc@aol.com (JR)
Subject: Re: Regex Question...
Message-Id: <319333f5.0108020901.54015844@posting.google.com>

Ren Maddox <ren@tivoli.com> wrote in message news:<m3k80nd821.fsf@dhcp9-161.support.tivoli.com>...
> On 1 Aug 2001, tommyumuc@aol.com wrote:
> 
> > I have a series of about 500 .dbf files that I need to merge
> > together into one large file that is sorted and neatly formatted.
> > For example, in the below partial file, I have: 
> 
> I'm not familiar with .dbf files, so if there is anything special
> about them that bears on this problem or solution, then I'm missing
> it.
> 
> > $myVar=<<"FILE"; 
> > 1 5C162810001H51Delaware Bay 188 
> > 2 92C162810001H51Delaware Bay 44 3 204
> > C162810001D85Killen Pond State Park 8 4 207
> > C162810001D85Killen Pond State Park 8 
> > FILE 
> > 
> > $myVar =~ s/\\W+//egs; #works 
> 
> For what definition of "works"?  With two "\"-s, it does nothing to
> this input.  Assuming that is just a typo, them it removes all of the
> non-word characters, which happens to be all of the white-space in
> this input.  If you really mean white-space, use \s instead of \W.
> But with the white-space gone, how do you distinguish the first three
> fields?  The second field obviously varies in length and presumably
> the first one does as well.
> 
> In addition, the /e and /s modifiers have no effect here.  (Well, the
> /e produces a bunch of warnings when warnings are enabled as they
> should be.)
> 
> > $myVar =~ s/\n//egs; #doesn't work 
> 
> Works for me (with the same issues as above for /e and /s).  Perhaps
> you have a DOS-formatted file that has \r\n at the end of each line.
> Wise use of \s can make this problem disappear.
> 
> > I've tried getting rid of instances of more than 2 spaces in the file,
> > which worked well, but I can't seem to get rid of the newline
> > characters in the same fashion. What I would like this file to
> > become ultimately (and I realize that after I have stripped the
> > newline characters, this is still a few lines of code away) is this
> > exactly:
> > 
> > 1 5 C1628 10001 H51 Delaware Bay 188
> > 2 92 C1628 10001 H51 Delaware Bay 44 
> > 3 204 C1628 10001 D85 Killen Pond State Park 8
> > 4 207 C1628 10001 D84 Killen Pond State Park 8
> 
> Well, making a few additional assumptions about the format, this
> works:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> my $myVar=<<FILE;
> 1 5C162810001H51Delaware Bay 188
> 2 92C162810001H51Delaware Bay 44 3 204
> C162810001D85Killen Pond State Park 8 4 207
> C162810001D85Killen Pond State Park 8
> FILE
> 
> while ($myVar =~ /(\S+)\s+(\d+)\s*(\w{5})(\w{5})(\w{3})(.*?)\s*(\d+)/g) {
>   print "$1 $2 $3 $4 $5 $6 $7\n";
> }      
> __END__
> 
> If extra newlines can fall in other places (between fields), then
> simply inserting \s* as appropriate can handle that.  One of the big
> assumptions here is that the second field can only be digits and the
> third field starts with a letter.
> 
> I hated having to use the $1, $2, etc. variables here, but I needed
> the pattern match to be in scalar context to get the proper behavior
> for /g.  Ah... the "answer" just came to me.  Use this instead:
> 
> my @fields = $myVar =~ /(\S+)\s+(\d+)\s*(\w{5})(\w{5})(\w{3})(.*?)\s*(\d+)/g;
> print join(" ", splice @fields, 0, 7), "\n" while @fields;
> 
> > After I have it in this format, I've already created the script to
> > merge the files (which I have tested, and works fine--I run this
> > script on the directory where I have the files I would like to merge
> > and then just redirect it into a .dat file--this script took only a
> > few minutes to write and once handled 16 million records in only 20
> > minutes):
> > 
> > #!/usr/bin/perl
> > 
> > opendir (DH, 'other_blocks')  ||  die "Cannot open:  $!";
> 
> Should include the name of the directory in the error message.
> 
> >    while ($file=readdir DH) { 
> >    next if (-d "other_blocks/$file");
> >    if (! open (F, "other_blocks/$file") ) {  
> >       warn "Cannot search: $!";
> 
> Should include the name of the file in the error message.
> 
> >       next;
> >    } 
> >    while(<F>)  {
> >       $_ =~ s/ /0/g;
> >       $st = substr($_, 1,2);	
> >       $cou = substr($_, 3, 3);
> >       $cen = substr($_, 6, 6);
> >       $block = substr($_, 12 ,4);
> >       $land = substr($_, 91, 14);
> >       $pop = substr($_, 117, 6);
> 
> I usually prefer a single unpack instead of a string of substr
> extractions.  Of course, I'm not sure your substr() values make much
> sense.  You start at 1 instead of 0.  Later, you skip to 91 and then
> again to 117.  This doesn't seem to match the above output data.
> 
> >       if ($st == '02') {
> >          print "$st$cou$census$block\t$land\t$pop\n";
> >       }
> >       elsif ($st == '15') {
> >          print "$st$cou$census$block\t$land\t$pop\n";
> >       }
> >       elsif ($st == '72') {
> >          print "$st$cou$census$block\t$land\t$pop\n";
> >       }
> 
> These all seem to do the same thing.
> 
> >       else {
> >          print "Incorrect values!\n";
> >       }
> >    }
> > } 
> > 
> > 
> > I appreciate any suggestions anyone may have--thank you.
> 
> I hope that helps.

Yes--this helps very much.  Thank you.


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

Date: Thu, 2 Aug 2001 16:06:00 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: Regular expression issue
Message-Id: <3b696c59$0$3760$ed9e5944@reading.news.pipex.net>

"Paul Johnston" <paul.johnston@dsvr.co.uk> wrote in message
news:3B6967A9.E278A842@dsvr.co.uk...
>
> You're soooooooooo nearly right.

Which, IMHO, is far more frustrating than being soooooooo very very wrong.




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

Date: Thu, 2 Aug 2001 18:20:55 +0200
From: "Sven Köhler" <skoehler@upb.de>
Subject: Re: Script works on PWS but not IIS?
Message-Id: <9kbuon$86c$07$1@news.t-online.com>

perhaps you use IE ... and IE automatically logs you in as the user you
are - for example administrator :-) - which gives the script the rights of
the administrator ...

"Alex" <samara_biz@hotmail.com> schrieb im Newsbeitrag
news:c7d9d63c.0108020511.1585293a@posting.google.com...
> > but you forgot one thing ! you perhaps dont' have ntfs on your machine
and
> > ntfs makes things complecated ...
> >
> > the admin of the iis-server must grant the IUSR_xxx write permissions on
the
> > file ...
>
> Thanks for the answer!
>
> Actually, I do have ntfs on the local webserver. I kinda guessed that
> I need write permissions for IUSR_xxx on that file, but then what
> confuses me is how come I don't have that permission set on that file
> on my local webserver and the script still runs.
>
> Alex




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

Date: Thu, 2 Aug 2001 17:11:38 +0200
From: "Ronan O'Connor" <ronan.oconnor@materna.nl>
Subject: serial ports/modems and chat2.pl
Message-Id: <9kbqj6$j02$1@penthesilea.materna.de>

I'm looking for information on chat2.pl. Can anyone point me towards
documentation.
I'm planning to use chat2.pl to connect to a modem on the serial port.
Anyone know of any useful modules to do this?

Thanks in Advance,

Ronan






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

Date: 2 Aug 2001 08:27:52 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Splitting a text list into smaller lists?
Message-Id: <74f348f7.0108020727.18bd9b7d@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3B68C7B2.897DA9E9@acm.org>...
> ctverlane@NOSPAM.blackdahlia.zzn.com wrote:
> > 
> > I apologize in advance for the cluelessness of this question, but I'm
> > desperate, so here goes.
> > 
> > I'm an Oracle dba.  I have a long list of users (25000) of them, in a
> > delimited text file.  What I want to do is use Perl to take the long list and
> > divide it up into 500 lists of 50 users each.  So the task breaks down to 1)
> > dividing the list into groups of 50, using the delimiter to show where each
> > username ends, and then 2) writing each list to a separate file.

<SNIP OP CODE>

> 
> #!/usr/bin/perl -w
> use strict;
> 
> my $file = 'userfile01';
> my @in;
> # Read the file of 25000 users from stdin:
> while ( <> ) {
> 
>     # Parse the line, using the numeral 4 as the delimiter.
>     push @in, split /4/;
>    
>     while ( @in >= 50 ) {
>         open OUT, "> $file" or warn "Cannot write to $file: $!" and
> next;
>         print splice( @in, 0, 50 );
>         $file++;
>         close OUT;
>         }
>     }

John, nice use of the ++ operator there..  A couple or minor
corrections though...  I personally wouldn't just jump to the next in
case of an open() failure, id die() instead.  Also the above will fail
to print out the last line if the number of names isnt an even
multiple of 50. (And to get really picky :-) I am printing the names
with a join as I think maybe they arent so useful all strung
together.) My slight modification would be:

#!/usr/bin/perl -w
use strict;

my $file = 'userfile01';
my @in;
# Read the file of 25000 users from stdin:
while ( <STDIN> ) { #using explicit for clarity
    chomp;
    # Parse the line, using the numeral 4 as the delimiter.
    push @in, split /4/;
    my $flush=eof(STDIN); #flush the array if eof on input
    while ( @in >= 50 || $flush) {
        open OUT, "> $file" or die "Cannot write to $file: $!";
        print OUT join("\n",splice( @in, 0, 50 ))."\n";
        $file++;
        close OUT;
        last if $flush; #bail if there aint any more input
    }
}

Incidentally to the OP, what kind of file do you have that uses the 4
character as a delimeter?  Surely you might a username with a 4 in it?
 Especially in 25000 users???

Yves


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

Date: Thu, 02 Aug 2001 10:20:59 -0700
From: BCC <a@b.c>
Subject: Re: The perlish way to write this?
Message-Id: <3B698BFB.F3D0EFC7@b.c>

Uri Guttman wrote:

>         $border ||= '0' ;
>         $align ||= 'abscenter ;
> 

Ahh, much nicer there....

> 
> for html i almost always use here docs:
> 
>         print <<HTML ;
> <a href="$href"><img src="$image" align="$align" border="$border"
> alt="$alt"></a>
> HTML
> 


Thanks Uri (And everyone else too!) for the nice tips.  One question on
the here doc though.  I agree that it is the best suited for this kind
of thing, but visually it is a pain in the a$$.  Maybe someone knows a
way around this particular annoyance with here docs?

Example:
sub A_Test_Sub {
   if ($someValue == 1) {
      if ($someOtherValue eq "yes") {
         $str = <<HTML;
          <a href=http://www.slashdot.com>Slashdot</a>
HTML
^^^^              
      }
   } elsif ($someValue == 2) {
      # do stuff
   } elsif ($someValue == 3) {
      # do other stuff
   }
}

Notice the HTML end must have no leading whitespace... visually very
distracting (for me anyaway).  I know you can do $str =<<"    HTML", but
then in my rapidly changing development environment (read correcting my
mistakes :) everytime an indent changes I have to go and recount spaces
so my here doc works again.  Maybe some neat little regex works?

Thanks!
Bryan


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

Date: Thu, 02 Aug 2001 19:37:18 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: The perlish way to write this?
Message-Id: <3B698FCE.2070006@post.rwth-aachen.de>

BCC wrote:

[snipped]

>Notice the HTML end must have no leading whitespace... visually very
>distracting (for me anyaway).  I know you can do $str =<<"    HTML", but
>then in my rapidly changing development environment (read correcting my
>mistakes :) everytime an indent changes I have to go and recount spaces
>so my here doc works again.  Maybe some neat little regex works?
>

Have a look at perlfaq 4: "Why don't my <<HERE documents don't work". 
This might help you.
 


Tassilo

-- 
Shick's Law:
	There is no problem a good miracle can't solve.




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

Date: Thu, 2 Aug 2001 15:55:19 +0000 (UTC)
From: jdassen@cistron.nl (J.H.M. Dassen (Ray))
Subject: Re: which module to mirror between servers?
Message-Id: <slrn9mitv7.m5u.jdassen@odin.cistron-office.nl>

Dan Baker <dan@nospam_dtbakerprojects.com> wrote:
> I have a projects coming up to mirror a specific directory of files
> between two servers... actually a localhost webserver on a win98
> machine, and a remote (LINUX or UNIX) host. I'm looking for a place to
> start reading; input on which module(s) might be the best to use.

http://www.webtechniques.com/archives/1998/11/perl/ looks like a nice
article. Personally, I rather like the efficiency of "rsync", so I'd
probably look at File::Rsync.

HTH,
Ray
-- 
Those who are willing to trade their liberty for security deserve neither.
	Benjamin Franklin


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

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


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