[18541] in Perl-Users-Digest
Perl-Users Digest, Issue: 709 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 18 21:05:57 2001
Date: Wed, 18 Apr 2001 18:05:14 -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: <987642314-v10-i709@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 18 Apr 2001 Volume: 10 Number: 709
Today's topics:
Blocking socket I/O <rlf@proimages.net>
Re: Blocking socket I/O <uri@sysarch.com>
DBI and hashref question... <xris@dont.send.spam>
Re: Duplicate Emails <dkelly@quisic.com>
Re: Duplicate Emails (Eric Bohlman)
Re: errors (Gwyn Judd)
FAQ .: Every post to the comp.lang.perl.misc newsgroup <faq@denver.pm.org>
Re: Filehandle problem (glob) (John Joseph Trammell)
Re: Filehandle problem (glob) <uri@sysarch.com>
Re: format must be in scope of 'my'? ugh. <pne-news-20010418@newton.digitalspace.net>
Re: format must be in scope of 'my'? ugh. <webmaster@webdragon.unmunge.net>
Re: help for a basic hash value access question (Gwyn Judd)
Re: hex to binary conversion (Craig Berry)
Re: Laziness, Impatience and Hubris :-) (Craig Berry)
Re: Laziness, Impatience and Hubris :-) <karlyoung@emailaddress.invalid>
Re: Laziness, Impatience and Hubris :-) (Damian James)
List comparison <jimbob4334@deja.com>
Multidimensional array question <nbr@newsbrowser.com>
Re: Porblems with the Perl Sleep (Andrew J. Perrin)
Re: Porblems with the Perl Sleep (David Efflandt)
Re: Problems trying to process multiple items on a sing (Dave Murray-Rust)
Re: Problems trying to process multiple items on a sing (Craig Berry)
Re: Processing all files in directory <taka@yarn.demon.co.uk>
reading a specific paragraph <rutterba@cisco.com>
Re: Slighty OT: Perl Books... <news@simonflack.com>
Re: So what do YOU use Perl for? <mischief@velma.motion.net>
Re: unicode, perl and webbrowsers <flavell@mail.cern.ch>
Using boundaries within regexps <g_adams27@hotSPAMISBADmail.com>
Re: Using boundaries within regexps <xris@dont.send.spam>
Re: Using boundaries within regexps (Craig Berry)
verifying write to file using "tie" <kimmfc@mydeja.com>
Re: workaround for sourcing file from perlscript (Brandon Metcalf)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Apr 2001 07:55:23 -0700
From: Robert Fonda <rlf@proimages.net>
Subject: Blocking socket I/O
Message-Id: <3ADDAADB.3DA2A004@proimages.net>
Ok, I'm trying to use read() from a socket. If there is no data on the
socket the read completes with 0 bytes. I need the read to block. Is
there any way to do this without using select()?
r.f
------------------------------
Date: Wed, 18 Apr 2001 16:02:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Blocking socket I/O
Message-Id: <x7y9syjiwl.fsf@home.sysarch.com>
>>>>> "RF" == Robert Fonda <rlf@proimages.net> writes:
RF> Ok, I'm trying to use read() from a socket. If there is no data on the
RF> socket the read completes with 0 bytes. I need the read to block. Is
RF> there any way to do this without using select()?
why are you trying to read it if there is no data? that is the whole
point of select.
in any case you have to make the socket non-blocking which IO::Socket
can do for you or you can do it yourself with Fcntl. even using select
the socket should be non-blocking unless you know the protocol on it
will be suitable for read or <>.
but use IO::Select to make your life much easier. the perl cookbook has
several examples. or use Event.pm which will give you a more powerful
multiplexor.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Wed, 18 Apr 2001 18:20:30 -0500
From: xris <xris@dont.send.spam>
Subject: DBI and hashref question...
Message-Id: <xris-C46433.18202918042001@news.evergo.net>
I've been messing with DBI a lot lately, and a lot of what I do ends up
being something like:
$sh = $dbh->prepare('SELECT * FROM myTable');
$sh->execute;
push @Rows, $ref while (my $ref = $sh->fetchrow_hashref);
$sh->finish;
I know that there's a "fetchall_arrayref" function, but am wondering if
there's something that returns an arrayref to hashes, rather than an
arrayref to more arrays (I have no guarantee about the order the fields
will be returned in, so I need the hash reference - plus, according to
what I've read, hashes are generally faster than accessing array
elements).
Does anyone know of a way to do this other than manually building the
array like I'm doing above?
------------------------------
Date: Tue, 17 Apr 2001 16:24:29 -0700
From: Darnell Kelly <dkelly@quisic.com>
Subject: Re: Duplicate Emails
Message-Id: <3ADCD0AD.39E15305@quisic.com>
is the FAQ at perl.com? also, another caveat...what i have is a form with
multiple checkboxes, right? basically, a person clicks any or all boxes,
writes a text message, maybe cc: someone, press submit and the emails go
forward. the @all_emails array you have can be substituted for @to which is
my argument from
my($to, $cc, $from, $subject, $message) = @ARGV; ,
correct? or is this wrong...
getting my feet wet with perl...again,
darnell
Bart Lateur wrote:
> ted wrote:
>
> >foreach (sort keys %all_emails) {
> > if ( exists $all_emails{$_} ) { next; }
> > $all_emails{$_} = $all_emails{$_} + 1;
> >
> > # do some stuff here #
> > }
>
> That's a variation on the entry in the FAQ, which basically says to use
> a hash. But there's some logic error here: if you go through the keys of
> a hash, then all of the entries will exist. You probably want
>
> foreach (sort @all_emails) {
>
> instead of
>
> foreach (sort keys %all_emails) {
>
> This is a slightly cleaned up version:
>
> my %done;
> foreach (@all_emails) {
> next if $done{$_}++;
>
> # do some stuff here #
> }
>
> Note that, for this particular problem, e-mail addresses should be
> reduced to their bare minimum, AKA the "canonical form", and also, make
> their case consisent, perhaps lower case, because e-mail addresses are
> case insensitive.
>
> --
> Bart.
------------------------------
Date: 18 Apr 2001 00:40:53 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Duplicate Emails
Message-Id: <9binql$p13$3@bob.news.rcn.net>
ted <tlav1@mediaone.net> wrote:
> I ran into a similar problem once before and this is how I solved it: I
> made the all the email addresses the keys of a hash, then check for the
> existence of the email address. If it already existed in the hash, I just
> skipped it. Something like this...
> foreach (sort keys %all_emails) {
> if ( exists $all_emails{$_} ) { next; }
> $all_emails{$_} = $all_emails{$_} + 1;
> # do some stuff here #
> }
> }
But once you've turned the array into the keys of a hash, the duplicates
have *already* been stripped out, so there's no need to test for them!
Just looping over the keys will give you the list, minus the dups:
my %nondup_emails;
@nondup_emails{@all_emails}=();
foreach (keys %nondup_emails) {
# do some stuff here
}
Note: a true Perl guru who was trying to impress others would have written
my %all_emails;
@all_emails{@all_emails}=();
foreach (keys %all_emails) {
# do some stuff here
}
Taking advantage of the fact that %variable and @variable are completely
distinct. But I'd consider that obfuscation.
------------------------------
Date: Wed, 18 Apr 2001 23:17:19 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: errors
Message-Id: <slrn9dsc09.15s.tjla@thislove.dyndns.org>
In article <dWmD6.17865$ep.5244651@news1.rdc1.tn.home.com>,
Todd Smith <todd@designsouth.net> wrote:
>Where can I get the list of common Perl errors that's in the back of the
>Blue Camel online?
You mean like in the 'perldiag' manpage?
perldoc perldiag
at the command line should do it. Or put:
use diagnostics;
at the top of your script.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Without freedom, no art; art lives only on the restrainst it imposes on
itself, and dies of all others.
-Albert Camus, Resistance, Rebellion, and Death
------------------------------
Date: Thu, 19 Apr 2001 00:16:34 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ .: Every post to the comp.lang.perl.misc newsgroup consumes the time and
Message-Id: <C7qD6.1228$T3.196825088@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
Every post to the comp.lang.perl.misc newsgroup consumes the time and
effort of readers all over the world who pay for their Internet access
just as you do. That's OK, because mutual support is what USENET is
all about. But it only works if posters check out other resources
first!
Please make an effort to find the answer to your question on your own
before posting. The resources below will help you.
BEFORE you post to this newsgroup, look at the following checklist:
1. The latest stable release of Perl is 5.6.0. The latest maintenance
release of the 5.004 track is 5.004_05, for the 5.005 track is
5.005_03. You can download them from
http://www.cpan.org/src/
(look in ftp://ftp.perl.com/perl/ for a list of FTP-based mirrors)
2. comp.lang.perl.misc is for questions on the Perl language. Try
comp.infosystems.www.authoring.cgi for questions on the CGI part of
CGI scripts. The two leading blocks of reusable code for CGI purposes
are CGI.pm, at
http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
and cgi-lib.pl, at
http://cgi-lib.berkeley.edu
You might also want to check out libwww-perl at
http://www.linpro.no/lwp/
If you are having problems with a CGI script, look through
http://language.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html
3. Are you using the following?
#!/usr/bin/perl -w
use diagnostics;
use strict;
"-w" turns on all sorts of warnings about probable errors (see the
perldiag manpage), "use diagnostics" causes the "-w" warnings to be
explained in greater detail (with the explanations from the perldiag
manpage), and "use strict" generates compile and run-time errors for
certain unsafe variable, reference and subroutine constructs (see the
strict manpage)
4. Are you checking the return values from the functions built in to
perl? Most of the file and system functions set $! and have return
values that you can test thus:
open(PASSWD, "</etc/passwd") or
die "error opening /etc/passwd: $!\n";
$! will contain an error message that will give you more information
on where your program is going wrong. The perlfunc man page will give
you more information on the return values from functions.
5. Have you read the Perl FAQ? Many questions on sockets programming,
an important and common problem with Solaris, text manipulation and
the jargon of perl are answered in the FAQ. As well as being posted
regularly to comp.lang.perl.misc, the FAQ is on the web at:
http://language.perl.com/faq/
6. Have you read the man pages? Here are some subjects and the man
pages to look in:
Objects perltoot, perlref, perlmod, perlobj, perltie
Data Structures perlref, perllol, perldsc
Modules perlmod, perlsub
Regexps perlre, perlfunc, perlop
http://www.perl.com/CPAN/doc/FMTEYEWTK/index.html
(not a man-page but still useful)
Moving to perl5 perltrap, perl
Linking w/C perlxstut, perlxs, perlcall, perlguts, perlembed
The man page for "perltoc" provides a crude table of contents for the
perl man page set.
7. Have you looked at http://www.perl.com ? This is a great
online reference, with documentation, pointers to modules in the
Comprehensive Perl Archive Network (CPAN), articles on the inner
workings of many bits of Perl, and more.
7.5. Have you checked to see if a Perl module satisfies your needs?
Many reusable modules are available for immediate download and use.
See http://www.perl.com/CPAN/modules/00modlist.long.html for details.
8. Have you tried archives of Usenet? http://www.dejanews.com/
maintains an archive of postings to Usenet dating from March, 1995.
Be sure to include "Perl" in your search.
9. The latest version of the "Camel Book" ("Programming Perl"),
updated for version 5.6.0, is available from your bookstore or from
http://www.ora.com/
10. Remember, USENET newsgroups are based on the idea of mutual aid.
USENET only works if we put as much into it as we get out of it. Good
luck with your Perl work.
-Nathan Torkington, Perl mini-FAQ maintainer
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep comming up. If you are some how irritated by
seeing these postings you are free to ignore them or add the sender
to your killfile. If you find errors or other problems with these
postings please send corrections or comments to the posting email
address.
If you are not able to find this or other Perl documentation from
your installation you may access it via the web by following the
appropriate links from one of the addresses listed below.
http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
http://www.perldoc.com
http://www.cpan.org
http://www.perl.com
Answers to questions about LOTS of other stuff, mostly not related to
Perl, can be found at
news:news.answers
and in the many thousands of other useful Usenet news groups.
Please note that the FAQ text posted by this server has been modified
from that distributed in the stable Perl release. It has been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ is available on request.
The perlfaq manual pages contain the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
When included as an integrated part of the Standard
Distribution of Perl or of its documentation (printed or
otherwise), this work is covered under Perl's Artistic
License. For separate distributions of all or part of
this FAQ outside of that, see the perlfaq manpage.
Irrespective of its distribution, all code examples here
are public domain. You are permitted and encouraged to
use this code and any derivatives thereof in your own
programs for fun or for profit as you see fit. A simple
comment in the code giving credit to the FAQ would be
courteous but is not required.
This work is provided in the hope that it will be useful but does
not represent a commitment of any kind on the part of the contributers,
authors or their agents.
--
This space intentionally left blank
------------------------------
Date: Tue, 17 Apr 2001 22:07:50 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Filehandle problem (glob)
Message-Id: <slrn9dpdgp.53c.trammell@bayazid.hypersloth.net>
On 17 Apr 2001 15:37:49 GMT, you_smell@fuckyou.co.uk wrote:
> Why is /tmp/bar empty? What am I doing wrong?
You're defining subroutines, but not calling them.
Fuck you too,
J
--
Just Another Perl Hacker.
------------------------------
Date: Wed, 18 Apr 2001 15:38:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Filehandle problem (glob)
Message-Id: <x71yqqkykd.fsf@home.sysarch.com>
>>>>> "l" == less <less@rude.not> writes:
l> package FILEGLOB;
l> use IO::File;
l> my $foo = {};
l> bless $foo, FILEGLOB;
l> $foo->handle_file;
l> sub handle_file{
l> my $self = shift;
l> my $file = new IO::File( ">/tmp/bar" ) or die ("Could not open file.\n");
indirect object calls are not considered as good style nor oare they
safe. there are some potential gotchas with them. use direct object
calls. also put $! in the die message:
my $file = IO::File->( ">/tmp/bar" ) or die ("Could not create file $!");
note that i use the term 'create' in the die when i open for writing.
l> my $msg_line = "Some foo in bar diddly.\n";
l> $self->process_message_line ($msg_line, $file);
l> $file->close;
either you are not indenting the code which is bad or your news setup is
losing the indent which is bad. either way it looks wrong here. you
appear to be using a web based newsfeed and that is almost always bad.
l> Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Wed, 18 Apr 2001 12:39:30 +0200
From: Philip Newton <pne-news-20010418@newton.digitalspace.net>
Subject: Re: format must be in scope of 'my'? ugh.
Message-Id: <ojrqdt0f1de2tgei0rfudqkfom3lpolj7q@4ax.com>
On 18 Apr 2001 07:51:06 GMT, "Scott R. Godin"
<webmaster@webdragon.unmunge.net> wrote:
> formats must be within the scope of a my declaration
True.
> Does anyone know a
> better way to write this?
>
> [begin fragment]
>
> while (my @row = $sth->fetchrow )
> {
> # need to do this in here because of the "my @row" --
> # formats MUST be within the my's scope. *ugh*
> format STDOUT_TOP =
[snip]
Well, nobody forces you to scope the "my @row" to the while block. You
could have "my @row;" right at the top of the program, which will give
@row file scope. Hence, the format can be anywhere within the same
file. (That's what I usually do when I use formats.)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 19 Apr 2001 00:58:50 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: format must be in scope of 'my'? ugh.
Message-Id: <9bld8a$klp$0@216.155.32.172>
In article <ojrqdt0f1de2tgei0rfudqkfom3lpolj7q@4ax.com>,
Philip Newton <pne-news-20010418@newton.digitalspace.net> wrote:
| Well, nobody forces you to scope the "my @row" to the while block. You
| could have "my @row;" right at the top of the program, which will give
| @row file scope. Hence, the format can be anywhere within the same
| file. (That's what I usually do when I use formats.)
yeah .. the problem occurs when certain elements of the @row array
contiain nothing -- which makes them default back to the previous value
and this fills the format with erroneous info. :)
I keep hoping there's a way to do this with references or something but
I just can't see it.
--
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw";
# ( damn spammers. *shakes fist* take a hint. =:P )
------------------------------
Date: Wed, 18 Apr 2001 23:05:08 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: help for a basic hash value access question
Message-Id: <slrn9dsb9e.15s.tjla@thislove.dyndns.org>
In article <B703BDA1-806F8@193.248.253.197>,
Francis Derive <Francis.Derive@wanadoo.fr> wrote:
>I was curious about having NO commas separating the 'a' and 'b' and 'c'. I
>thought you had forgotten them ! (I come from Lisp and I appreciate !).
>
>So , I can do this :
> $hash{2}= [qw/a b c/];
> print $hash{2}[1];
>It's OK.
>However I would prefer to see a reference to a list more than to an array :
> $hash{2}= (qw/a b c/); # does not work
That's because that is not a reference to a list. The difference between
a list and an array is more or less that an array is resizable and that
the elements can be changed. You can assign a list to an array though.
Anyway placing the brackets () around the list doesn't take a reference
to the list. Actually I'm not really sure you can take a reference to a
list, I think it would always be converted to an array reference.
Anyway the qw// operator simply takes a string as an argument and will
convert it into a list by splitting on any whitespace.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
When the rich make war it's the poor that die.
-- Jean-Paul Sartre, "Le Diable et le bon Dieu", 1951
------------------------------
Date: Wed, 18 Apr 2001 23:43:30 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: hex to binary conversion
Message-Id: <tds9l26tqvk09@corp.supernews.com>
RayJ (rayj00@yahoo.com) wrote:
: How can I turn 99(hex) into 10011001??
A brain-damaged but possibly useful approach:
#!/usr/bin/perl -w
# hexbin - convert hex to binary representation
# Craig Berry (20000418)
use strict;
my %map;
@map{'0'..'9', 'A'..'F', 'a'..'f'} =
map { sprintf '%04b', $_ } (0..15, 10..15);
while (<>) {
s/(.)/$map{$1}/g;
print;
}
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: Wed, 18 Apr 2001 23:30:15 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Laziness, Impatience and Hubris :-)
Message-Id: <tds8s797dn34a1@corp.supernews.com>
Chris Stith (mischief@velma.motion.net) wrote:
: Perl is a complex language. Programming of itself is fairly complex,
: and wouldn't do us any good if it wasn't. So expecting someone else
: to understand a statement as simple as `does not work' without great
: effort on his or her part implies that you not only believe in
: psychic phenomena, but believe in such so strongly that you should
: already know what they are going to say.
My favorite analogy is going to the doctor, stating "I don't feel well",
not answering his questions nor permitting him to examine you, and then
getting huffy when he declines to provide a diagnosis or prescription.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: Wed, 18 Apr 2001 03:18:22 +0100
From: "Karl Young" <karlyoung@emailaddress.invalid>
Subject: Re: Laziness, Impatience and Hubris :-)
Message-Id: <987560477.25444.0.nnrp-01.c2ded7c2@news.demon.co.uk>
"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
news:987518464.13083@itz.pp.sci.fi...
| In article <987441174.8613.0.nnrp-14.c2ded7c2@news.demon.co.uk>, Karl
Young wrote:
| >
| >May I ask a question though, which I hope you may be able to answer for
me?
| >As a newbie to Perl programming, how can I tell if it is relevant to post
| >here? If I have a script which doesn't run (& I've looked through my
books &
|
| Start by shunning that mantra of the ignorant, "doesn't run". Things
| never just "don't work". They fail, and they fail in some specific way
| that will tell you where the problem is, or at least where it isn't.
|
| "Complains about an insecure dependency" is a useful starting point for
| an investigation. So is "gives the expected output, but does not modify
| the files it should." So is even "gives a 500 server error." But not
| "it doesn't work!"
|
| Once you know how it fails, you can ask yourself exactly what it is that
| fails. Of course, sometimes you just can't narrow it down to a single
| possible area. In that case, you first check the FAQs for *both* areas.
| Then, if that didn't help, you post -- maybe even crosspost -- asking "I
| can't tell if the following problem is caused by [foo] or by [bar]. Can
| anyone suggest a way to figure out what the cause might be?"
|
| The important thing is to be polite, and to offer enough information up
| front so that the problem can be diagnosed in either case, preferably
| even by people who themselves only know one of the areas. Say which
| possibilities you've eliminated, too, both because that will save people
| some extra work and because you _might_ have made a mistake there.
|
| Most of all, show that you're willing to learn. Ask how to solve the
| problem, not what the solution is. Ask how to tell the difference
| between two kinds of problems, not which kind a particular problem is.
| In the end, it all boils down to the impression you make. People are,
| even here, more than willing to give you a push in the right direction.
| They just don't want to start playing Sisyphus.
|
|
| Ps. A good way to tell CGI and Perl problems apart is to test the script
| from the command line. CGI.pm even has a convenient "offline mode" for
| this. If your webspace provider doesn't give you shell access, install
| Perl on your own computer. Actually, that would be a good idea anyway.
Many Thanks Ilmari, that was very useful. I do have shell access, I will
look into the CGI.pm offline mode.
--
Karl
¸ ¸
\(Ö)/
Ô
_/ \_
------------------------------
Date: 18 Apr 2001 03:01:00 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Laziness, Impatience and Hubris :-)
Message-Id: <slrn9dq0ol.rvd.damian@puma.qimr.edu.au>
Ilmari Karonen chose 17 Apr 2001 14:46:27 GMT to say this:
>... People are,
>even here, more than willing to give you a push in the right direction.
>They just don't want to start playing Sisyphus.
>
Those to whom this makes no sense may want to refer to the only animated
gif I ever included on a webpage:
http://home.pacific.net.au/~djames.hub/imgs/sisyphus.gif
I found this somewhere or other years ago, forgot to note the source. If
you are or know the creator, please let me know :-).
Cheers,
Damian
--
NB that the pages associated with the link above are out-of-date,
unmaintained and -- since my ISP got bought by this bunch -- doomed.
------------------------------
Date: Tue, 17 Apr 2001 22:22:48 -0500
From: "Jim F" <jimbob4334@deja.com>
Subject: List comparison
Message-Id: <9bj1a8$7sk8@nntp.cig.mot.com>
Hi,
I have a file with a list on each line, if I load it into a hash or array is
there a way I can compare the contents of the whole list at once instead of
iterating through each?
I would like to do something like
if $string is found in $list then print $string
I did not know where to look.
Thanks for any help,
Jim
------------------------------
Date: Thu, 19 Apr 2001 01:30:21 +0100
From: "The NewsBrowser" <nbr@newsbrowser.com>
Subject: Multidimensional array question
Message-Id: <9blbi8$9kr9v$1@ID-18325.news.dfncis.de>
Sigh.
I'm new to Perl, and I'm trying to do something I thought would be
quite simple; read a file into an array of arrays, then print out
the contents of the array using the foreach construct.
This is what I have:
#the array
@InboxArray = ();
#reading the file into the array
my $InboxFileContents = "";
my $InboxFileContentBuffer = "";
$InboxFileName = "MyInbox.txt";
open(INBOXFILE,"<$InboxFileName");
while($InboxFileContentBuffer = <INBOXFILE>)
{
@TempArray = split(/\s/, $InboxFileContentBuffer);
push(@InboxArray, [@TempArray]);
}
close(INBOXFILE);
#writing the first three elements in each of the arrays
#in @InboxArray
foreach $Elem (@InboxArray)
{
print $Elem->[0];
print $Elem->[1];
print $Elem->[2];
}
However, nothing gets printed out. I'm sure I've made a mistake
in the references; I read the perlref, perldsc and perlreftut
documents, but I wasn't entirely clear how exactly I would handle
a multidimensional array, so I hope someone here can help me.
TIA,
--
Akin
akin at aksoto dot idps dot co dot uk
------------------------------
Date: 18 Apr 2001 19:48:34 -0500
From: andrew_perrin@unc.edu (Andrew J. Perrin)
Subject: Re: Porblems with the Perl Sleep
Message-Id: <87d7a9n28t.fsf@nujoma.perrins>
Well, I can't see why you should be getting the result below (for
those who didn't feel like going to the website, here's a code
snippet):
while ($SAMPLES-- >0) {
undef %begin,%end;
$btime = time;
%rb = do gather_stat();
# qx(sleep $SAMPLE_TIME);
print 'Sleeping...', scalar localtime;
sleep 5;
print 'slept. ', scalar localtime, "\n";
$etime = time;
%re = do gather_stat();
do analyse();
}
If indeed you're getting these results:
"Bert Tijhuis" <B.Tijhuis@inter.NL.net> writes:
>
> Sleeping...Wed Apr 18 22:51:31 2001slept. Wed Apr 18 22:51:36 2001
5 seconds
> Sleeping...Wed Apr 18 22:51:37 2001slept. Wed Apr 18 22:51:42 2001
5 seconds
> Sleeping...Wed Apr 18 22:51:43 2001slept. Wed Apr 18 22:51:46 2001
3 seconds
> Sleeping...Wed Apr 18 22:51:47 2001slept. Wed Apr 18 22:51:49 2001
2 seconds
> Sleeping...Wed Apr 18 22:51:50 2001slept. Wed Apr 18 22:51:52 2001
2 seconds
> Sleeping...Wed Apr 18 22:51:53 2001slept. Wed Apr 18 22:51:53 2001
0 seconds
> Sleeping...Wed Apr 18 22:51:54 2001slept. Wed Apr 18 22:51:55 2001
1 second
> Sleeping...Wed Apr 18 22:51:56 2001slept. Wed Apr 18 22:51:57 2001
1 second
> Sleeping...Wed Apr 18 22:51:58 2001slept. Wed Apr 18 22:52:00 2001
2 seconds
> Sleeping...Wed Apr 18 22:52:01 2001slept. Wed Apr 18 22:52:02 2001
1 seconds
> Sleeping...Wed Apr 18 22:52:03 2001slept. Wed Apr 18 22:52:03 2001
0 seconds
with the snippet posted above, that's clearly a bug. If the code
you're actually using uses a variable instead of the 5, your variable
is clearly being changed. Try running the simplified code I posted
and see if that gives you consistent results. If not, upgrade your perl.
--
----------------------------------------------------------------------
Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology
(Soon: Asst Professor of Sociology, U of North Carolina, Chapel Hill)
andrew_perrin@unc.edu - http://www.unc.edu/~aperrin
------------------------------
Date: Wed, 18 Apr 2001 04:46:41 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Porblems with the Perl Sleep
Message-Id: <slrn9dq71h.jc6.see-sig@typhoon.xnet.com>
On Tue, 17 Apr 2001, Bert Tijhuis <B.Tijhuis@inter.NL.net> wrote:
> I've written a script that reads out the Database I/O of an ORACLE database.
> Within that script I want to wait a specified
> number of seconds. Normally you should use the sleep function from perl
> itself.
>
> within a while loop the sleep command is repeately called. The first time
> the sleep command waits the specified number of seconds but the second time
> not.
>
> How come? and how to solve this
>
> To solve this problem I've program now in my program
> the next line of code (that is working)
> qx( sleep $NUMBER );
Apparently your $NUMBER is either being changed or going out of scope.
Is it set before you enter the loop or within the loop? And why are you
using qx? Perhaps you did not know that sleep is also a Perl function.
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Wed, 18 Apr 2001 23:16:33 +0100
From: dave@mo-seph.com (Dave Murray-Rust)
Subject: Re: Problems trying to process multiple items on a single line
Message-Id: <slrn9ds4i1.1oa.dave@flop.localnet>
On Wed, 18 Apr 2001 17:12:01 -0400, George Adams
<g_adams27@hotSPAMISBADmail.com> wrote:
> $foo =~ s/(\d+) months/push(@months,$1)/eig;
>I start working with $foo? Or is there a more "elegant"
>way to achieve what
>I'm doing above that leaves $foo untouched?
Try:
@months = $foo =~ m/(\d+) month/g;
perldoc perlop
will explain the behaviour of m//g in scalar and list context
HTH
Dave Murray-Rust
--
------------------------------
Date: Wed, 18 Apr 2001 23:50:10 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Problems trying to process multiple items on a single line
Message-Id: <tdsa1ib6jrgj29@corp.supernews.com>
George Adams (g_adams27@hotSPAMISBADmail.com) wrote:
: Here's a simplified example that demonstrates a problem I'm trying to solve.
:
: $foo = "We can store your files for 5 months, 10 months, or 12 months.";
:
: I know that $foo contains a certain number of phrases that have the syntax
: of "NNN months", though I'm not sure how many occurences there are.
: Furthermore, I need to capture what all the NNN amounts are (in this
: example, 5, 10, and 12).
my @months = $foo =~ m/(\d+) months/g;
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: 18 Apr 2001 08:44:40 +0100
From: Paul the Nomad <taka@yarn.demon.co.uk>
Subject: Re: Processing all files in directory
Message-Id: <87snj6d53r.fsf@euterpe.yarn.demon.co.uk>
nobull@mail.com writes:
> Bart Lateur <bart.lateur@skynet.be> writes:
>
> > nobull@mail.com wrote:
>
> > >I'd probably do a Swartzian transform to avoid calling stat() so often
> > >(see FAQ for details).
> >
> > Or the orcish manouvre: cache the file dates in a hash.
>
> Not much in it really:
>
> print "Directory has ",scalar(@articles)," entries\n";
>
> timethese(1000, {
> simple => sub {
> @sorted = sort { (stat($b))[10] <=> (stat($a))[10] }
> map { "$article_dir$_" }
> grep {!/^\./ && !/~$/ && !/^\#/} @articles;
>
> },
> Swartz => sub {
> @sorted = map { $_->[0] }
> sort { $b->[1] <=> $a->[1] }
> map { [ "$article_dir$_" , (stat "$article_dir$_")[10] ] }
> grep {!/^\./ && !/~$/ && !/^\#/} @articles;
> },
> orcish => sub {
> my %date;
> @sorted = sort { ($date{$b} ||= (stat($b))[10]) <=>
> ($date{$a} ||= (stat($a))[10]) }
> map { "$article_dir$_" }
> grep {!/^\./ && !/~$/ && !/^\#/} @articles;
> }
> });
>
>
> Directory has 213 entries
> Benchmark: timing 1000 iterations of Swartz, orcish, simple...
> Swartz: 23 wallclock secs (18.50 usr + 3.52 sys = 22.02 CPU) @ 45.41/s (n=1000)
> orcish: 22 wallclock secs (19.02 usr + 2.20 sys = 21.22 CPU) @ 47.13/s (n=1000)
> simple: 87 wallclock secs (60.24 usr + 20.64 sys = 80.88 CPU) @ 12.36/s (n=1000)
Great discussion. Thanks.
Perl Cookbook has a discussion on Schwartzian, but is there any good
info on Orcish transformations?
Paul
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
--
-----------
Paul
http://www.seditiousdiaries.com/Donald10.html
------------------------------
Date: Wed, 18 Apr 2001 18:12:01 -0500
From: "R. Utterback" <rutterba@cisco.com>
Subject: reading a specific paragraph
Message-Id: <987635656.128256@sj-nntpcache-3>
All,
Reading a file, I have a string I want to extract. The string is within
parens, and the line starts with 'Comp:'. It can look like any of the
following, followed by at least one blank line:
1) Comp: some_string (the_string_I_want)
2) Comp: some_string (the_string
_I_want)
3) Comp: some_string
(the_string
_I
_want)
(etc.)
I have tried using $/ to set the input record separator and do this:
$/ = "";
while (<INFILE>) {
if (/Comp:/) {
$_ =~ s/\n//g; #remove any newlines
$string = ($_ =~ /\((.*)\)/);
}
}
The problem is, some of the files I am working with have the stinkin ^M at
the end of each line, which throws off the whole "read in by paragraph"
thing.
Is there an easy way to get the string I want?
Thnx
Robert
------------------------------
Date: Wed, 18 Apr 2001 03:26:25 +0100
From: "Simon Flack" <news@simonflack.com>
Subject: Re: Slighty OT: Perl Books...
Message-Id: <9biu3m$9armd$1@ID-83895.news.dfncis.de>
Hi Robbie.
IIRC, the Perl CD Bookshelf comes with a hardcopy "Perl in a Nutshell". If
you want a hardcopy book, I'd suggest the Camel, but since you already get
an online version of that with the Perl Bookshelf, it wouldn't necessarily
be worth it.
I'd save the $50 and maybe get a more advanced book such as "Mastering
Regular Expressions" or "Code Complete" once you finish the Bookshelf. That
way, you can think about which area you want to learn more about.
Simon
"RobbieB" <robbie@totaln.com> wrote in message
news:306D6.27021$PF4.45185@news.iol.ie...
> Thanks for the quick reply man, I might look into that, and, with $50 or
so
> to spare, can anyone recommend a har copy book that would fulfil my needs
as
> posted in the first message of this thread?
>
> --Robbie Burke
>
>
------------------------------
Date: Wed, 18 Apr 2001 23:04:44 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: So what do YOU use Perl for?
Message-Id: <tds7ccn0vdtoa6@corp.supernews.com>
Ilmari Karonen <iltzu@sci.invalid> wrote:
> In article <3ACFB415.63D2CA91@gmu.edu>, Szilvia Oszko wrote:
>>One recurring theme in this newsgroup seems to be that Perl!=CGI and
>>that while Perl is often used to write CGI scripts, it can also be used
>>to do a lot of other things. I'd be curious to see what non-CGI stuff
>>you do with Perl.
> * Posting this message.
I haven't reinvented the newsreader yet, but i have a Perl script
that configures and launches my newsreader for me.
> * If I type "google some phrase" in a shell window, a small Perl script
> I wrote starts up lynx and feeds it the appropriate query. Another
> such script gets dictionary and thesaurus results from www.m-w.com.
> The feeling of having the world at my fingertips is simply amazing.
I need to do at least the second one, although the first would be
handy too. I have a one-line Perl script that calls ispell with
with default system dictionary and checks the command line arguments.
> * Whenever I add or delete pages to a website I maintain, I run a Perl
> script that autogenerates the appropriate "previous" / "next" links
> on each page. Doing it any other way would be a pain.
At my last development job, my web sites were mostly done from
templates, and updated every half hour. The previous/next links
were generated on along with the variable parts of the content.
> * "rename 's/htm$/html/' *.htm"
I like that a lot.
> * I use procmail and Perl to provide automatic responses to e-mails
> sent to certain addresses. Try ada@itz.pp.sci.fi for example. I
> also use them to make my usenet addresses expire after a fortnight.
I have a mailing list system I'm writing in Perl, a mail-based
document server I've coded once and am about to recode, and several
other mail-related things. Once that comes in very handy at an ISP
is the ability to pop a user's mailbox, deleting only the files which
their crappy MUA times out trying to read from the server over their
ancient 14.4kbit/second modem.
> * A more versatile substitute for grep and sed.
Is there an award for udnerstatement?
> * A project I used to work on had some immense function libraries that
> followed a rather pointless scheme. I used some really scary Perl
> one-liners to split the files into functions (+associated comments),
> figure out what part of the project each function belonged to, and
> write a new set of smaller, more sensibly organized library files.
I've never tackled this particular problem using Perl, but I have
used Perl to eliminate dead code from C and Perl programs at the
source level.
> * Silly word list tricks, like finding pairs of words that rot13 into
> each other such as "or" / "be" and "nowhere" / "abjurer".
Remember, rot13("Iraq") and rot13("Abba") are words, too.
Interestingly enough, rot13("terra") is "green".
> * JAPHs.
These are cool, and don't forget obfuscated Perl contests, the Perl
camel from Perl code, and the three-line RSA implementation in Perl.
> Of course, I also use it for CGI quite extensively. Most of the scripts
> I've written are not CGI, but if one discounts throwaways and one-liners
> the ratio gets closer to even. Though I do occasionally whip up a small
> throwaway CGI script just to test something.
I write a lot of systems which are part CGI and part not. Specifically,
I have one system right now that has two command-line programs, a dozen
or so CGIs, and two daemons, all written in Perl.
I also use Perl to amaze my friends and to impress women so I can get
dates. ;-) (Hi, Randal!)
I use Perl for many, many log-traversing reporting scripts. One gives
me disk usage for ISP users. One gives me online time usage for them.
One gives me the IP of a certain user at a certain time or the user
who was on a certain IP at a certain time (mainly for complaints
of mail abuse, fruad while online, child porn, or piracy).
Other Perl programs show me any errors with customer websites,
process averages on servers so we can more easily plan upgrades,
and how many email messages I have waiting on which of my multiple
email spools.
> "Swiss Army Chainsaw" pretty much sums it up.
Yep.
Chris
--
Christopher E. Stith
Disclaimer: Actual product may not resemble picture in ad in any way.
------------------------------
Date: Wed, 18 Apr 2001 17:05:31 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: unicode, perl and webbrowsers
Message-Id: <Pine.LNX.4.30.0104181651530.16255-100000@lxplus003.cern.ch>
On Wed, 18 Apr 2001, Bart Lateur wrote:
> >There is a relevant Netscape 4 bug, agreed. But it _can_ still cope
> >with either utf-8 coded characters _or_ &#bignumber; representations
> >as long as you tell it the charset is utf-8. My checklist should
> >help: http://ppewww.ph.gla.ac.uk/~flavell/charset/checklist
Please see also my posting
<Pine.LNX.4.30.0104102143580.32121-100000@lxplus003.cern.ch>
> I slightly misremembered. But your "checklist" is wrong, too. The truth
> is inbetween these two extremes.
>
> On Netscape 4.x, you CAN display any kind of character if you say that
> the charset is UTF-8. But it DOES NOT WORK in forms.
I can only agree with what you say.
The checklist was designed to help people choose an appropriate
character coding for their HTML authoring requirements. I have to
admit that problems with forms weren't specifically addressed there.
I do have a separate draft about forms, which now covers some of these
issues to the best of my current knowledge.
http://ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html
What's missing seems to be a cross-reference from the checklist page
and I'll do something about that shortly.
> So: there's no way, in Netscape 4.x, to *edit* both French and Polish in
> the same HTML form. UTF-8 just doesn't work there.
Unfortunately, I can only confirm that you're right about that.
How glad we'll all be when the use of that derelict hulk finally
dies out.
--
Follow-ups devoid of meaningful content are the life-blood of this group.
Most are a little more subtle about it though. -- Graybags on apihna
------------------------------
Date: Wed, 18 Apr 2001 19:21:04 -0400
From: "George Adams" <g_adams27@hotSPAMISBADmail.com>
Subject: Using boundaries within regexps
Message-Id: <9bl7h1$oup$1@taliesin.netcom.net.uk>
Thanks to those who replied to my earlier question - using m/// in a list
context works well.
One followup question - here's another simplified example:
$data = "<select><option>foo<option>bar<option>baz</select>";
Here I want to extract all the HTML options. I can be sure that, whatever
$data contains, each option will start with <option> and end either with
another <option> or </select> .
This partially works:
push(@results,$1) while ($data =~
m#<option>(.*?)(<option>|</select>)#ig);
except that it only extracts "foo" and "baz" from $data. I'm guessing that
by using <option> as both the starting and ending boundary, I end up slicing
$data like this:
<select> (= no match)
<option>foo<option> (= match!)
bar (= no match)
<option>baz</select> (= match!)
So the question is, how can I use the second occurrence of <option> as BOTH
the ending boundary of the first match (foo) AND the beginning boundary for
the next match (bar) ?
Thanks again.
------------------------------
Date: Wed, 18 Apr 2001 18:29:34 -0500
From: xris <xris@dont.send.spam>
Subject: Re: Using boundaries within regexps
Message-Id: <xris-4797EE.18293418042001@news.evergo.net>
In article <9bl7h1$oup$1@taliesin.netcom.net.uk>,
"George Adams" <g_adams27@hotSPAMISBADmail.com> wrote:
> This partially works:
> push(@results,$1) while ($data =~
> m#<option>(.*?)(<option>|</select>)#ig);
try a zero-width lookahead:
m#<option>(.*?)(?=<option>|</select>)#igo
heck, you could even do somthing like:
@words = split(/(?:</?option>|</?select>)+/);
at least, I think that would work properly...
and if you're into a tiny speedup, use the "o" option like I did, which
doesn't recompile the pattern every time it's executed.
And not to criticize your html, but you really should close those
<option> tags with </option>, just to make sure that all browsers handle
them properly (I know it's not required, but it's a good idea).
------------------------------
Date: Thu, 19 Apr 2001 00:08:28 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Using boundaries within regexps
Message-Id: <tdsb3shfvdij66@corp.supernews.com>
George Adams (g_adams27@hotSPAMISBADmail.com) wrote:
: Thanks to those who replied to my earlier question - using m/// in a list
: context works well.
s/\/\/\//\/\/
Sorry, I couldn't resist. :)
: One followup question - here's another simplified example:
:
: $data = "<select><option>foo<option>bar<option>baz</select>";
:
: Here I want to extract all the HTML options. I can be sure that, whatever
: $data contains, each option will start with <option> and end either with
: another <option> or </select> .
my @options = $data =~ m!<option>(.*?)(?=<option>|</select>)!g;
: This partially works:
: push(@results,$1) while ($data =~
: m#<option>(.*?)(<option>|</select>)#ig);
:
: except that it only extracts "foo" and "baz" from $data. I'm guessing that
: by using <option> as both the starting and ending boundary, I end up slicing
: $data like this:
: <select> (= no match)
: <option>foo<option> (= match!)
: bar (= no match)
: <option>baz</select> (= match!)
You guess correctly.
: So the question is, how can I use the second occurrence of <option> as BOTH
: the ending boundary of the first match (foo) AND the beginning boundary for
: the next match (bar) ?
Using posititive lookahead, per my example.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: Wed, 18 Apr 2001 23:48:00 GMT
From: Kim C <kimmfc@mydeja.com>
Subject: verifying write to file using "tie"
Message-Id: <t39sdt06sv0k8054fld8si5hirmsqqs5ue@4ax.com>
Hello,
Is there a way to verify whether or not a tied hash has successfully
been able to write to a file? I've noticed that if a hash is tied to
a file located over a network connection, the untie function will
still return true if the connection is lost and the file cannot be
updated. Thus, something like ...
unless (untie (%hash)){
##dump somewhere else
}
...won't work. In addition, the contents of %hash are emptied on
"untie" regardless of whether or not the DB file was updated, so
checking for its contents isn't of use either.
So, other than verifying file access immediately before untieing, is
there any way of determining a successful write?
Thanks,
Kim.
------------------------------
Date: 18 Apr 2001 15:51:00 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: workaround for sourcing file from perlscript
Message-Id: <9bkd54$i6q$1@bcarh8ab.ca.nortel.com>
r.diwan@india.ti.com writes:
> I want to use put this command in perl script
> source abc
> executable argument
>
> where abc is file which when sourced sets some variable
> and allow to use some executables
> but if i put this in perl script and runs it. it source the file in new
> shell and hence all those executables can't be run as they are run in
> different shell .
>
> Can any body tell the workaround
perldoc -q environment
Brandon
------------------------------
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 709
**************************************