[23973] in Perl-Users-Digest
Perl-Users Digest, Issue: 6174 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 21 18:05:39 2004
Date: Sat, 21 Feb 2004 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 21 Feb 2004 Volume: 10 Number: 6174
Today's topics:
Re: Can Perl do this task??? thumb_42@yahoo.com
Re: Checking HTML, following links and such <noreply@gunnar.cc>
Re: help on hash of hashes (Anno Siegel)
Re: how add/update/delete data in MySQL database here? (Malcolm Dew-Jones)
Re: how add/update/delete data in MySQL database here? <gnari@simnet.is>
Re: how add/update/delete data in MySQL database here? <gp@nospm.hr>
Re: how add/update/delete data in MySQL database here? <nospam@bigpond.com>
Re: How to let browsers be done when parent is done and thumb_42@yahoo.com
Re: Looking for a way to increase CPU usage <wiser@invalid.invalid>
Re: Looking for a way to increase CPU usage (Anno Siegel)
MAKE LOADS OF MONEY FOR FREE <me@ntlworld.com>
Re: PERL/MySQL tutorial <nospam@bigpond.com>
Re: replace unicode characters by &#number; representat (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 21 Feb 2004 20:21:21 GMT
From: thumb_42@yahoo.com
Subject: Re: Can Perl do this task???
Message-Id: <55PZb.375919$na.567743@attbi_s04>
Bob Mariotti <R.Mariotti(at)FinancialDataCorp.com> wrote:
> Unix system: I have a compiled application that can only use STDIO
> but I now need it to talk to a remote server using TCP on a particular
> socket.
>
> I've tried some hardware type interfaces in between but its difficult
> if not impossible to control the port assignments.
>
> I was thinking that I could create a perl program and via a pipe
> connect it to my compiled application and the perl program could use a
> module like Sockets::IO to connect to and pass the IO through both
> ways. Sometimes the traffic is incoming and sometimes its outgoing.
>
> Am I crazy or would this be possible and viable? Any other
> suggestions also appreciated.
It's viable and possible too, just look at what rsh/ssh do. :-)
Speaking of which, why not just use ssh?
Jamie
------------------------------
Date: Sat, 21 Feb 2004 20:05:01 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Checking HTML, following links and such
Message-Id: <c18aci$1fsean$1@ID-184292.news.uni-berlin.de>
Joti wrote:
> "Ben Morrow" <usenet@morrow.me.uk> skrev i meddelandet
> news:c1893k$mb$1@wisteria.csv.warwick.ac.uk...
>>
>> Try WWW::Mechanize.
>
> I'm sorry, but i don't really know that much about perl, only the
> basic stuff. Not about what ever WWW::Mechanize is. I've made a
> google search but I still don't seem to understand. Could someone
> explain?
It's a Perl module, available at www.cpan.org.
One of the characteristics of Perl is that a lot of useful tools are
provided in the form of modules, i.e. separate files with code that
you load into your main program and make use of in accordance with the
documentation for respective module. WWW::Mechanize is not part of the
standard Perl distribution, so to use it, you need to download and
install it. Learning how to do that is one of the first things you
should do.
http://learn.perl.org/
HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 21 Feb 2004 19:14:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: help on hash of hashes
Message-Id: <c18ang$8t9$1@mamenchi.zrz.TU-Berlin.DE>
Stephen Moon <vibfft@yahoo.com> wrote in comp.lang.perl.misc:
[in reply to a posting of mine (Anno)]
> Have another question. I fixed the code as you told me to
Please show a little of the context you are replying to. It seems to
me that you are really replying to Paul Lalli. You have incorporated
some of his advice, it appears, but partly ignored mine.
You did reduce the code to the essentials, and that makes it much more
usenet-friendly. Now if it also used the DATA filehandle for input, and
STDOUT for output, instead of external files, it would be an ideal
example of code you can copy/paste into an editor and run it. Well,
there is still an unused and undeclared variable. The code should run
under strict and warnings.
> while ( my $line = <DATA_IN> ) {
> chomp($line);
> if($line =~ s/^(.*?):\s*//){ <===fixed here
> my $who = $1;
> $rfwho = \$who;
Unused, undeclared. Why is it here?
> my $rfrec = {};
> $HoH{$who} = $rfrec;
> for my $field ( split /\s+/, $line) {
> my ($key, $value) = split /=/,$field;
> $rfrec->{$key} = $value;
> }
> }
> }
>
> foreach my $family ( sort keys %HoH ) {
> printf(DATA_OUT "$family:\n");
> foreach my $role ( sort keys %{ $HoH{$family} } ) {
It doesn't make much sense to sort the roles, since they are largely
independent in each family. If there were a set of roles that must
be present in every family it would make sense to place these first
and sort them, but in general it doesn't.
> printf(DATA_OUT "$role=$HoH{$family}{$role}\n");
Still using printf without a format. I told you it's going to bite.
> }
> }
>
> The output that I get is below:
>
> flintstones:
> lead=fred
> pal=barney
> jetsons:
> boy=elroy
> lead=george
> wife=jane
> simpsons:
> kid=bart
> lead=homer
> wife=marge
>
> How can I change the above code so that I can output as below?
To see the relation of what you have to what you want more clearly,
print one line for each family. I think your original code tried to
do that, but it didn't seem to make sense then. It does now. So,
instead of your second loop, do this:
foreach my $family ( sort keys %HoH ) {
my $line = "$family: ";
foreach my $role ( keys %{ $HoH{$family} } ) {
$line .= "$role=$HoH{$family}{$role} ";
}
print "$line\n"; # not printf!
}
This prints
flintstones: pal=barney lead=fred
jetsons: boy=elroy lead=george wife=jane
simpsons: kid=bart lead=homer wife=marge
while you want
> flintstones:,jetsons:,simpsons:
> lead=fred,boy=elroy,kid=bart
> pal=barney,lead=george,lead=homer
> ,wife=jane,wife=marge
Looking at it and squinting a little we see that the columns of the first
one make up the lines of the second. So the problem turns out to be
one of matrix transposition.
> Is this even possible? I have been struggling with this one a bit.
It's certainly possible, I'll sketch a solution. You may want to try and
come up with your own method, the one I'm using is a little advanced.
It also ignores the HoH representing the families. Looking at the
line-wise output again, it appears that it essentially reproduces the
input lines. So to arrive at the wanted output, we can start directly
from the input without building the HoH structure.
We build an array of arrays, splitting the input lines on white space,
then transpose that. The first line of the resulting array of arrays
contains the families, the following lines contain the various roles.
We never bothered to separate the role specifications ("lead", "wife"...)
from the associated names. We print the families and the role lines in
slightly different formats. The result is:
flintstones: jetsons: simpsons:
lead=fred, lead=george, lead=homer
pal=barney, wife=jane, wife=marge
, boy=elroy, kid=bart
The table is differently arranged from your example, but it contains
the same information.
Anno
--------------------------------------------------------
#!/usr/bin/perl
use strict; use warnings;
my @columns = transpose( map [ split], <DATA>);
print "@$_\n" for shift @columns; # print header
foreach ( @columns ) {
print join( ', ', @$_), "\n"; # print role columns
}
sub transpose {
my $max = 0;
$max > @$_ or $max = @$_ for @_; # length of longest line
map [ map shift( @$_) || '', @_], 1 .. $max;
}
__DATA__
flintstones: lead=fred pal=barney
jetsons: lead=george wife=jane boy=elroy
simpsons: lead=homer wife=marge kid=bart
------------------------------
Date: 21 Feb 2004 11:59:11 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: how add/update/delete data in MySQL database here?
Message-Id: <4037b88f@news.victoria.tc.ca>
PHP2 (gp@nospm.hr) wrote:
: how add/update/delete data in MySQL database here?
: CREATE TABLE IF NOT EXISTS example
: (
: item VARCHAR(255) NULL,
: category VARCHAR(255) NULL,
: picture LONGBLOB NULL,
: model VARCHAR(255) NULL,
: serial_number VARCHAR(255) NULL,
: information TEXT NULL,
: date_purchased DATE NULL,
: depreciation DOUBLE NULL,
: assigned_display DOUBLE NULL,
: depreciation_life DOUBLE NULL,
: remaining_life DOUBLE NULL,
: cost DOUBLE NULL,
: book_value DOUBLE NULL
: ) TYPE=MyISAM;
`DBI' - found on CPAN
You would also need the mysql DBD module
Once installed, type perldoc DBI for usage instructions.
--
Web Work Wanted, Perl Projects Programmed, Database Development Done.
I'm looking for telecommute projects. (Paying that is, various
arrangements possible.)
------------------------------
Date: Sat, 21 Feb 2004 21:15:35 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: how add/update/delete data in MySQL database here?
Message-Id: <c18ho3$47d$1@news.simnet.is>
"PHP2" <gp@nospm.hr> wrote in message news:c185kj$m85$1@ls219.htnet.hr...
> how add/update/delete data in MySQL database here?
>
>
>
> CREATE TABLE IF NOT EXISTS example
> (
> item VARCHAR(255) NULL,
> category VARCHAR(255) NULL,
[snip more SQL]
> any help?
INSERT INTO example ('foo','bar');
UPDATE example set information='none' WHERE item='foo';
DELETE FROM example WHERE cost>0;
gnari
P.S.: DBI can help
------------------------------
Date: Sat, 21 Feb 2004 23:38:02 +0100
From: "PHP2" <gp@nospm.hr>
Subject: Re: how add/update/delete data in MySQL database here?
Message-Id: <c18miv$b2f$1@ls219.htnet.hr>
I am totaly newbie in Perl.. can you write to me whole script?
"gnari" <gnari@simnet.is> wrote in message
news:c18ho3$47d$1@news.simnet.is...
> "PHP2" <gp@nospm.hr> wrote in message news:c185kj$m85$1@ls219.htnet.hr...
> > how add/update/delete data in MySQL database here?
> >
> >
> >
> > CREATE TABLE IF NOT EXISTS example
> > (
> > item VARCHAR(255) NULL,
> > category VARCHAR(255) NULL,
>
> [snip more SQL]
>
> > any help?
>
> INSERT INTO example ('foo','bar');
>
> UPDATE example set information='none' WHERE item='foo';
>
> DELETE FROM example WHERE cost>0;
>
> gnari
>
> P.S.: DBI can help
>
>
>
>
>
------------------------------
Date: Sun, 22 Feb 2004 08:54:53 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: how add/update/delete data in MySQL database here?
Message-Id: <1859826.qnntlf9aQj@GMT-hosting-and-pickle-farming>
PHP2 wrote:
> how add/update/delete data in MySQL database here?
As I previously explained, you are a moron.
GO AWAY.
gtoomey
------------------------------
Date: Sat, 21 Feb 2004 20:26:51 GMT
From: thumb_42@yahoo.com
Subject: Re: How to let browsers be done when parent is done and not wait for childrn's finishing in CGI
Message-Id: <faPZb.370386$xy6.1926713@attbi_s02>
[ Note: follow-up set, and cross-posted to appropriate newsgroup]
Zhidian Du <zdu@cs.nmsu.edu> wrote:
> I am writing a CGI program and find that the browsers always wait for
> all the processes to be done, it will be done.
>
> What I want to do is to let browsers say "done" on its status bar when
> parent is done, which is very short and do not let it say
> "transferring data...." since childrn take very long time.
>
> How to do it.
This is more of a CGI issue than a perl issue.
Basically, you need to close STDOUT to tell the browser that your done.
You have to do this in the child process too. (do it right away, and make
sure the buffers are flushed first)
Jamie
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
------------------------------
Date: Sat, 21 Feb 2004 19:36:23 GMT
From: Miser <wiser@invalid.invalid>
Subject: Re: Looking for a way to increase CPU usage
Message-Id: <hpcf3096jlpu8g5k909jq5irqm2sblhvrt@4ax.com>
From some of the posts here it appears many have misinterpreted the
OP's intent. I believe he is looking for a CPU stressor, something to
cause increased CPU usage as an artificial load for a specified time
period.
------------------------------
Date: 21 Feb 2004 20:55:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Looking for a way to increase CPU usage
Message-Id: <c18gjq$bu4$1@mamenchi.zrz.TU-Berlin.DE>
Miser <wiser@invalid.invalid> wrote in comp.lang.perl.misc:
> From some of the posts here it appears many have misinterpreted the
> OP's intent. I believe he is looking for a CPU stressor, something to
> cause increased CPU usage as an artificial load for a specified time
> period.
That's what I thought, and since it's fun to write a busy wait,
here goes:
sub consume {
my $limit = cputime() + shift;
1 while cputime() < $limit;
}
# return whatever defines cpu time in your context
sub cputime {
my ( $user, $system) = times;
$user + $system;
}
This should consume almost exactly the requested amount of time, plus
a tiny overshoot.
Anno
------------------------------
Date: Sat, 21 Feb 2004 19:08:27 +0000
From: "me" <me@ntlworld.com>
Subject: MAKE LOADS OF MONEY FOR FREE
Message-Id: <6ZPZb.11641$ft.10026@newsfe1-win>
MAKE MONEY!!!MAKE MONEY!!!
MAKE THOUSANDS!!!
I found this on a bulletin board and decided to try it: I don't care
about the useless pre-fabricated crap this message usually says. All I
say is, it works. Continue pre-fab crap.
WELL GUESS WHAT!!!
Within five days, I started getting money in the mail!! I
was shocked!! I figured it would end soon, but the money just kept
coming in. In my first week, I made about $63.00 By the end of the
second week I had
made a total of $1873.00!! In the third week I had made a total of
$9,612.00 and more mail kept coming in!! This is now my fourth week and I
have made a total of $35,165.00 and it's still coming rapidly. It's
certainly worth $6.00 and six stamps, and I have spent more than that
on the lottery without ever winning!!!
My mailman asked me what was with all the mail , and when i showed him this
system he was amazed and got going at it . Everyday he thanks me , it feels
good to know your helping make other pepole have more time and money to do the
things they care about most .(Dont let this pass you buy , it so easy and it
realy does work)
Let me tell you how this works and most important, why it
works..........
also make sure you print this out NOW, so you can get the information
off of it, as you will need it. I promise you that if you follow the
directions exactly that you
will start making more money than you thought possible by doing
something so easy!!
Suggestion: Read this entire message carefully!! (Print it out or
download it)
Follow the simple directions and watch the money come in!! It's easy.
It's legal. And, your investment is only $6.00 (Plus postage) !!!
IMPORTANT:
This is not a rip-off, it is decent; it's legal; and it is virtually
no risk - it really works!! If all the following instructions are
adhered to, you will receive extraordinary dividends.
PLEASE NOTE:
Please follow the directions EXACTLY, and $50,000 or more can be yours
in 20 to 60 days. This program remains successful because of the
honesty and
integrity of the participants. Please continue its success by
carefully adhering to
the instructions. You will now become apart of the Mail Order
business. You
are in the business of developing Mailing Lists. Many large
corporations are
happy to pay big bucks for quality lists. However, the money made from
the
mailing lists is secondary to income which is made from people like
you and me asking to be included in that list. Here are the four easy
steps to success.
STEP ONE:
Get six separate pieces of paper and write the following on
each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST."
Now get 6 U.S. $1.00 bills and place ONE inside of EACH of the six
pieces of paper so the bill will not be seen through the envelope (to
prevent thievery). Next, place one paper in each of the six envelopes
and seal them. You now should have six sealed envelopes, each with a
piece of paper stating the above phrase, your name and address, and a
$1.00 bill. What you are doing is creating a service.
THIS IS ABSOLUTELY LEGAL!!!!!
You are requesting a legitimate service and you are paying for it!!
Like
most of us I was a little skeptical and little worried about the legal
aspects
of it all. So I checked it out with the U.S. Post Office
(1-800-238-5355) and they
confirmed that it is indeed legal!!
Mail the six envelopes to the following addresses:
1) A. L. Alexander
12 Briggate
Elland Bridge
Elland
HX5 9DP
England
2) G. Burrows
1/264 Tor St
Toowoomba QLD
4350 Australia
3) J. Safian
6950 W. Forest Presrv. Dr., #115
Norridge, IL 60706-1324
4) R. Ansems
Gen. Foulkesstraat 5
4641 BW Ossendrecht
Netherlands
5)C. Milligan
6597 Herry Rd.
Vernon BC
Canada
V1B3T6
6)s. Foster
39 Poplar Avenue,
Hollins,
Oldham,
England
STEP TWO:Now take the #1 name off the list that you see above, move
the other names up (six becomes 5, 5 becomes 4, and etc.) and add YOUR
NAME as number 6 on the list.
STEP THREE:
Change anything you need to but try to keep this article as close to
original as possible. Now post your amended article to at least 200
news groups. :
(I think there are close to 24,000 groups) All you need is 200, but
remember, the more you post, the more money you make!! This is
perfectly legal!! If you have any doubts, refer to Title 18 Sec. 1302
& 1341 of the Postal Lottery laws. Keep a copy of these steps for
yourself and whenever you need money, you can use it again, and again.
PLEASE REMEMBER that this program remains successful because of the
honesty and integrity of the participants and by their carefully
adhering to directions. Look at it this way. If you were of integrity,
the program will continue and the money that so many others have
received will come your way.
NOTE: You may want to retain every name and address sent to you,
either on a computer or hard copy and keep the notes people send you.
This VERIFIES that you are truly providing a service. (Also, it might
be a good idea to wrap the $1 bill in dark paper to reduce the risk of
mail theft). So, as each post is downloaded and the directions
carefully followed, all members will be reimbursed for their
participation as a List Developer with one dollar each. Your name
will move up the list geometrically so that when your name reaches the
#1 position you will be receiving thousands of dollars in CASH!!! What
an opportunity for only $6.00 ( $1.00 for each of the first six people
listed above) Send it now, add your own name to the list and you're in
business!!!
*****DIRECTIONS FOR HOW TO POST TO NEWS GROUPS!!!*****
STEP ONE: You do not need to re-type this entire letter to do your own
posting. Simply put your cursor at the beginning of this letter and
drag your
cursor to the bottom of this document, and select 'copy' from the edit
menu. This
will copy the entire letter into the computer's memory.
STEP TWO:
Open a blank 'notepad' file and place your cursor at the top
of the blank page. From the 'edit' menu select 'paste'. This will
paste a copy
of the letter into the notepad so that you will add your name to the
list.
STEP THREE:
Save your new notepad file as a text file. If you want to do your
posting in different settings, you'll always have this file to go back
to.
STEP FOUR:
You can use a program like "postXpert" to post to all the newsgroups
at once.
You can find this program at <http://www.download.com>.
Use Netscape or Internet Explorer and try searching for various new
groups (on- line forums, message boards, chat sites, discussions.)
STEP FIVE:
Visit message boards and post this article as a new message by
highlighting the text of this letter and selecting paste from the edit
menu. Fill in the subject, this will be the header that everyone sees
as they scroll through the list of postings in a particular group,
click the post message button. You're done.
Congratulations!!!!!!
THAT'S IT!! All you have to do, and It Really works!!!
Best Wishes
------------------------------
Date: Sun, 22 Feb 2004 08:52:01 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: PERL/MySQL tutorial
Message-Id: <2170047.dWblGRtRzL@GMT-hosting-and-pickle-farming>
PHP2 wrote:
> all URLs are standard Help pages.. but facts that on market realy have not
> examples of some private person.. other programming languages have simialr
> tutorials from private persons..
That's unintelligible nonsense.
gtoomey
------------------------------
Date: 21 Feb 2004 21:29:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: replace unicode characters by &#number; representation
Message-Id: <c18ijc$d1o$1@mamenchi.zrz.TU-Berlin.DE>
Alan J. Flavell <flavell@ph.gla.ac.uk> wrote in comp.lang.perl.misc:
>
> Suppose I've read-in a line of text which can contain a large
> repertoire of characters. Assume that I've done it using Perl's
> native unicode support, a la
>
> binmode IN, ':encoding(whatever)';
>
> specifying, of course, the correct external character encoding for
> the input file that I'm reading, whatever it might be.
>
> I've come up with this regex[1]
>
> s/([^\0-\177])/'&#'.ord($1).';'/eg;
>
> to replace all non-ASCII characters by their &#number; representation.
Considerations aside whether this should be done on I/O level, if what
you want is the recoded string, there's nothing wrong with it. In
particular, /e has none of the bad smell of string eval (/ee does,
a bit). Ben's suggestion about :ascii: is a good one, and I'd space
out the perl code in s///e as usual, so
s/([^[:ascii:]])/'&#' . ord( $1) . ';'/eg;
but that's only stylistics.
> Is this indeed the simplest approach, or am I missing some simpler
> code than writing ord($1) and using /e to evaluate it?
I can't think of anything more elementary than ord().
Anno
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6174
***************************************