[18690] in Perl-Users-Digest
Perl-Users Digest, Issue: 858 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 8 21:05:53 2001
Date: Tue, 8 May 2001 18:05:07 -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: <989370307-v10-i858@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 8 May 2001 Volume: 10 Number: 858
Today's topics:
Re: Base 6 sieve. <michael@stroeck.com>
Re: hanging fork? (Logan Shaw)
Re: Help on optimization wanted <flavell@mail.cern.ch>
Re: HELP with @INC <ren@tivoli.com>
Re: how to set binary mode when uploading a file (R.S.)
Re: how to set debug mode in perl (Logan Shaw)
Re: Loading a file full of SQL via DBI/DBD <todd@designsouth.net>
Re: Local Time <todd@designsouth.net>
Re: Local Time <flavell@mail.cern.ch>
Re: Local Time (Todd Smith)
Re: need help with reading, splicing, substitution <ren@tivoli.com>
Perl 2 Exe (Tony Van der Voort)
Re: Perl 2 Exe <djm@spamfree.mcoe.k12.ca.us>
Re: Perl 2 Exe <wyzelli@yahoo.com>
Re: Prices for work? (Alan Barclay)
Re: Prices for work? <bettylee@Stanford.EDU>
Problem writing to a socket after forking <rdoerr@planetkc.com>
Re: Question about "->" operator (F. Xavier Noria)
Re: Question about "->" operator <todd@designsouth.net>
Re: Seeking a PERL Tutorial (F. Xavier Noria)
Re: Seeking a PERL Tutorial <flavell@mail.cern.ch>
Re: Sort String (Randal L. Schwartz)
Re: Take out lines that are flagged <joe+usenet@sunstarsys.com>
Re: Take out lines that are flagged <ren@tivoli.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 9 May 2001 01:34:57 +0200
From: "Michael Ströck" <michael@stroeck.com>
Subject: Re: Base 6 sieve.
Message-Id: <3af8827d$1@e-post.inode.at>
Abigail wrote:
> As Anno pointed out yesterday, a sieve based on a base 6 numbering
> system uses less memory. Here's an implementation, which is hopefully
> reasonable efficient.
<code snipped>
That was a great piece of code, Abigail.
I think the fact that I understand what's going on is
telling volumes about your programming-style :-)
Thanks,
Michael Ströck
------------------------------
Date: 8 May 2001 17:27:07 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: hanging fork?
Message-Id: <9d9rrr$j6p$1@boomer.cs.utexas.edu>
In article <3AF86849.44936C85@acc.com>,
Scott Shannon <scott.shannon@ericsson.com> wrote:
>
>Hi. I'm new to perl&cgi, so sorry if this is a silly problem...
>
>I'm trying to make a perl cgi script that will usually run a long
>program on some othe rmachines (I'm doing that with Net::Telnet).
>Because its long , I want to fork, give a simple message in the parent,
>which then returns to the main page, while the child ges off and
>runs the program, later emailing the result.
>The problem Im finding is that, even tho the fork works, the
>parent 'hangs' like it's waiting for the child to finish...when I say
>hang I mean the little loading bar at the bottom of the page is
>still going, and when I hit either the form return button or simple
>stop,
Just a guess, but probably the web server is connecting to the CGI and
waiting for it to stop sending output. When you fork and your parent
exits, the child is still attached to the output stream, so the web
server doesn't see an end-of-file and thinks maybe more output is
coming later.
Try doing something like this (error checking omitted for brevity):
if ($pid = fork)
{
print "You'll get an e-mail later, blah blah blah\n";
exit 0;
}
else
{
close STDIN;
close STDOUT;
close STDERR;
# do whatever
}
Of course, I could be wrong -- it could be due to something else. It
probably depends on the web server and platform you're running on.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Wed, 9 May 2001 01:04:32 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Help on optimization wanted
Message-Id: <Pine.LNX.4.30.0105090053500.26979-100000@lxplus003.cern.ch>
On Sun, 6 May 2001, Michael Ströck wrote:
(quoting me:)
> > Maybe my misgivings are unjustified, based on superstitions
> > about GOTO, or something; but I'd rather see the inner loop being a
> > logical function returning true or false, and the outer loop testing
> > that to see whether execution should continue or iterate, than to see
> > things like "next OUTER" in an inner block.
>
> I just knew that would pop up :-) I agree with you on the whole, but
> sometimes I think that a GOTO is just much more logical and easy to
> follow than more elobarate loop logic.
In this case it seems to be very easy. (Of course the other
discussions show that there are better algorithms, but let's just
pretend that we're going to use this one anyway).
In this case it seems to me that we can trade that "next LOOP" for a
return from an eval block:
> LOOP:
> while ($current_number <= $numbers_to_test) {
> $current_number+=2;
> foreach (@primes) {
> next LOOP if ($current_number % $_ == 0);
> }
> push (@primes, $current_number);
> }
while ($current_number <= $numbers_to_test) { eval {
$current_number+=2;
foreach (@primes) {
return if ($current_number % $_ == 0);
}
push (@primes, $current_number);
}
}
> In my example, I think it's more natural to say "if you find a modulus 0,
> forget the current number and get a new one." Especially in such a basic
> script.
Yes, but this says the same thing, no?
In more complex cases it may be necessary to return a true/false value
to indicate which kind of return was taken from the eval block, and
make a test in the outer loop to see what action to take next. But in
this case it was even simpler.
So there I am, hankering for that old VALOF...RESULTIS logic I learned
from BCPL. Wait till you hear what the others say about this, though.
cheers
------------------------------
Date: 08 May 2001 15:32:04 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: HELP with @INC
Message-Id: <m31ypzshtn.fsf@dhcp9-172.support.tivoli.com>
On Tue, 8 May 2001, dennis.kowalsk@daytonoh.ncr.com wrote:
> I have an environmental variable called MYLIB set to /dira/dirb and
> the following does not work
Did you export the environment variable?
> #!/bin/perl -I$MYLIB
No, I wouldn't expect that to work.
> neither does
>
> #!/bin/$ENV{MYLIB}
And certainly not that.
> The $MYLIB text is added to @INC.
What do you mean here? It is added by one of the above but the module
still doesn't work?
> I have also tried the following
>
> use lib $ENV{MYLIB}
>
> That does not work either.
Now that *should* work. Yup, I verified that it does work. Again,
the environment variable must be exported (for Bourne-shell
derivatives).
> I have also tried
>
> push @INC, $ENV{MYLIB};
>
> That does not work either.
That one only works if it is placed inside a BEGIN block so that it
happens before the "use", which has an implicit BEGIN block.
> When it fails I get a BEGIN failed message saying x.pm could not be
> found.
>
> The use x.pm follows all of the variations I have shown you.
"use" happens at compile time, as if it were in a BEGIN block, so
having it later in the script doesn't accomplish anything unless the
other code is *also* in a BEGIN block.
Now wait a minute.... You are trying to "use x.pm"? Surely not, as
that would give a syntax error. "use x" is what you meant, I assume.
> Can someone tell me how to add the contents of an environmental
> variable to @INC ??
The OTW (One True Way -- often, the answer is that TINOTW: There Is No
One True Way, but in this case, I don't think that applies) is:
use lib $ENV{MYLIB};
use x;
I take it back, there is another way. Use the environment variable
PERL5LIB, which is automatically included on @INC... but you'll still
need to export it.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 08 May 2001 23:19:18 GMT
From: rastacey@roadrunner.nf.net (R.S.)
Subject: Re: how to set binary mode when uploading a file
Message-Id: <3af87eaf.649612653@news.thezone.net>
On Tue, 08 May 2001 00:21:56 GMT, rastacey@roadrunner.nf.net (R.S.)
wrote:
Well for anyone else who gets caught , the answer is to add
'binmode(filehandle)' before saving the file.
BOB
>I am trying to upload an image file (jpg) using
>print $query->filefield(-name=>'photo'.-default=>'starting
>value',-size=>50,-maxlength=>80);
>
>And then save the fiel uaing
>open(OUTFILE,">pics\\photo.jpg")
>while ($bytesread=read($fileH1,$buffer,1024)) {
>print OUTFILE $buffer:
>}
>
>This works as far as uploading the file but there always seem to be
>too many characters.
>I have lookaed at buffer, binary, headers without fixing this problem.
>
>Any help or a pointer to a sample would be appreciated.
>
>
------------------------------
Date: 8 May 2001 17:22:17 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: how to set debug mode in perl
Message-Id: <9d9rip$j44$1@boomer.cs.utexas.edu>
In article <3AF86631.503B1931@lmc.ericsson.se>,
Andrew Pan (LMC) <lmcanpa@yahoo.com> wrote:
>I'm a new user of Perl and I'd like to know how to set debug mode when
>running perl script. As you know in B shell script we can add "set -x"
>in the first line then the script would run in debug mode,
That's trace mode.
But anyway, do "perl -d myscript". When inside the debugger, type "h"
for help. The key commands you need to know about are
n next (step over)
s step (step into)
x print a variable's value
b set a breakpoint
c continue (the opposite of break)
l list lines of source file
q quit
You can also use "t" to turn on tracing, but it doesn't work quite
like it does in the Bourne shell.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Tue, 08 May 2001 23:49:17 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Loading a file full of SQL via DBI/DBD
Message-Id: <1C%J6.80256$U4.17626764@news1.rdc1.tn.home.com>
> if ( $sqlstring =~ /;/ && length($sqlstring)){
> $dbh->do($sqlstring) or die ("Ack!:$sqlstring\n");
> $sqlstring = "";
> }
Not an answer, but I just noticed some useless code:
if ( $sqlstring =~ /;/ && length($sqlstring)){
if $sqlstring matches /;/, then it will always be at least 1 length, so the
second evaluation is always true and useless. Maybe you mean to ask if
there's anything before the semicolon, so you might want:
if ( $sqlstring =~ /;/ && length($`)){
-todd
------------------------------
Date: Wed, 09 May 2001 00:07:09 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Local Time
Message-Id: <NS%J6.80286$U4.17639789@news1.rdc1.tn.home.com>
<ryan@dcntet.net> wrote in message
news:E1yJ6.43555$FS3.481009@sjc-read.news.verio.net...
> Hello,
> I have just a quick question, I have been through the documentation
> and I can't find what I am looking for. I want to assign the local time
to
> a variable in the following format. Wed May 2 09:56:48 2001. If anyone
> could point me in the right direction as far as documentation or what
> module to use, I would greatly appreciate it.
>
> Thanks in advance.
> Ryan
Since everybody else said to use 'localtime', I'll say to use
chomp($date = `date`);
It gives the time zone too :)
------------------------------
Date: Wed, 9 May 2001 02:15:35 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Local Time
Message-Id: <Pine.LNX.4.30.0105090212240.4334-100000@lxplus003.cern.ch>
On Wed, 9 May 2001, Todd Smith wrote:
[fullquote including salutation and greeting. Not quite so bad as a
jeopardy-quote, but still a recognised bogosity alarm...]
> Since everybody else said to use 'localtime', I'll say to use
>
> chomp($date = `date`);
I'm glad you've discredited that answer then. How's your taint
checking, by the way?
> It gives the time zone too :)
And you didn't know any other way to get that?
--
Caution: product may contain traces of nut.
------------------------------
Date: Wed, 09 May 2001 00:54:40 GMT
From: todd@designsouth.net (Todd Smith)
Subject: Re: Local Time
Message-Id: <Xns909BCA0BE2B12todddesignsouthnet@24.7.143.118>
"Alan J. Flavell" <flavell@mail.cern.ch> wrote in
news:Pine.LNX.4.30.0105090212240.4334-100000@lxplus003.cern.ch:
> On Wed, 9 May 2001, Todd Smith wrote:
>
> [fullquote including salutation and greeting. Not quite so bad as a
> jeopardy-quote, but still a recognised bogosity alarm...]
>
>> Since everybody else said to use 'localtime', I'll say to use
>>
>> chomp($date = `date`);
>
> I'm glad you've discredited that answer then. How's your taint
> checking, by the way?
>
>> It gives the time zone too :)
>
> And you didn't know any other way to get that?
>
why do you have to be so mean?
--
-todd
------------------------------
Date: 08 May 2001 17:45:15 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: need help with reading, splicing, substitution
Message-Id: <m3n18nqx38.fsf@dhcp9-172.support.tivoli.com>
On Tue, 08 May 2001, lmoran@wtsg.com wrote:
> #!/usr/bin/perl -w
> use diagnostics;
> use strict;
>
> open (LIST, "sn.txt") ||
> die "No file sn.txt exists." ;
>
> my $pwd = <LIST>;
Lots of ways to do this. Try:
my $pwd = do {local $/; <LIST>};
or
my $pwd = join "", <LIST>;
> $pwd =~ s/^/, /; #attempt to replace \n with ", " -- not working
Again, lots of ways. One is:
$pwd =~ s/\n/, /g;
> $pwd =~
> y/A-Za-z/2223334445556667778889990022233344455566677788899900/;
> my $names = <LIST>;
> print "$names = $pwd";
>
> close LIST;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 08 May 2001 22:29:56 GMT
From: tvdv@advalvas.be (Tony Van der Voort)
Subject: Perl 2 Exe
Message-Id: <3af872a5.51524068@news.skynet.be>
Dear all,
I'm doing tests with Perl2Exe for linux, but before I want to spend
150$ to buy the official version, i want to be shure that i can do
everything i want with it. The demo version is too limited to test all
the option (no tiny and small mode). Can some borrow me a registration
code ? I assume you that this is just for test. I buy immediatly my
own version after a positive evaluation of this tool.
Many thanks for the help and understanding !
------------------------------
Date: Tue, 08 May 2001 23:06:54 GMT
From: "Dave" <djm@spamfree.mcoe.k12.ca.us>
Subject: Re: Perl 2 Exe
Message-Id: <i__J6.4$sI.535@typhoon.sonic.net>
Many so called "program authors" are just con men looking for a quick and
easy buck.
Never pay for a program that you can't really test out first. 30-day full
working versions are cool. Stripped down demo's are not true trial
software.
Perl2Exe needs to get ignored until someone writes a better and 30-day test
version. Assuming they are even going to charge for it.
"Tony Van der Voort" <tvdv@advalvas.be> wrote in message
news:3af872a5.51524068@news.skynet.be...
> Dear all,
>
> I'm doing tests with Perl2Exe for linux, but before I want to spend
> 150$ to buy the official version, i want to be shure that i can do
> everything i want with it. The demo version is too limited to test all
> the option (no tiny and small mode). Can some borrow me a registration
> code ? I assume you that this is just for test. I buy immediatly my
> own version after a positive evaluation of this tool.
>
> Many thanks for the help and understanding !
------------------------------
Date: Wed, 9 May 2001 09:43:10 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Perl 2 Exe
Message-Id: <pX%J6.3$3c.3693@vic.nntp.telstra.net>
"Tony Van der Voort" <tvdv@advalvas.be> wrote in message
news:3af872a5.51524068@news.skynet.be...
> Dear all,
>
> I'm doing tests with Perl2Exe for linux, but before I want to spend
> 150$ to buy the official version, i want to be shure that i can do
> everything i want with it. The demo version is too limited to test all
> the option (no tiny and small mode). Can some borrow me a registration
> code ? I assume you that this is just for test. I buy immediatly my
> own version after a positive evaluation of this tool.
>
I have had better success with PerlApp from the PDK which is available from
Activestate.
Wyzelli
--
@x='074117115116032097110111116104101114032080101114108032104097099107101114
'=~/(...)/g;
print chr for @x;
------------------------------
Date: 8 May 2001 23:44:35 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Prices for work?
Message-Id: <989365468.973125@elaine.furryape.com>
In article <cfLJ6.73777$U4.16942084@news1.rdc1.tn.home.com>,
Todd Smith <todd@designsouth.net> wrote:
> Just
>tell them it's really complicated code even if it's not
I'd have to disagree with this.
Perhaps the person hiring you is ignorant, perhaps she's a perl expert
but just too busy to do the work. Even if he's ignorant, perhaps he
might explain the problem to a friend, who is an expert. Either way,
the customer might find out that the code isn't complicated, in which
case in their eyes you're either incompetent or a liar, neither of
which is going to get you rehired.
------------------------------
Date: 9 May 2001 00:47:08 GMT
From: Betty Lee <bettylee@Stanford.EDU>
Subject: Re: Prices for work?
Message-Id: <9da42c$7na$1@nntp.Stanford.EDU>
Todd Smith <todd@designsouth.net> wrote:
+ "Bryan Coon" <bcoon@sequenom.com> wrote in message
+ > I have been asked do do some contract work for a local company, which
+ > involves installing a perl htaccess/htpasswd manager program and
+ > modifying the code to suit their needs. Nothing major, just a few hours
+ > work at most.
+ >
+ > Can someone please point me to some resources that will help determine
+ > how much I should charge them?
+ >
+ > For example, what's the going rate on perl programmers? I have been
+ > programming in perl for about 3 years, but it has always been for my
+ > company, never outside. I hear crazy rumors of people paying 50k for a
+ > static site with less than 10 pages, which I cannot verify. I just need
+ > to get a ballpark idea of what is acceptable, so I dont overcharge or
+ > undercharge.
+
+ I'd say $30-40 an hour unless you're in a huge city, then go $50-$60.
+ Just tell them it's really complicated code even if it's not
I strongly disagree with that. I don't know about other people, but I'm
less likely to pay a higher hourly rate for someone who thinks a task is
complicated. The higher wages will go to the person who can get the task
done better in less time, and if the contractor gets bogged down coding
basic functionality, they're not going to be very efficient. Also,
$60/hr sounds rather low, but I haven't worried about prices since the
downturn, and I imagine prices vary quite a bit depending on your local
region.
--
Betty Lee
bettylee@Stanford.EDU
------------------------------
Date: Tue, 8 May 2001 19:04:29 -0500
From: "Ray Doerr" <rdoerr@planetkc.com>
Subject: Problem writing to a socket after forking
Message-Id: <tfh2f5drsmmgad@corp.supernews.com>
I am having a problem writing to a socket after I have forked on a Windows
2000 machine. I have the forking part working perfectly. The problem is
once I send on the socket, it is never sent out the ethernet port until the
send function is called two or three times. After the second or third call
to send, I finally see the first packet that was send and sometimes the
second as well. It appears to be a problem with the autoflush buffer with
module IO:Socket, but since version 1.18 the autoflush buffer is enabled by
default. Below is my test script that can be used to recreate this problem.
If you send it any data on UDP Port 1813, it will echo the packet back to
the sender. The interesting thing here is if the number of Worker Threads
is reduced to 1 with the for loop, it works fine. Another problem I have is
with the creation of the Worker Threads, if the sleep in the Work Thread
function is commented out, only the first Thread is created, but with a 1
second sleep, everything works fine. Any help would be greatly appreicated
as I have been pulling my hair out for 1 week now. Here is the code:
Thanks Ray Doerr
require 5.005;
use strict;
use IO::Socket;
use IO::Handle;
# Default some variables
my ($datagram, $socket) = "";
#-- Open a socket
$socket = IO::Socket::INET->new(LocalPort => '1813',
Proto => "udp")
or die "Can't open UDP Port: $@\n";
my ($tid) = "";
my ($thread_count) = 0;
print "Parent Thread ID = $$\n";
# Create 5 Worker Threads
for (my $i=1; $i<=5; $i++) {
if (defined($tid = CreateThread(\&WorkerThread))) {
print "Count = $i, Thread ID = $tid\n";
$thread_count++;
} else {
print "Count = $i, *** Failed to Create Thread ***\n";
}
#sleep 1; # Small delay between Thread Creation, but not required.
}
print "A total of $thread_count Worker Threads are now running\n";
# Catch any error from the Threads
while ($thread_count) {
# Wait if any Thread die.
$tid = wait(); # Wait for Exit Status Code ($?) from child.
# A Code of 0 indicates that the child exited normally
$thread_count--;
print "Thread ID = $tid Ended, Exit Status Code = $?, $thread_count
remaining\n";
}
print "Program has Terminated!\n";
exit;
sub WorkerThread {
my ($datagram) = "";
$| = 1; # This force Perl to flush the output buffers after every Print or
Write operation, STDOUT
sleep 1; # If this sleep is not present only the first Worker Thread is
created.
print "Worker Thread $$ is now ready to accept Packets\n";
eval {
while ($socket->recv($datagram, 1024)) {
print "Thread=$$, Received datagram from IP=" . $socket->peerhost() . ",
Port=" . $socket->peerport() .
", Length=".length($datagram)."\n";
# Send a Response back to the Client.
if (my $sent = $socket->send($datagram)) {
print "$sent bytes Sent OK\n";
} else {
print "Failed sending Response";
}
}
};
print "Unknown error occured in Thread $$: $@, $!\n";
sleep 5;
}
sub CreateThread {
my ($subroutine) = @_;
my ($pid) = fork();
if (defined($pid)) {
if( $pid == 0 ) {
# If $pid = 0, then this is the Child Thread. $$ is the pseudo-process
ID
$| = 1; # This enables the autoflush buffer, if it's not
# there, you won't see the output from the Thread!
&$subroutine;
exit();
}
}
# This function will now return with the Thread ID or return UNDEFINED
# if Creation of the Thread Failed.
return $pid;
}
------------------------------
Date: Tue, 08 May 2001 22:15:13 GMT
From: fxn@isoco.com (F. Xavier Noria)
Subject: Re: Question about "->" operator
Message-Id: <3af86f6d.56955690@news.iddeo.es>
On Tue, 08 May 2001 18:04:12 -0400, Ed Napier <napes@attglobal.net> wrote:
: I don't really understand what I'm asking perl to do when I use "->".
: Can
: someone explain it to me? I checked perlop, but that really doesn't
: click.
Perhaps perldoc perlreftut could help?
-- fxn
------------------------------
Date: Wed, 09 May 2001 00:00:43 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Question about "->" operator
Message-Id: <LM%J6.80273$U4.17635470@news1.rdc1.tn.home.com>
"Ed Napier" <napes@attglobal.net> wrote in message
news:3AF86D5C.E3848F99@attglobal.net...
> I feel as though I'm misunderstanding something. I think the thing I'm
> missing is a complete understanding of the "->", the infix dereference
> operator.
> $cds->{$host}->{$src} = $dest;
This tells perl to look at $cds as a reference to a hash. When you put
the -> on the end, you are dereferencing it with the key $host. the -> on
the end of that statement means that the value of $cds->{$host} is also a
hashref, and you dereference it with the key $src, the value of which is a
scalar.
> $cds{$host}->{$src} = $dest; # This line does what I want.
You have a hash called %cds. $cds{$host} looks up the key $host in the hash
%cds. The code above and this one use two different variables, $cds and
%cds. This line looks up $host in the normal hash %cds, and returns a
hashref. Then you look up $src in that hashref and assign it a scalar.
if you want the first line to work, put this line above it:
$cds = { %cds };
-todd
------------------------------
Date: Tue, 08 May 2001 22:09:05 GMT
From: fxn@isoco.com (F. Xavier Noria)
Subject: Re: Seeking a PERL Tutorial
Message-Id: <3af86d5c.56426413@news.iddeo.es>
On Tue, 8 May 2001 17:39:54 -0400, Neal Weissman <nweissma@mathlab.sunysb.edu> wrote:
: Please recommend a PERL tutorial.
Choose one:
http://www.perl.com/reference/query.cgi?tutorials
though I encourage you to get a copy of "Learning Perl", aka "The
Llama Book", the best intro to a programming language I've ever read.
-- fxn
------------------------------
Date: Wed, 9 May 2001 00:02:16 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Seeking a PERL Tutorial
Message-Id: <Pine.LNX.4.30.0105082359160.26979-100000@lxplus003.cern.ch>
On Tue, 8 May 2001, Neal Weissman wrote:
> Please recommend a PERL tutorial.
Silly question, without knowing where you're starting from.
Please read the FAQs (perlfaq2 for starters) and see how the resources
cited there meet your needs and existing skillset. Come back with a
more specific question when you feel ready.
------------------------------
Date: 08 May 2001 16:21:31 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sort String
Message-Id: <m1vgnb77gk.fsf@halfdome.holdit.com>
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
RLS> and never use split /(....)/.
Uri> well, not until you know why you need to use it. i have rarely used it
Uri> but it has a use nonetheless. sometimes you want to keep the fields and
Uri> their delims (which could be odd and not just fixed strings).
In which case it's still more natural to teach:
my %hash = /(.*?)=(.*)\n/g;
which comes out extremely awkward if you try to write it as a
capturing split.
Naah... I've pretty much given up on capturing splits.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 08 May 2001 18:34:56 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Take out lines that are flagged
Message-Id: <m3y9s7zcz3.fsf@mumonkan.sunstarsys.com>
"Jim F" <jimbob4334@deja.com> writes:
> I have a file that has many fields in it. The first field is the
> unique id for the record. ($id)
>
> There is field called $flagged, if there is a value in flagged, I want
> to remove the record of data that has the matching $if.
>
> I want to be able to go through the file and grab all the $flagged
> values then go through a second time and remove those where $id
> matches $flagged.
>
> File is tab seperated, so I use split to load it into variables for
> each line then dump it into a pipe seperated file.
>
> What is the best way to remove the flagged $id ???
I don't know about the best, but this might qualify as the worst:
% perl -wle'
$"="|";
delete @_{ map{ (local @_ = split /\t/) < 4 ? () :
do{ chomp( $_{$_[0]} = "@_[0,2,3]" ); $_[1] }
} <>
};
print join "\n", values %_;
'
--
Joe Schaefer "A witty saying proves nothing."
-- Voltaire
------------------------------
Date: 08 May 2001 15:58:16 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Take out lines that are flagged
Message-Id: <m3wv7rr21j.fsf@dhcp9-172.support.tivoli.com>
On Tue, 8 May 2001, jimbob4334@deja.com wrote:
> I have a file that has many fields in it. The first field is the
> unique id for the record. ($id)
>
> There is field called $flagged, if there is a value in flagged, I
> want to remove the record of data that has the matching $if.
I assume $if is supposed to be $id.
> I want to be able to go through the file and grab all the $flagged
> values then go through a second time and remove those where $id
> matches $flagged.
>
> File is tab seperated, so I use split to load it into variables for
> each line then dump it into a pipe seperated file.
>
> What is the best way to remove the flagged $id ???
Best? I don't know about that -- TMTOWTDI.
Here's one way:
#!/usr/bin/perl
use strict;
use warnings;
chomp(my @data = grep { !/^\s*$/ && !/^Feature/ } <DATA>);
my @flagged = map { (split /\t/)[1] } @data;
for (@data) {
my($id, $flagged, $total_faults, $source_schema) = split /\t/;
next if grep { $id eq $_ } @flagged;
print "$id|$total_faults|$source_schema\n";
}
__DATA__
1234 5678 12 blue
2345 7890 23 red
5678 2345 43 yellow
3245 1243 87 orange
__END__
Note that this assumes that $id will never be null if $flagged is
allowed to be null. If $id can be null but should still not be
removed even if there is a null $flagged field somewhere, then you can
change the code to ignore null $flagged fields by using:
my @flagged = grep { length } map { (split /\t/)[1] } @data;
--
Ren Maddox
ren@tivoli.com
------------------------------
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 858
**************************************