[12846] in Perl-Users-Digest
Perl-Users Digest, Issue: 256 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 26 01:07:22 1999
Date: Sun, 25 Jul 1999 22: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 Sun, 25 Jul 1999 Volume: 9 Number: 256
Today's topics:
Re: 18+ ONLY PLEASE 11609 (Tad McClellan)
Re: AIX socket broken-ness? <paulblake@mindspring.com>
Re: directory sizes <ron_savage@non-hp-australia-om5.om.hp.com>
Re: Extracting plain text from email (Michael Rubenstein)
Re: Extracting plain text from email (Michael Rubenstein)
Re: Extracting plain text from email (Abigail)
Re: FAQ 8.37: How do I make my program run with sh and (Michael Wang)
Re: Geekspeak Programming Contest (Abigail)
How can I get the number of users who are logging? <csanon@hotmail.com>
Re: index.cgi script help <mike@customautotrim.com>
jpg files blown away <jfrey@bon.net>
Need installation help on Apache or PWS <thetaworld@magikomik.de>
Re: need to understand do { block } (Michael Wang)
Re: Opening Sockets (Martien Verbruggen)
Re: perl cgi (Martien Verbruggen)
Re: random (elephant)
Re: random (Tony Greenwood)
Re: reg expression (Ronald J Kimball)
Re: reg expression (Abigail)
Re: reg expression (Tad McClellan)
Re: remove records from database (Chad Horton)
Re: remove records from database (Martien Verbruggen)
Removing a file using activePERL on NT <terrycat@proaxis.com>
Re: Removing characters (Tad McClellan)
Re: Removing characters <JFedor@datacom-css.com>
Re: system() (Martien Verbruggen)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Jul 1999 17:33:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: 18+ ONLY PLEASE 11609
Message-Id: <8rvfn7.2pg.ln@magna.metronet.com>
O8UYFOU@UYGEDA.COM wrote:
: Wanna meet someone tonight?
: * Guys: $1 per minute
^^
Meet a guy for a dollar.
[ you should never use $1 without testing for the success of the
pattern match that you think is setting its value.
]
: * Girls: Totally FREE
Meet a girl for nothing.
I think their market concept is most very strange indeed...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 25 Jul 1999 23:32:04 -0400
From: "Paul L. Blake" <paulblake@mindspring.com>
To: Ng Pheng Siong <ngps@my-deja.com>
Subject: Re: AIX socket broken-ness?
Message-Id: <379BD6B4.EC472E59@mindspring.com>
Hi,
I've had a problem similar to what you describe and I probably did the same
as you. I use AIX as well of course. It turns out that the book actually
has the workaround in it as well. You need to say something like:
$SIG{CHLD} = sub { $reenter_loop += wait; }; # or something similar in your
# REAPER routine
$reenter_loop = 0; # variable visible to SIG{CHLD} as well as this loop.
while ((accept(...)) or ($reenter_loop)) {
if ($reenter_loop) {
$reenter_loop = 0;
next;
}
... # main body
}
Notice that the "or" comes directly after the accept() call. I've noticed
that the CHLD signal results in the accept getting unblocked and falling
through to the "or" clause. My handling of the CHLD signal is a bit of a
hack here as well ... wait will return 0 if there is no child to be reaped.
If you issue a system command or backticks in the main body, perl itself
would reap the child and the accept would stay blocked. Otherwise,
$reenter_loop will become the value of the child's pid (nonzero) and the
"if" statement will return to accept another connection.
I think what I've said here is the workaround I did ... can't recall
exactly. So I would add a variable visible to the SIG{CHLD} routine as well
as your accept() loop and then add the conditional on that variable as I did
above. See how this works. I'm sure there's probably a more elegant
workaround but this one was in the camel book itself and I think it worked
for me. If it doesn't work for you, reply to me and I'll go into work and
see what I did in my programs ... I'm sure I actually found a workaround;
just can't recall exactly what I did.
--Blake
P.S.: I always build perl from scratch and that isn't the problem you've
encountered here.
Ng Pheng Siong wrote:
> Hi,
>
> I typed in the TCP socket client/server example in the Camel book
> almost verbatim.
>
> On FreeBSD and Linux, the pair behaves as expected:
> $ ./svr
> ./svr 1769: connection from localhost [ 127.0.0.1 ] at port 1137 at Wed
> Jul 7 11:31:43 1999
> ./svr 1769: begat 1781 at Wed Jul 7 11:31:43 1999
> ./svr 1769: reaped 1781 at Wed Jul 7 11:31:43 1999
> ./svr 1769: connection from localhost [ 127.0.0.1 ] at port 1140 at Wed
> Jul 7 11:31:44 1999
> ./svr 1769: begat 1783 at Wed Jul 7 11:31:44 1999
> ./svr 1769: reaped 1783 at Wed Jul 7 11:31:44 1999
>
> $ ./cli
> 127.0.0.1 localhost localhost.localdomain
> $ ./cli
> 127.0.0.1 localhost localhost.localdomain
> $ ./cli
> 127.0.0.1 localhost localhost.localdomain
>
> On Aix, I get the following:
> $ ./svr
> ./svr 12906: server started on port 2345 at Wed Jul 7 11:34:22 1999
> ./svr 12906: connection from localhost [ 127.0.0.1 ] at port 1689 at Wed
> Jul 7 11:34:25 1999
> ./svr 12906: begat 17006 at Wed Jul 7 11:34:25 1999
> ./svr 12906: reaped 17006 at Wed Jul 7 11:34:25 1999
> $ Daemon has died, back at the prompt!
>
> $ ./cli
> 127.0.0.1 localhost
>
> Here are the programs. (I hope posting short pieces is ok.)
> $ cat svr
> #!/usr/local/bin/perl -Tw
>
> BEGIN { $ENV{PATH}='/usr/bin'; }
>
> use strict;
> use Socket;
> use Carp;
>
> sub spawn;
> sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
>
> my $port=shift || 2345;
> my $proto=getprotobyname('tcp');
> socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
> setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) or die
> "setsockopt: $!";
> bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
> listen(Server, SOMAXCONN);
>
> logmsg "server started on port $port";
>
> my $waitedpid = 0;
> my $paddr;
>
> sub REAPER {
> $SIG{CHLD}=\&REAPER;
> $waitedpid=wait;
> logmsg "reaped $waitedpid" . ($? ? " with exit $?": "");
> }
> $SIG{CHLD}=\&REAPER;
>
> for (; $paddr=accept(Client, Server); close Client) {
> my ($port, $iaddr)=sockaddr_in($paddr);
> my $name=gethostbyaddr($iaddr, AF_INET);
> logmsg "connection from $name [", inet_ntoa($iaddr), "] at port
> $port";
> spawn sub {
> exec '/usr/bin/cat /etc/hosts' or confess "can't cat: $!";
> };
> }
>
> sub spawn {
> my $coderef=shift;
> unless (@_==0 && $coderef && ref($coderef) eq 'CODE') {
> confess "usage: spawn CODEREF";
> }
> my $pid;
> if (!defined($pid=fork)) {
> logmsg "cannot fork: $!";
> return;
> } elsif ($pid) {
> logmsg "begat $pid";
> return;
> }
> open(STDIN, "<&Client") or die "can't dup client to stdin";
> open(STDOUT, ">&Client") or die "can't dup client to stdout";
> exit &$coderef();
> }
>
> $ cat cli
> #!/usr/local/bin/perl -w
>
> use strict;
> use Socket;
> my ($remote, $port, $iaddr, $paddr, $proto, $line);
>
> $remote=shift||'localhost';
> $port=shift||2345;
> if ($port=~/\D/) { $port=getservbyname($port, 'tcp') }
> die "No port" unless $port;
> $iaddr=inet_aton($remote);
> $paddr=sockaddr_in($port, $iaddr);
> $proto=getprotobyname('tcp');
> socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
> connect(SOCK, $paddr) or die "connect: $!";
> while ($line=<SOCK>) {
> print $line;
> }
> close SOCK or die "close: $!";
> exit;
>
> Anyone seen this before? Any hints what's wrong?
>
> TIA. Cheers.
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
------------------------------
Date: Mon, 26 Jul 1999 13:19:58 +1000
From: "Ron Savage" <ron_savage@non-hp-australia-om5.om.hp.com>
Subject: Re: directory sizes
Message-Id: <7ngkfq$mg7$1@ocean.cup.hp.com>
Try:
#!/usr/gnu/bin/perl -w
use File::Find;
@ARGV = ('.') unless @ARGV;
my $sum = 0;
find sub { $sum += -s }, @ARGV;
print "@ARGV contains $sum bytes\n";
--
Cheers
Bus: rons@hpaco.aus.hp.com
Home: ron@savage.net.au
http://savage.net.au/
Brian Pontz wrote in message <379a0aad.10547406@news2.channel1.com>...
>Hello,
>Does anyone know how to get a total directory size including all the
>subdirectories? I thought about using
> system("du -c /path/to/directory/");
>But I cant get this to work correctly
>
>#!/usr/local/bin/perl -w
>$max=10000;
>
>opendir(HOME, "/path/to/dir") || die "Couldnt open dir:$!";
>@array=readdir(HOME);
>closedir(HOME);
> foreach (@array) {
> next if -f;
> $name=$_;
> system("du -c /usr/home/$name/www/ | grep total | cut -f1 -dt")
> $total=<STDOUT>;
> if($total > $max) {
> print $name;
> }
> }
>This still prints out everything. I tried making the ">" into "<" but
>that didnt help.
>
>Brian Pontz
------------------------------
Date: Mon, 26 Jul 1999 03:14:01 GMT
From: miker3@ix.netcom.com (Michael Rubenstein)
Subject: Re: Extracting plain text from email
Message-Id: <379bd21c.866225@nntp.ix.netcom.com>
On 25 Jul 1999 21:22:34 -0500, abigail@delanet.com (Abigail)
wrote:
>Michael Rubenstein (miker3@ix.netcom.com) wrote on MMCLV September
>MCMXCIII in <URL:news:37aebcbe.110050624@nntp.ix.netcom.com>:
>''
>'' Where is the rule that says responses must follow quotes?
>
>
>Common sense. It's on the same page that says you shouldn't
>sort all the letters in your response.
And other people seem to think that common sense says that the
response comes before the quote. Apparently your opinion is not
universally recognized as common sense.
------------------------------
Date: Mon, 26 Jul 1999 03:57:32 GMT
From: miker3@ix.netcom.com (Michael Rubenstein)
Subject: Re: Extracting plain text from email
Message-Id: <37a0dc44.3466314@nntp.ix.netcom.com>
On 25 Jul 1999 20:11:23 -0700, Tom Christiansen
<tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting mailed to cited author]
>
>In comp.lang.perl.misc, miker3@ix.netcom.com (Michael Rubenstein) writes:
>:I repeat. Where is the rule that says responses must follow
>:quotes?
>
>Subject: FREQUENTLY IGNORED ADVICE: your quoting strategy
>Message-ID: <379bbaf8@cs.colorado.edu>
>Date: 25 Jul 1999 19:33:44 -0700
>
>The following message will be posted daily until posters get a clue.
On 25 Jul 1999 20:11:23 -0700, in comp.lang.perl.misc you wrote:
> [courtesy cc of this posting mailed to cited author]
>
>In comp.lang.perl.misc, miker3@ix.netcom.com (Michael Rubenstein) writes:
>:I repeat. Where is the rule that says responses must follow
>:quotes?
>
>Subject: FREQUENTLY IGNORED ADVICE: your quoting strategy
>Message-ID: <379bbaf8@cs.colorado.edu>
>Date: 25 Jul 1999 19:33:44 -0700
>
>The following message will be posted daily until posters get a clue.
Somehow a response escaped before it was tamed. I have canceled
it. Please ignore the previous version if you see it.
This is a very positive step. However, don't stop posting it
when you think people see your point -- just cut it down to once
or twice a month. Usenet is constantly changing.
------------------------------
Date: 25 Jul 1999 23:15:50 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Extracting plain text from email
Message-Id: <slrn7pno6d.f12.abigail@alexandra.delanet.com>
Michael Rubenstein (miker3@ix.netcom.com) wrote on MMCLV September
MCMXCIII in <URL:news:379bd21c.866225@nntp.ix.netcom.com>:
<> On 25 Jul 1999 21:22:34 -0500, abigail@delanet.com (Abigail)
<> wrote:
<>
<> >Michael Rubenstein (miker3@ix.netcom.com) wrote on MMCLV September
<> >MCMXCIII in <URL:news:37aebcbe.110050624@nntp.ix.netcom.com>:
<> >''
<> >'' Where is the rule that says responses must follow quotes?
<> >
<> >Common sense. It's on the same page that says you shouldn't
<> >sort all the letters in your response.
<>
<> And other people seem to think that common sense says that the
<> response comes before the quote. Apparently your opinion is not
<> universally recognized as common sense.
Oh, I know there are flocks of people that don't recognize common
sense, and reverse cause and effect. However, that doesn't invalidate
the fact that common sense dictates the reply comes after the quote.
Abigail
--
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 26 Jul 1999 04:07:51 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: FAQ 8.37: How do I make my program run with sh and csh?
Message-Id: <7ngmun$cf9$1@news.ml.com>
Tom Christiansen <perlfaq-suggestions@perl.com> wrote:
>
> How do I make my program run with sh and csh?
>
> See the eg/nih script (part of the perl source distribution).
what is "the eg/nih script"? Thanks.
--
Michael Wang
http://www.mindspring.com/~mwang
------------------------------
Date: 25 Jul 1999 23:09:53 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Geekspeak Programming Contest
Message-Id: <slrn7pnnr6.f12.abigail@alexandra.delanet.com>
Tom Christiansen (tchrist@mox.perl.com) wrote on MMCLV September MCMXCIII
in <URL:news:379bcb61@cs.colorado.edu>:
"" [courtesy cc of this posting mailed to cited author]
""
"" In comp.lang.perl.misc,
"" abigail@delanet.com writes:
"" :Even if he were a computer programmer, he still wouldn't have counted
"" :from 0. To be able to count from 0, you must know what 0 is. He, and
"" :the society around him didn't. Only later would Arab trading bring
"" :this Indian invention to Europe.
""
"" One-based versus zero-based is also why the hours of 1-12 before noon
"" were all orginally "AM" and those of 1-12 after noon were all originally
"" "PM". There was no zero for the hour. Yes, that meant that the hour
"" of 12 noon was deemed AM and 12 midnight deemed PM. It couldn't go
"" PM until after noon, and noon couldn't be *after* noon, so it must
"" have been AM. (I know, I know, you can argue the other way, too. :-)
"" Possibly more interesting was that midnight constituted the final hour
"" of the previous day and date, not the beginning of the subsequent one.
I would be very surprised if the 12h time system originated at the
same time as the date changing at midnight. The Romans divided night
and day into 12 hour segments, but those segments varied, as night and
day length varies from season to season. A new day started at sunset.
(This is still true in Jewish and Moslem calendars).
"" Most people being now comfortable with 0 tend to define them the other way
"" (noon as PM and midnight as AM), if at all. But it didn't always used
Reading throught the faq of sci.astro suggest that the introduction of
24 hour time, and having a day start at 00:00 (midnight) coincided.
The same faq also says that strictly speaking 12:00 is neighter AM, nor
PM. But it says that nowadays, 12:00AM is common for midnight, and 12:00PM
for noon. It also refers to 12:00M == midnight, and 12:00N == noon. It
doesn't suggest at all that 12:00PM has any reason to call itself midnight.
I've noticed that sometimes, the entire 12:00 confusion is avoided by
using 12:01 instead. For instance, trains leaving on the hour, every hour,
might have '12:01PM' in the timetable for the train leaving around noon.
"" to be that way, and you'll still now and then run across people who swear
"" it's the other way around. It's probably more reasonable to exempt noon
"" and midnight from that scheme altogether. I suggest writing "noon" and
"" "midnight", not "12:00am" or "12:00pm", as the former are unabiguous and
"" the latter are not. I know -- it's a problem in a numeric-only input
"" field, but works just fine for speech or free-form correspondence.
"" And while computers and the military enjoy the zero-based notion of
"" "00:00", this doesn't seem to go over well in the streets of America.
Oh, but the world is much larger than just America. And it seems to go
very well outside it. Or at least, live in a happy coexistance with 12h
based measurement. I have overslept on many occasions, because I had
set the alarm at 8:30 PM instead of 8:30.
24h time is an ISO standard, and also recommended by the US Naval
Observatory, the official US time keepers.
"" --tom, waiting for metric time
During the French revolution, people used a form of of metric time. Months
were divided in 3 periods of 10 days. But they didn't really like working
9 days, and have one day of rest. ;-)
Metric time isn't worth it - it doesn't solve much, and will only lead
to confusion. Noone in the world is using it. 24h based time, as opposed
to 12h based time, does solve confusion, and is being used on a large
scale already.
References:
* sci.astro FAQ. http://sciastro.astronomy.net/
* calendar FAQ. http://www.pip.dknet.dk/%7Ec-t/calendar.html
Since the relevance with Perl has approached 0, followups set.
Abigail
--
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 25 Jul 1999 23:10:38 -0500
From: "Sanon Chowchaiyaporn" <csanon@hotmail.com>
Subject: How can I get the number of users who are logging?
Message-Id: <379be02c.0@news.tamu-commerce.edu>
Hi! everybody,
I tried to write a program that shows the number of people who are logging
in. Can I just simply use $num=system 'w|wc -l'? If it's not, how can I do
it?
Thanks
Kidd
------------------------------
Date: Sun, 25 Jul 1999 21:00:22 -0700
From: Mike <mike@customautotrim.com>
Subject: Re: index.cgi script help
Message-Id: <379BDD56.268B45F@customautotrim.com>
Thanks Rik,
I really appreciate the time you took to reply. What is "utterly silly" to some
is like reading "Chinese" to others (like me). I don't hang around here, or
"lurk" as they say. I just came to ask a question without spending a week
getting to know some of the people's personalities, or reading 3000 posts. I
looked in the headers of the messages, and there was nothing related to my
question (being so utterly silly and all).
I'll try your suggestion. It seems like a good work a round to me. If I can ever
help you out Rik, please let me know.
Best regards,
Mike
"Rik." wrote:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> schreef in berichtnieuws
> 7nevtg$5oh$1@lublin.zrz.tu-berlin.de...
> Mike <mike@customautotrim.com> wrote in comp.lang.perl.misc:
> and others posted also
>
> But.. in order to answer your question:
>
> What the script does, is trying to deal with the so-called subdomains.
> The string that you pu in $url, will become visible in the address bar (as
> the visitor will be forwarded to the $url).
> This means that if you forward a visitor to
> http://www.kewlness.com/index5.html
> also the index5.html will become visible in the address bar.
>
> In order to just keep a hey-i-don't-want-a-page URL in the address bar, you
> could (and maybe should) create a directory (perhaps named 'othersite'?)
> which you forward to.
>
> This way http://subdomain.kewlness.com would load
> http://www.kewlness.com/otherside
> which is its turn loads the default page: index.html (home.htm whatsoever)..
>
> Give it a try.
>
> Rik
------------------------------
Date: Mon, 26 Jul 1999 00:20:52 -0400
From: Joe Frey <jfrey@bon.net>
Subject: jpg files blown away
Message-Id: <379BE221.9139CF3E@bon.net>
Ladies and gents, I'm trying to create a script that checks the
modification date on a jpg file. If it has changed, the program will
copy it into a different directory and call an exe to operate on the
file. I've written this much, When I try to open the file after I've
moved it Photoshop won't recognize it as a jpg. Why is this? Is there
another way to move the jpg?
Also, when I get to it, should I print a bat file to STDOUT to
run or should I pipe the file to the exe program?
The code:
($a_atime,$a_mtime,$a_ctime)=(stat("D:/fromfolder/moveme.jpg"))[8,9,10];
print "$a_atime,$a_mtime,$a_ctime\n";
#get timestamp off the new file
($b_atime,$b_mtime,$b_ctime)=(stat("D:/tofolder/moveme.jpg"))[8,9,10];
print "$b_atime,$b_mtime,$b_ctime\n";
#get timestamp off the old file
if ($a_mtime==$b_mtime) {
print "no go.1\n";
}
else {
print "this far\n";
open ( READGRAB,"D:/fromfolder/moveme.jpg" || die "can't open
READGRAB\n $!");
#read in new jpg file
open ( WRITEGRAB,">D:/tofolder/moveme.jpg" || die "can't open
WRITEGRAB\n $!");
#write in new jpg file over the old jpg file
while (<READGRAB>) { #read a line from new jpg
print WRITEGRAB $_; #write a line to old jpg
print "no go.2\n";
}
close (READGRAB || die "can't close READGRAB\n $!");
close (WRITEGRAB || die "can't close WRITEGRAB\n $!");
}
utime($a_atime,$a_mtime,"D:/tofolder/moveme.jpg");
#set the moved files modification date back to original
# Now, How do I call jpegtrans.exe (as a bat file?) and
#how do I move the jpg without crunching it!
------------------------------
Date: Mon, 26 Jul 1999 04:54:45 +0200
From: "Marko Cehaja" <thetaworld@magikomik.de>
Subject: Need installation help on Apache or PWS
Message-Id: <7ngilc$men$1@news.online.de>
Hi
I want to debug and run my cgi and pl scripts on Windows 98. I have Apache
server and if needed the Microsoft Personal Webserver. My perl is installed
properly and it runs scripts, but under PWS and Apache, doesnt write new
files, or it can open files.
I don't see how to change that on Apache or on PWS. So, the problem is that
I want my CGI scripts to be able to WRITE something on the harddisk. And I
use it just for debugging as a local server.
Can someone can help about that basic installation?
I spent already a whole day trying to install that all properly but it
didn't work.
Thanks,
Marko
------------------------------
Date: 26 Jul 1999 04:53:16 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: need to understand do { block }
Message-Id: <7ngpjs$cul$1@news.ml.com>
Perl experts,
Thanks for the explanation of (1..5). However my question is about
the do block and incorrect use of .. operator made things complicated.
Now I use something simpler.
what will be output by the following Perl script?
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
my ($i, $j);
print(
do {
foreach $i (1..2) {
$j=$i;
}
}
)
Here is my analysis:
(1) It will print what do { } returns
(2) what do returns is the last expression evaluated in the do block
[Camel book page 158]
(3) foreach (1, 2) { } is a statement, not an expression
which has no return value
(4) $j=$i is an expression and returns 1
(5) $j=1 is the first expression evaluated, which returns 1
(6) $j=2 is the last expression evaluated, which returns 1
(7) do {} should return 1
(8) print should output 1
But in fact the above Perl script output nothing (no errors either).
So I would like to know what steps in above analysis are not true? Thanks.
--
Michael Wang
http://www.mindspring.com/~mwang
------------------------------
Date: Mon, 26 Jul 1999 04:29:01 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Opening Sockets
Message-Id: <huRm3.88$1m.10318@nsw.nnrp.telstra.net>
In article <7ng8sd$2a9j$1@slrn.eurobell.net>,
"Troy Knight" <flexit@flexit.eurobell.co.uk> writes:
> I want to be able to open a socket and use the filehandle just like any
> other normal filehandle. I am on win98 and using Apache but I just can't
> work out how to do it.
You should be able to use a socket in the same way you use a file
handle... More or less.
I don't really understand why you are mentioning Apache... Is this a
CGI? In any case: The socket code shouldn't be different.
> I want to be able to use the variables $port and $address for the port and
> address to connect to, could anyone please spend a little time to give me
> the correct code. Thanks, it's very much appreciated.
# perldoc -f socket
[snip]
See the example in L<perlipc/"Sockets: Client/Server Communication">.
# perldoc perlipc
/Client\/Server
There is quite some code here.
You might also want to read:
# perldoc Socket
# Perldoc IO::Socket
The latter is more OO, while the former is more a reflection of the
standard system calls.
The 'Perl Cookbook' has many snippets of useful code, so does
'Programming Perl'.
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry. Then
Commercial Dynamics Pty. Ltd. | things get worse.
NSW, Australia |
------------------------------
Date: Mon, 26 Jul 1999 03:21:59 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: perl cgi
Message-Id: <rvQm3.77$1m.8310@nsw.nnrp.telstra.net>
In article <37986B5E.CE1C3EC3@ford.com>,
"Dennis M. Parrott" <dparrott@ford.com> writes:
> msdb159@my-deja.com wrote:
>>
>> Why doesn't straight Perl CGI scale?
>>
>
> one simple problem: process creation overhead - each CGI
> is a new process (unless you do other more complicated
> magic).
And this is relevant in what way? "Perl" ne "CGI". The problem you
outline above is true for any CGI program, irrespective of the
language.
Besides that... Whatever was meant with 'straight Perl' most likely
excludes CGI.
> This is why I have *banned* stupid crap like counter
> scripts from the intranet site I administer -- who
> wants CPU bandwidth eaten up running crappy, stupid
> scripts that don't do as good a job as grepping the
> log files.
I could write one in sh, csh or C. Or any number of other languages,
be they efficient or not. Again: Why is this perl related? You talk
about CGI. The question was about 'straight Perl'.
Are you really in a position to 'ban stupid crap like counter
scripts'?
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Mon, 26 Jul 1999 13:42:08 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: random
Message-Id: <MPG.1206841e882451d7989b79@news-server>
elephant writes ..
>Tony .. the only addition that I have to the '50 elements' solution is
>that if the probability of receiving a 2, 3 or 7 should be equal and the
>probability of receiving a 4, 5 or 6 should be equal then you could
>dispense with the 50 element array and get more exact by using the ratios
but in another response Tony wrote ...
>5% get 7
>10% get 6
>20% get 5
>35% get 4
>25% get 3
>5% get 2
to which I now respond .. Tony .. ignore my original post .. as it was
assuming stuff that wasn't the case .. go with the 20 element array ..
much simpler
--
jason - remove all hyphens for email reply -
------------------------------
Date: Mon, 26 Jul 1999 04:13:52 GMT
From: tony@webscripts.org (Tony Greenwood)
Subject: Re: random
Message-Id: <37a8e006.36072989@news.freeserve.co.uk>
Hey! e-lephant@b-igpond.com (elephant)
>>dispense with the 50 element array and get more exact by using the ratios
>
>but in another response Tony wrote ...
No sooner had I posted and I saw your other post... I wasn't ignoring
and do thank you for the inpupt.
>to which I now respond .. Tony .. ignore my original post .. as it was
>assuming stuff that wasn't the case .. go with the 20 element array ..
>much simpler
Now set in stone..And thanks:)
--
Tony Greenwood
PORTFOLIO www.webscripts.org
------------------------------
Date: Sun, 25 Jul 1999 23:21:13 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: reg expression
Message-Id: <1dvitzz.1hethd5vdia6yN@p47.tc1.state.ma.tiac.com>
Dr. Who <qwerty@post.utfors.se> wrote:
> $fff=~s/<img.*>//gi;
Well, that will certainly delete all the img tags...
(And maybe a little extra.)
> llornkcor wrote:
>
> > Is there any wild card expressions ? I would like to delete all <img
> > src="blah blah blah"> tags. Not knowing what the actual url of the
> > image is. How could I match all the characters from < to >?
> > LP
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 25 Jul 1999 23:18:50 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: reg expression
Message-Id: <slrn7pnoc2.f12.abigail@alexandra.delanet.com>
Ronald J Kimball (rjk@linguist.dartmouth.edu) wrote on MMCLV September
MCMXCIII in <URL:news:1dvitzz.1hethd5vdia6yN@p47.tc1.state.ma.tiac.com>:
'' Dr. Who <qwerty@post.utfors.se> wrote:
''
'' > $fff=~s/<img.*>//gi;
''
'' Well, that will certainly delete all the img tags...
''
'' (And maybe a little extra.)
Of not enough.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 25 Jul 1999 19:24:46 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: reg expression
Message-Id: <ub6gn7.31h.ln@magna.metronet.com>
Dr. Who (qwerty@post.utfors.se) wrote:
: $fff=~s/<img.*>//gi;
Sometimes that deletes the right thing.
Sometimes it deletes stuff that is not part of thing.
It would be better if it worked more frequently than "sometimes"...
: llornkcor wrote:
: > Is there any wild card expressions ? I would like to delete all <img
: > src="blah blah blah"> tags. Not knowing what the actual url of the
: > image is. How could I match all the characters from < to >?
: > LP
------------------------
#!/usr/bin/perl -w
use strict;
my $fff = '<img src="before.jpb"><p>good text</p><img src="after.jpg">';
$fff=~s/<img.*>//gi;
print "'$fff'\n";
------------------------
output:
''
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 25 Jul 1999 19:18:15 -0800
From: sandc@sprynet.com (Chad Horton)
Subject: Re: remove records from database
Message-Id: <WnQm3.259$9d.139473@WReNphoon3>
No, this is not SQL!
I am writing a perl script that will do this. I am not using SQL or MSQL.
I know where I posted my question and thank you for not assuming any further
as to what I am really asking.
I am sick of people answering what they please and not getting to the point
of the subject. If you don't know the anser to this specific problem, then
please do not respond!
This is a legit. perl question. I need to know how to implement this in a
perl script.
I know enough about SQL and do not want to use it in this. I also do not
want to use the SQL modules.
-**** Posted from RemarQ, http://www.remarq.com/?a ****-
Search and Read Usenet Discussions in your Browser - FREE -
------------------------------
Date: Mon, 26 Jul 1999 04:11:44 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: remove records from database
Message-Id: <4eRm3.87$1m.9356@nsw.nnrp.telstra.net>
In article <r2Jm3.152$9d.81921@wrenphoon3>,
sandc@sprynet.com (Chad Horton) writes:
> Here is my dilema:
>
> I have a database like this:
>
> 100|www.pepsi.com|10|10|80|0|
> 20|www.pepsi.com|1||1|18|0|
> 20|www.pepsi.com|1|1|18|0|
> 10|www.pepsi.de|1|1|8|0
> 65|www.remark.pepsi.com|32|20|10|3|
> 44|www.pepsi.com|10|10|12|12|
> 23|www.digipepsi.net|5|15|1|2|
> 100|www.digipepsi.net|25|30|20|25|
I will assume that you are talking about a flat text file, and not a
relational database system. If I am wrong in that: Use SQL.
> What I need to find the highest value for column 1 for all records per
> domain and remove the duplicate records.
'duplicate'? What exactly do you mean by 'duplicate'? The above does
not have any duplicate records.
If you really, really mean 'duplicate records':
# sort in file_that_contains_your_data | uniq
If you mean 'unique keys' (the things in column 1):
# sort -nu file_that_contains_your_data
Note that the above just gets rid of some of the duplicate keys, and
that you may not have any control over which ones get discarded.
If you mean anything else, sort will be able to do it anyway, but it
may be easier to write a perl script. The really easiest way would
probably be to some module that can treat a text file as a SQL-able
database thingy, and use SQL.
> So, in this case the results be be this:
>
> 100|www.pepsi.com|10|10|80|0|
> 10|www.pepsi.de|1|1|8|0
> 65|www.remark.pepsi.com|32|20|10|3|
> 100|www.digipepsi.net|25|30|20|25|
I fail to see how this removed duplicate records. Is your definition
of duplicate maybe 'has the same value in column 2'? And if that is
your definition, which of the original 'duplicates' do you want to
keep?
Then: What do you mean by domain? Do you know that that is quite a
difficult question, especially when you are dealing with addresses
outside of the US?
What I'd like you to do is to write down your question more
specifically, try a few things, read some documentation, try a few
things, read the FAQ, try a few things, and then ask again, showing us
what you tried, and why it doesn't work. Most of us have better things
to do that to try to second-guess your meaning, and waste time on
writing code, only to find out that that was not what you wanted in
the first place.
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use being
NSW, Australia | a damn fool about it.
------------------------------
Date: Sun, 25 Jul 1999 21:29:42 -0700
From: "G. Breunsbach" <terrycat@proaxis.com>
Subject: Removing a file using activePERL on NT
Message-Id: <379BE3FD.C514C30D@proaxis.com>
I'm converting a bunch of PERL scripts from UNIX to NT. I didnt' write
the UNIX scripts... one of the things the scripts do is unlink a file.
This doesn't seem to be working. Any clue on how to make this work?
line of code:
unlink ("temp/filename.p");
Please reply to me directly, as i dont' read this group often.
ThANKS!
-Gretchen (terrycat@proaxis.com)
------------------------------
Date: Sun, 25 Jul 1999 19:05:16 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Removing characters
Message-Id: <c75gn7.2pg.ln@magna.metronet.com>
Garth Sainio (modred@shore.net) wrote:
: In article <19990725161814.21146.00001525@ng-fx1.aol.com>,
: jimtaylor5@aol.com (Jimtaylor5) wrote:
: !! I'm trying to remove every first character of my variables. If it was on the
: !! end I could use chop, but how would I remove one character at the
: front without
: !! leaving a space?
: You can use substr to extract the substring from the second character onward.
: $var = substr($var, 1);
You can also use it as an lvalue (or with 4 args), to remove
the offending substr.
substr($var, 0, 1) = ''; # so long first character
substr($var, 0, 1, ''); # so long first character
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 26 Jul 1999 01:15:01 -0400
From: "Jody Fedor" <JFedor@datacom-css.com>
Subject: Re: Removing characters
Message-Id: <7ngotr$rf9$1@plonk.apk.net>
Jimtaylor5 wrote in message
<19990725161814.21146.00001525@ng-fx1.aol.com>...
>I'm trying to remove every first character of my variables. If it was on
the
>end I could use chop, but how would I remove one character at the front
without
>leaving a space?
$var = "12345";
$var =~ s/.//;
print $var;
Works too!
Jody
------------------------------
Date: Mon, 26 Jul 1999 04:38:49 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: system()
Message-Id: <tDRm3.91$1m.10318@nsw.nnrp.telstra.net>
In article <379B73D5.57718BA5@americanisp.net>,
Brad Baker <brad@americanisp.net> writes:
> This is a multi-part message in MIME format.
Please don't do that. Usenet is a plain text medium.
> The syntax for the system() function is:
>
> system("/bin/command var1 var2 etc");
Actually, it's not.
# perldoc -f system
=item system LIST
=item system PROGRAM LIST
system accepts a list, and in most cases should be called with a list,
not a single string with all the arguments in it.
If you read the documentation for list, it will even tell you what the
difference is:
"If there is more than one argument in LIST, or if LIST is
an array with more than one value, starts the program given by the
first element of the list with arguments given by the rest of the
list."
"If there is only one scalar argument, the argument is
checked for shell metacharacters, and if there are any, the entire
argument is passed to the system's command shell for parsing [...]. If
there are no shell metacharacters in the argument, it is split into
words and passed directly to C<execvp()>, which is more efficient."
> But what would I put in the system function if the command to run
> requires quotes?
> /bin/command "Hello world" "Variable two" "mystuff"
my $rc = system( '/bin/command', "Hello World', 'Variable Two', 'mystuff' );
or, if it's all a bit more complicated:
my @args = ( 'Hello World', 'Variable Two', 'mystuff' );
my $command = '/bin/command';
my $rc = system( $command, @args );
Of course you are free to embed quotes in your single string, and make
sure it gets passed to the shell that way, but it's unnecessarily
ugly and slow. If you tell system that you are executing a program,
and what its arguments are, it will do the right thing. (Using a \42
in those strings is really something I wouldn't even contemplate).
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd. | excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V9 Issue 256
*************************************