[8298] in Perl-Users-Digest
Perl-Users Digest, Issue: 1915 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 17 02:07:27 1998
Date: Mon, 16 Feb 98 23:00:37 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 16 Feb 1998 Volume: 8 Number: 1915
Today's topics:
"Can't locate Config.pm in @INC" - how to cure it? <arkady@nsi.co.il>
Re: "undef" and Inititializing .. (Greg Bacon)
<$x> OK but <$_[0]> NOT?!! (Keith Kong)
Re: ? Regular Expressions ? <tchrist@mox.perl.com>
Re: Being Nice 2 Nice Beings [Was: Reading The FAQ's et (Gabor)
Re: Can't use string ("") as a subroutine ref while "st <webmaster@fccj.cc.fl.us>
Re: Can't use string ("") as a subroutine ref while "st <webmaster@fccj.cc.fl.us>
Re: Courtesy Emails (was Re: A Pubilc Apology.) (Jonathan Feinberg)
Re: Date validation <rjk@coos.dartmouth.edu>
Re: File Permission/Ownership <tchrist@mox.perl.com>
Re: File Permission/Ownership <xxTony.Curtis@vcpc.univie.ac.at>
File question <orange19@rocketmail.com>
Re: formating a text file (hard returns)? <palincss@nicom.com>
Help: Why does sysread give false end of file? (Stan Majka)
HTTP::Daemon _with_ Authentication <palm@gfz-potsdam.de>
Re: Location: returns empty document? <c2@3-g.com>
Re: New perl programmer requesting comments <rjk@coos.dartmouth.edu>
non-polling way to detect new files? <glipper1@san.rr.com>
Re: on reading FAQs and gurus answering questions <joseph@5sigma.com>
Re: on reading FAQs and gurus answering questions (Jonathan Feinberg)
Re: pattern Search problem (Craig Berry)
Re: pattern Search problem <rjk@coos.dartmouth.edu>
Re: PC vs PC vs PC (was: Multithreaded servers and comm (Jonathan Stowe)
Re: PGP - Perl puzzle <iggiebee@rhpworld.org>
Q: Storing complex records in DBM files <boris@i3.informatik.rwth-aachen.de>
Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/ <rjk@coos.dartmouth.edu>
Re: Remove files in a PERL sript <tchrist@mox.perl.com>
Re: Remove files in a PERL sript <xxTony.Curtis@vcpc.univie.ac.at>
Re: Search string in log files advice <rjk@coos.dartmouth.edu>
Re: sockets to webservers (Jonathan Feinberg)
Strange predefined variables <a@b.c.d>
Stripping HTML tags in 5.004 (Andrew Haylett)
Re: The Young Man and the Beach (Mark Kramer)
Re: The Young Man and the Beach <bf8$s03c92f97$a93d2@kf8nh.apk.net>
Re: The Young Man and the Beach (Richard Bellavance)
Re: Tom wins flamer of the year award! (Joel Coltoff)
Re: VB5: Win95 sound volume control <camerond@mail.uca.edu>
Re: what is exaclty the "_" Variable ?!?! (Gabor)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 16 Feb 1998 13:27:50 +0200
From: Arkady Zilberberg <arkady@nsi.co.il>
Subject: "Can't locate Config.pm in @INC" - how to cure it?
Message-Id: <34E822B6.41C6@nsi.co.il>
Hello, all!
I'm not a perl programmer so excuse me if the question is trivial.
Recently I installed a product which uses perl5 in its scripts so I
also installed perl5 (I took file perl5.001.tar.gz from ftp.cdrom.com).
First, perl scripts couldn't locate their modules - this I fixed by
defining PERL5LIB as /usr/local/lib/perl5 (I had installed perl under
/usr/local). Now, I have more peculiar problem: in File::Basename there
is an operator 'use Config;' which can't locate Config.pm. I found this
file (Config.pm) in /usr/local/lib/perl5/alpha-dec_osf (guess what
system I'm using :-). Should I:
1) create a symbolic link
cd /usr/local/lib/perl5
ln -s alpha-dec_osf/Config.pm Config.pm
2) define another environment variable
3) redefine PERL5LIB (how?)
Thanks in advance,
Arkady.
------------------------------
Date: 16 Feb 1998 16:45:39 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: "undef" and Inititializing ..
Message-Id: <6c9qfj$ods$2@info.uah.edu>
[Posted and mailed]
In article <34E85BDA.861EDDEC@uni-oldenburg.de>,
Claus van de Vlierd <vlierd@uni-oldenburg.de> writes:
: is a Variable always initialized
: with Zero (as a number) and with "" as a string ?!?
Almost: scalars begin life with an undefined value which can look like
the numeral 0 and the empty string, depending on the context.
I was surprised to find that
#! /usr/bin/perl -w
$foo += 42;
print "$foo\n";
$bar .= "yo mama so fat";
print "$bar\n";
doesn't emit any warnings. Nonetheless, you still see the behavior.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 17 Feb 1998 01:51:16 GMT
From: kkong@ece.ucdavis.edu (Keith Kong)
Subject: <$x> OK but <$_[0]> NOT?!!
Message-Id: <6caqek$uf$1@mark.ucdavis.edu>
I've got a file handle created some place that I want to pass to a
subroutine. Something like the following:
sub foo {
$line = <$_[0]>;
return $line;
}
open( FILE , "< stuff" );
$x = foo( \*FILE );
Things don't seem to work so I tried to simplify:
$_[0] = \*FILE;
$line = <$_[0]>;
print $line;
Things still don't work so I tried another simplification:
$_[0] = \*FILE;
$x = $_[0];
$line = <$x>;
print $line;
This works. So what's the deal? I'm using perl 5.003 (is that the
reason?)
Thanks!!
Keith
------------------------------
Date: 16 Feb 1998 23:48:56 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: ? Regular Expressions ?
Message-Id: <6caj98$bh3$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, mgjv@comdyn.com.au (Martien Verbruggen) writes:
:I would use man if Solaris didn't have such a
:broken version of makewhatis installed.
Get the linux or perl versions.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
If I don't document something, it's usually either for a good reason,
or a bad reason. In this case it's a good reason. :-)
--Larry Wall in <1992Jan17.005405.16806@netlabs.com>
------------------------------
Date: 16 Feb 1998 16:09:01 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Being Nice 2 Nice Beings [Was: Reading The FAQ's etc.: a teacher's perspective...]
Message-Id: <slrn6egp12.59j.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, Nathan V. Patwardhan <nvp@shore.net> wrote :
# Jaime Metcher (metcher@spider.herston.uq.edu.au) wrote:
# : Secondly, as it was explained to me, the "F" stands for a particularly
# : aggressive word and carries an implied "you moron" or worse - although,
# : as with most acronyms, there is more than one expansion.
#
# The 'F', as it were, can mean just about anything that you want it to:
# - freakin'
# - freaking
# - fargin'
# - the offensive word
# - flippin
# - etc etc etc
I think it reads as 'Read The Friendly Manual'. ;-)
A very good advice to anyone who wants to get past the level of
'newbie'. In fact, I would argue that it's what differentiates the
expert from the bumbling start-up.
# But RTFM has been around much longer than you (and probably me), and
# it's there for good reason, so I wouldn't assume that it's going to
# disappear anytime soon.
gabor.
--
Let's say the docs present a simplified view of reality... :-)
-- Larry Wall in <6940@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Mon, 16 Feb 1998 14:31:35 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Can't use string ("") as a subroutine ref while "strict refs" in use
Message-Id: <34E84CB7.7D75AFA4@fccj.cc.fl.us>
I looked back thru my code and found that Tom
Christiansen was right :-)
I actually had two logic errors working against me!
One error was I did not take into account that the data file
started with two lines which I thought I was throwing out
(they were not needed, but in the data anyways...)
I wasn't throwing them far enough!
The other issue was - somehow during debugging my
original variable &$vSub() had become &{"$vSub"}()
Oops :-) Sorry about that, was trying to force things that
didn't want to be.
Tom, thank you for your input :-)
Bill
Tom Christiansen wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, bill@astro.fccj.cc.fl.us writes:
> :Can't use string ("CODE(0x257d28)") as a subroutine ref while "strict refs"
> :in
> : use at Filebase_Tabs.pl line 207, <prjCF> chunk 1 (#1)
>
> At some point, you did this:
>
> $r = \&func;
> $s = "$r";
> &$s();
>
> Don't quote variables you shouldn't -- it can destroy them.
>
> --tom
> --
> Tom Christiansen tchrist@jhereg.perl.com
>
> #define SIGILL 6 /* blech */
> --Larry Wall in perl.c from the 4.0 perl source code
------------------------------
Date: Mon, 16 Feb 1998 14:49:44 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: Can't use string ("") as a subroutine ref while "strict refs" in use
Message-Id: <34E850FA.6B4DE23E@fccj.cc.fl.us>
Found answer for Case-Switching -
How do I create a switch or case statement?
This is explained in more depth in the the perlsyn manpage. Briefly, there's no
official case statement, because of the variety of
tests possible in Perl (numeric comparison, string comparison, glob comparison,
regexp matching, overloaded comparisons, ...).
Larry couldn't decide how best to do this, so he left it out, even though it's
been on the wish list since perl1.
Here's a simple example of a switch based on pattern matching. We'll do a
multi-way conditional based on the type of reference
stored in $whatchamacallit:
SWITCH:
for (ref $whatchamacallit) {
/^$/ && die "not a reference";
/SCALAR/ && do {
print_scalar($$ref);
last SWITCH;
};
/ARRAY/ && do {
print_array(@$ref);
last SWITCH;
};
/HASH/ && do {
print_hash(%$ref);
last SWITCH;
};
/CODE/ && do {
warn "can't print function ref";
last SWITCH;
};
# DEFAULT
warn "User defined type skipped";
}
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_create_a_switch_or_case
Thx,
Me :-)
Bill Jones wrote:
> I looked back thru my code and found that Tom
> Christiansen was right :-)
>
> I actually had two logic errors working against me!
>
> One error was I did not take into account that the data file
> started with two lines which I thought I was throwing out
> (they were not needed, but in the data anyways...)
>
> I wasn't throwing them far enough!
>
> The other issue was - somehow during debugging my
> original variable &$vSub() had become &{"$vSub"}()
>
> Oops :-) Sorry about that, was trying to force things that
> didn't want to be.
>
> Tom, thank you for your input :-)
>
> Bill
>
> Tom Christiansen wrote:
>
> > [courtesy cc of this posting sent to cited author via email]
> >
> > In comp.lang.perl.misc, bill@astro.fccj.cc.fl.us writes:
> > :Can't use string ("CODE(0x257d28)") as a subroutine ref while "strict refs"
> > :in
> > : use at Filebase_Tabs.pl line 207, <prjCF> chunk 1 (#1)
> >
> > At some point, you did this:
> >
> > $r = \&func;
> > $s = "$r";
> > &$s();
> >
> > Don't quote variables you shouldn't -- it can destroy them.
> >
> > --tom
> > --
> > Tom Christiansen tchrist@jhereg.perl.com
> >
> > #define SIGILL 6 /* blech */
> > --Larry Wall in perl.c from the 4.0 perl source code
------------------------------
Date: Mon, 16 Feb 1998 09:24:05 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Courtesy Emails (was Re: A Pubilc Apology.)
Message-Id: <MPG.f52160c28b843d99896dc@news.concentric.net>
schuerig@acm.org said...
: Jonathan Feinberg <jdf@pobox.com> wrote:
:
: > schuerig@acm.org said...
: > : 3) The sender isn't being curteous at all. Rather he or she is trying to
: > : tell me what an idiot I am -- and want's to stick their opinion right
: > : into my face. There's no arguing with this kind of people.
: >
: > Do you mean to say that every piece of email you receive in response to a
: > newsgroup question contains a personal insult?
:
: No, I didn't mean to say that and I did not say that. What you're
: quoting is only one of the three very common cases of courtesy mail I've
: received in the past.
You're quite right; I apologize. I may have been quoting a followup, and not
your original post. My bad.
: > [This message was posted to c.s.p.m, and a copy was NOT sent to the cited
: > author.]
:
: And there was no need for it. I've found it here in the group without
: any problem whatsoever. BTW, if I had sent you a copy of this reply how
: would have felt?
Oh, probably happy to hear "You've got mail!" Honestly, I appreciate getting
emailed on replies. I dunno, it's a personality thing, I guess. Genetic.
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,^.*-+ ,,,,chop;for(split?/*?){($$_++or$y=$_,y,
y \,y,<STDIN>,,eval"sub $_ {print '$y'}"),y,0 \,},>STDOUT,,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Mon, 16 Feb 1998 12:33:16 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: I R A Aggie <fl_aggie@thepentagon.com>
Subject: Re: Date validation
Message-Id: <34E8785E.8A3659A4@coos.dartmouth.edu>
[posted and mailed]
I R A Aggie wrote:
>
> $input=<STDIN>; # reads mm/dd/yyyy from STDIN
> ($mon,$day,$year)=split #/#, $input; # split apart the input string
I think you're trying to be a little too clever there:
DB<1> $input = "1/2/34"
DB<2> $_ = "foo bar"
DB<3> @date = split #/#, $input; # split apart the input string
DB<4> x @date
0 'foo'
1 'bar'
If you want to use a character other than / as the regex delimiter, you need
to use the operator explicitly: m#/#
Of course, in your original code, you would have gotten a compilation error,
because the semicolon has been commented out.
> [...]
> if ($mon=~/\d*/) { #contains numbers only...presuming I got the regex right
I'm afraid you didn't. That regex will match *any* string. It will even match
an undefined value. Why? Because there will always be at least zero digits in
any string. (And it will always match at the beginning of the string, for the
same reason.)
Either of these would do what you intended:
if ($mon =~ /^\d+$/) {
if ($mon !~ /\D/) {
Note that they're not equivalent: the first allows a trailing newline, and the
second one doesn't. But you've probably already used chomp().
Chipmunk
------------------------------
Date: 16 Feb 1998 17:06:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: File Permission/Ownership
Message-Id: <6c9rn7$dm1$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Matt Somers <msomers@hendco.com> writes:
:Whenever I try to create a file on the fly, it has an owner of
:nobody.
Funny, when *I* make a file, *I* owned the file. Are you sure
you aren't having some web-related issue?
:How do I make it so that this file belongs to users
:and can be accessed and altered later in the program?
Personally, I'd look into the Apache suexec mechanism.
And a newsgroup whose charter has something to do with
the web. This one does not.
--tom
CPAN's Web-related modules in Perl:
http://www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/
The Idiot's Guide to solving Perl/CGI problems
http://www.perl.com/perl/faq/idiots-guide.html
Perl FAQs
http://www.perl.com/CPAN/doc/FAQs/
Perl Manpages (old)
http://www.perl.com/CPAN/doc/manual/html/
CGI FAQ
http://www.webthing.com/page.cgi/cgifaq
WWW Security FAQ
www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html
Web FAQ
http://www.boutell.com/faq/
HTTP Spec
http://www.w3.org/pub/WWW/Protocols/HTTP/
HTML Spec
http://www.w3.org/pub/WWW/MarkUp/
CGI Spec
http://hoohoo.ncsa.uiuc.edu/cgi/interface.html
--
Tom Christiansen tchrist@jhereg.perl.com
"Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in."
--Larry Wall
------------------------------
Date: 16 Feb 1998 17:32:55 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
Subject: Re: File Permission/Ownership
Message-Id: <7xhg5zse6g.fsf@beavis.vcpc.univie.ac.at>
Re: File Permission/Ownership, Matt <msomers@hendco.com>
said:
Matt> Whenever I try to create a file on the fly, it has an
Matt> owner of nobody. How do I make it so that this file
Matt> belongs to users and can be accessed and altered later
Matt> in the program?
Oh dear, this is really a CGI/WWW question isn't it?
http://www.boutell.com/
hth
tony
------------------------------
Date: Mon, 16 Feb 1998 15:46:27 +0200
From: "Gil Steiner" <orange19@rocketmail.com>
Subject: File question
Message-Id: <6c9foq$pfe$1@news.ibm.net.il>
Hi
I must have quite a big missunderstanding here, but I am new, so forgive
me...
How do I open a file, read each line, process it, and return it to the same
file ?
what I do now is open the file, read the lines and write them to a different
file.
Please POST the reply here.
Thanks,
+Gil
------------------------------
Date: Mon, 16 Feb 1998 17:43:48 -0800
From: Steve Palincsar <palincss@nicom.com>
To: nNature_Boy@earthling.net
Subject: Re: formating a text file (hard returns)?
Message-Id: <34E8EB54.58E2@nicom.com>
Since Perl's motto is "There's More Than One Way To Do It" and since
everybody's already told you about Text::Wrap, let me introduce Another
Way: the self-wrapping format with tildes that repeats until all
text is gone:
format STDOUT=
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$Your_Text
.
Copy your text into $Your_Text, then issue the following command:
write;
This would be especially dandy for a file you're reading in in paragraph
mode (i.e., $/=''; )
Formats don't appear to get much respect in CLPM, but I find them
endlessly useful.
Steve Palincsar
John Davidson Highfill wrote:
>
> Sorry for the vauge subject but i was wondering about formating text
> files that are too wide. I have been trying to make up a perl script
> (I am VERY new to perl, and programing in general)(If it makes a diff
> i am using linux slackware) that would atuomatically format a text file
> so that is is say 70 char long bout would not cut off words (rather hard
> return and put them on the next line). thank you very much.
>
> -Davidson
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> NAME: Davidson Highfill POSITION: Student Extrodinare
> E-MAIL: davidson@unity.ncsu.edu or nature_boy@earthling.net
> "The last bug isn't fixed until the last user is dead..."
> When mailing me don't forget to take the 1st "n" out of my email address
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
------------------------------
Date: 17 Feb 1998 00:30:34 GMT
From: spamblock_majka@richmond.infi.net (Stan Majka)
Subject: Help: Why does sysread give false end of file?
Message-Id: <6calna$nkb$1@nw003t.infi.net>
Can anyone tell me what's going wrong with sysread?
I'm trying to read a 711 KB file, but a straightforward sysread loop quits
after only about 42 KB.
The file contains variable length records. Each record starts and ends with a
2-byte record length. I read the length of the first record, then loop,
reading each record plus the 2-byte length field for the next record.
I can successfully read 162 records, but on the 163rd, I ask for 280 bytes but
only get 10. If I do another sysread for 270 bytes, I get 0. If I keep doing
sysreads for 999 bytes, I keep getting 0 bytes read.
If I put in an error recovery routine, I can read the entire 711 KB. Whenever
the bytes read is less than the record length, I close the file, re-open it,
seek to where the next record is supposed to be, and continue from there. This
gets me through the file, but it seems kludgy; why isn't sysread seeing a
continuous file as it appears when I open it with a text editor?
Running Perl for Win32 on NT 4.0.
Thanks in advance,
Stan
------------------------------
Date: Mon, 16 Feb 1998 17:08:16 +0100
From: Hartmut Palm <palm@gfz-potsdam.de>
Subject: HTTP::Daemon _with_ Authentication
Message-Id: <34E86470.90A0614C@gfz-potsdam.de>
Is there a PERL-Script, that works like an
HTTP-Server (with fork) and authentication?
or
How to use HTTP::Daemon with authentication?
--
Thanx
------------------------------
Date: Sat, 14 Feb 1998 23:04:00 -0500
From: Chad Casselman <c2@3-g.com>
Subject: Re: Location: returns empty document?
Message-Id: <34E66930.B479774B@3-g.com>
P. Schmitz wrote:
>
> Hi everyone,
>
> Does anyone have any idea why the following perl script:
>
> print "Location: www.yahoo.com\n\n";
>
> doesn't redirect my browser to Yahoo!, but instead gives a 'Document
> contains no data' message? The same thing in a C++ CGI-bin works
> perfectly. Returning HTML works perfectly. But for some reason,
> redirects like the above don't work from perl scripts...
>
> I'm running perl 5 on Windows NT Server 4.0 with MS IIS. I sure hope you
> know what's going on, because this has me baffled...
>
> Pepijn.
>
I am having the same trouble! What is up with NT! I am unix programmer
but this crap don't work on NT! Please reply!
Thanks,
c2
------------------------------
Date: Mon, 16 Feb 1998 20:03:40 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Justin Baugh <baughj@rpi.edu>
Subject: Re: New perl programmer requesting comments
Message-Id: <34E8E1F3.92E9B9B1@coos.dartmouth.edu>
[posted and mailed]
Justin Baugh wrote:
>
> $who = `w -h`;
> [...]
> @who1 = split(/\n/,$who);
If you use backticks in a list context, it will return each line as a separate
element. So, replace the above two lines with:
@who1 = `w -h`;
Of course, you can call it @who and not @who1 if you want to.
> $num_users = length(@who1)+1;
That does not do what you intend. length() returns the number of bytes of the
scalar value of its argument. An array evaluated in scalar context returns
the number of elements in the array. So, if there are 15 users, the above
code would set $num_users to 3.
The documentation for length() specifically says "Do not try to use length to
find the size of an array or hash. Use scalar @array for the size of an array..."
So, replace the above with:
$num_users = @who1;
Note that you never again use $num_users in your code. In fact, you simply
repeated the incorrect code length(@who1)+1. Also note that if you use
foreach, you don't need to know how many elements are in @who1.
> [...]
> # Dump it out to the browser; I used the <<'marker' convention for ease of
> # design and modifications
Excellent decision! It also makes the intended output easier to read.
> [...]
> print <<beforeTable
Put the semicolon here instead of after the here-doc.
print <<beforeTable;
> [...]
> beforeTable
> ;
>
> [...]
> $i=0;
> if (@who1[0]) {
That is a list slice of 1 element. Use $who1[0] instead.
On the other hand, what you really want to know is if there are any elements
in @who1, not whether $who1[0] is "true", so it should be:
if (@who1) {
Because, as I mentioned above, an array in a scalar context gives the number
of elements in the array.
> for ($i; $i<=length(@who)+1; $i++) {
Use foreach instead.
foreach $who (@who) {
> print "<tr>";
> print "<th>";
> print substr(@who1[$i],0,8);
> print "<\th>";
> [...]
(Once again, you have @who1[$i] when you wanted $who1[$i].)
With the foreach, that would now be:
print substr($who, 0, 8);
You could also do this as a here-doc:
print <<Table;
<tr><th>@{[substr($who, 0, 8)]}</th>
...
Table
Chipmunk
------------------------------
Date: Mon, 16 Feb 1998 11:04:06 -0800
From: George Lippert <glipper1@san.rr.com>
Subject: non-polling way to detect new files?
Message-Id: <34E88DA6.DDBC5D59@san.rr.com>
Gentlefolk,
I've tried to do my homework on this question but come up with no
elegant answer.
Is there a way to detect when a new file is placed into a directory,
other than, say, looping on the directory's modification time and then
comparing new vs. old filename lists? I guess I'm hoping there is
something like a directory version of select(). Thanks in advance.
George
------------------------------
Date: Mon, 16 Feb 1998 03:29:10 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: on reading FAQs and gurus answering questions
Message-Id: <34E814CB.32942E70@5sigma.com>
I personally favor the absence of a mainstream unmoderated group.
Let people create alt.perl.blah.blah.blah if they feel the need. The
noise level is extremely high and the postings seem to be by and
large an endlessly repeating cycle. (Another alternative would
be to rmgroup comp.lang.perl.misc in the process of inaugurating
comp.lang.perl.mod.)
I don't know if it would be practical to actually have a human
moderate the group, but it sure would be nice to at least transition
to moderated status so that might one day be an option.
According to some German officer (according to David Hackworth in
About Face) you can classify people as stupid or smart, and lazy or
industrious. Smart, lazy people make good general officers, since they
are always trying to figure out the easy way to do things. Smart,
industrious people are good staff officers, since they get things
done. Stupid, lazy people are just one of those things humanity
presents you with, but they do no harm. It's the stupid, industrious
people you have to watch out for. Every day they show up is
another day you are behind.
The problem is that the endless blather in the group has long
driven off smart, lazy people and is very taxing to the smart,
industrious crowd. The blather, of course, comes from the stupid,
lazy crowd, which can't be blamed for being what it is. However,
when the only remaining "perl gurus" are the stupid, industrious
types, watch out. I think we are headed in that direction, and
some days it looks like we're already there.
-joseph
Russ Allbery wrote:
>
> Chip Salzenberg <chip@mail.atlantic.net> writes:
>
> > The problems aren't related to voting --- at least not the problems that
> > I'm aware of. News systems on autopilot abound, and there's no way to
> > arrange that all those active files will get updated.
>
> rec.arts.comics.creative was converted from unmoderated to moderated.
> Three months later, the problems were almost gone; after a year, there's
> nary a difficulty in sight. It takes a while, but it happens. You just
> have to encourage your users to bug their local ISPs to change the group
> status.
>
> Larger groups, of course, will have more problems.
>
> (This is not to say I favor moderating in place. For this group, I think
> creating a new moderated group would be a better approach.)
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: Mon, 16 Feb 1998 09:50:15 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: on reading FAQs and gurus answering questions
Message-Id: <MPG.f521c31525f67649896dd@news.concentric.net>
joseph@5sigma.com said...
: However,
: when the only remaining "perl gurus" are the stupid, industrious
: types, watch out. I think we are headed in that direction, and
: some days it looks like we're already there.
Because I respect your opinion, I'm hoping you'll elaborate on the hallmarks
of a "stupid, industrious" person. It seems like you're disparaging the
dispensation of advice by well-intentioned but under-informed people. Is that
the idea? The last time I took the Perl purity test, I scored "User," but I
still want to contribute to what's left of this community.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 17 Feb 1998 00:10:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: pattern Search problem
Message-Id: <6cakhe$5sl$4@marina.cinenet.net>
Chipmunk (rjk@coos.dartmouth.edu) wrote:
: Hunter Johnson wrote:
: >
: > $_ =~ s/\. (.)/". \u$1"/eg;
:
: As the right side of a substitution is treated as a double-quotish string,
: you don't need the /e in this case:
:
: $_ =~ s/\. (.)/. \u$1/g;
Or, using defaults and capturing to save error-prone typing:
s/(\. )(.)/$1\u$2/g;
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Mon, 16 Feb 1998 18:39:54 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: pattern Search problem
Message-Id: <34E8CE4C.C2603DC7@coos.dartmouth.edu>
Hunter Johnson wrote:
>
> $_ =~ s/\. (.)/". \u$1"/eg;
As the right side of a substitution is treated as a double-quotish string,
you don't need the /e in this case:
$_ =~ s/\. (.)/. \u$1/g;
Chipmunk
------------------------------
Date: Mon, 16 Feb 1998 16:38:03 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: PC vs PC vs PC (was: Multithreaded servers and communicating object processes (proper))
Message-Id: <34e8687d.5593342@news.btinternet.com>
On 14 Feb 1998 15:44:59 GMT, jcr.remove@this.phrase.idiom.com (John C.
Randolph) wrote:
>
>To me, the abbreviation in question means:
>
><snip>
>
>All other definitions I ignore.
>
>
>--
>John C. Randolph (408) 358-6732 NeXT mail preferred.
>Chief Technology Officer, WARPnet Incorporated.
>"Only in a police state is the job of a policeman easy." - Orson Welles
>
The what about Police Constable ...
/J\
------------------------------
Date: Mon, 16 Feb 1998 03:56:25 -0500
From: Ignacio Bustamante <iggiebee@rhpworld.org>
Subject: Re: PGP - Perl puzzle
Message-Id: <6c8vad$gft@bgtnsc03.worldnet.att.net>
Ooops,
Just in case someone rightfully points out my slopiness on the generic
code posted. The sample code line should read:
$ENV{'PGPPATH'} = "/home/my_home/.pgp";
Please note, that this does not fix the problem of the code not working.
Regards,
Ignacio
------------------------------
Date: Mon, 16 Feb 1998 09:42:57 +0100
From: Boris Boehlen <boris@i3.informatik.rwth-aachen.de>
Subject: Q: Storing complex records in DBM files
Message-Id: <34E7FC11.F466D6E5@i3.informatik.rwth-aachen.de>
Hi,
I'd like to know how I can store a complex record using one of the DBM
modules. Since the records might be very large I want use the GNU or
Berkley DBM.
The records I'd like to store contain some scalar and array fields. All
my attempts to use the GDBM or MLDBM module failed, because I don't
understand how perl the treats the arrays in my record.
Thanx
Boris
--
- Boris Boehlen | Kirchrather Strasse 41
- | 52074 Aachen
- | Phone: +49 241 870034
- | EMail: boris@i3.Informatik.RWTH-Aachen.de
------------------------------
Date: Mon, 16 Feb 1998 18:57:08 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/
Message-Id: <34E8D257.B094676A@coos.dartmouth.edu>
Jack Applin wrote:
>
> Fritz Knack wrote:
>
> > if ($phone =~ /^[800|888]/) {
>
> You know, it wouldn't be so bad if -w were to generate a warning in this case,
> something like:
>
> Duplicate character '8' found in character class at line 1.
> Duplicate character '0' found in character class at line 1.
I think it would be bad, as it is perfectly legit to have duplicate characters
within a character class. I even have code which does so, and I'd be rather
annoyed if it started generating warnings for that with some future version of Perl.
(The code in question takes a sequence of letters, such as a name, and goes
through a word list finding all the words that can be made from the given
letters. One step is to skip the current word if it does not match
/^[\Q$letters\E]+$/ )
Chipmunk
------------------------------
Date: 16 Feb 1998 13:30:15 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Remove files in a PERL sript
Message-Id: <6c9f17$nk5$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, PTBS <ptbs@mail.dma.be> writes:
:Then I want to remove the files from my /temp directory.
:But how can I do that?
You grep for "Delete" in the perlfunc manpage. You want the matches
for the functions that talk about files and directories, not those for
arrays or hashes.
Happy manning!
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I'm not writing any more tapes, ever. --Andrew Hume
------------------------------
Date: 16 Feb 1998 14:31:57 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
Subject: Re: Remove files in a PERL sript
Message-Id: <7xwwev8ylu.fsf@beavis.vcpc.univie.ac.at>
Re: Remove files in a PERL sript, PTBS <ptbs@mail.dma.be>
said:
PTBS> /temp directory. But how can I do that? I'm running
PTBS> the script on a UNIX server. I think I have to use
PTBS> the rm command, but how do I use it in Perl?
perldoc -f unlink
------------------------------
Date: Mon, 16 Feb 1998 19:16:31 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Jsgines <jsgines@aol.com>
Subject: Re: Search string in log files advice
Message-Id: <34E8D6E3.38C60AF1@coos.dartmouth.edu>
[posted and mailed]
Jsgines wrote:
>
> the logic I am following is this:
> >Enter user to search for: jsgines (from keyboard)
> Open $LogFileName || die "Can't open: $LogFileName";
>
> If this user is found in the 5th column of $LogFileName,
> print the DATE, TIME and user (ie., jsgines)
> keep searching the log file for a "Submit Title" string.
> if the "Submit Title" string is found
> print the DATE, TIME, and the value following the "Submit Title" string
> keep reading the log file to find "Submit via local queue '<queuename>'"
> Close $LogFileName
> else
> print some message
>
> Open <queuename>
> start search process all over again but starting at the DATE TIME and looking
> for string user
> print that line
> if search fails,
> search for any error messages, but starting at the DATE TIME
> print that line
> Close <queuename>
Are there specific parts of this program you are having problems coding?
To use user-specified input as part of a regex, you could do this:
chomp($text = <>);
if ($string =~ /\Q$text\E/) { # \Q and \E to escape any metacharacters
# do something
}
(If you want to allow $text to be a full regex and not just literal text,
you'd have to remove the \Q\E and use eval.)
To match something in the fifth column of an input line, you could do this:
while(<>) {
@cols = split; # default split: whitespace and $_
if ($col[4] =~ /re/) {
# do something
}
}
Note that with the data you provided, date and time would be conveniently
stored in $col[0] and $col[1].
If you're getting stuck on other aspects of your program, post more details!
Chipmunk
------------------------------
Date: Mon, 16 Feb 1998 18:46:35 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: sockets to webservers
Message-Id: <MPG.f5299e75e9d67259896e1@news.concentric.net>
[courtesy cc of this posting sent to cited author via email]
dev@sgi.net said...
: What socket options should one use to connect to a webserver?
Nowadays, one uses the LWP modules. If you *really* need to roll your own
networking code, then do yourself a big favor and
use Socket;
because your code will be a lot cleaner and easier to debug. Run, do not
walk, to CPAN.
Sample:
use LWP::Simple;
$doc = get 'http://www.sn.no/libwww-perl/';
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,^.*-+ ,,,,chop;for(split?/*?){($$_++or$y=$_,y,
y \,y,<STDIN>,,eval"sub $_ {print '$y'}"),y,0 \,},>STDOUT},,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 16 Feb 1998 11:24:21 -0500
From: Myles Barrett Williams <a@b.c.d>
Subject: Strange predefined variables
Message-Id: <lcoh07h616.fsf@duncan.cs.utk.edu>
Whenever I run:
perl5 -e '$,="\n"; print keys %::;' |cat -v
I see the usual predefined variables, but there are also strange names
like _<perlmain.c and "\cX" (not "^X"). What kind of variables are
these? Can I use them for anything?
--
mwilliam@ | "Who'll join my tribe?" -- Jack, _Lord of the Flies_
cs.utk.edu | I successfully filter out ALL junk E-mail.
------------------------------
Date: Mon, 16 Feb 1998 16:32:46 GMT
From: ajh@primag.co.uk (Andrew Haylett)
Subject: Stripping HTML tags in 5.004
Message-Id: <EoHCMn.Io3@primag.co.uk>
I know this is an FAQ, but the answer in the FAQ is wrong ;-)
"perldoc perlfaq9" yields the RE s/<(?:[^>'"]*|(['"]).*?\1)*>//gs,
which works fine in 5.001 but bites the dust in 5.004 ("regexp *+
operand could be empty").
The FAQ also points to
http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz,
but that has the same problem.
Yes, I know I could go for HTML::Parse, which I assume works, but that
is somewhat elaborate (and, I suspect, slow) for my quick-and-dirty
requirements of munging a sentence or two, and I can't be sure that my
ISP even has that module installed (this is for a CGI script, I should
say).
Any ideas?
Andrew.
--
Andrew Haylett Senior Software Engineer, Webmaster
Primagraphics, Nr. Cambridge, UK Tel. +44 1763 852222 Fax. +44 1763 853324
email: ajh@primag.co.uk web: http://www.primag.co.uk/
------------------------------
Date: Mon, 16 Feb 1998 16:30:26 GMT
From: c28f62@world.std.com (Mark Kramer)
Subject: Re: The Young Man and the Beach
Message-Id: <EoHCIr.Hu3@world.std.com>
In article <6c73b4$dm@fridge.shore.net>,
Nathan V. Patwardhan <nvp@shore.net> wrote:
>
>*sigh* It's a shame that people don't follow netiquette anymore.
One of those bits of netiquette hapens to involve OS flaming.
------------------------------
Date: Mon, 16 Feb 98 19:27:06 -0500
From: "Brandon S. Allbery KF8NH" <bf8$s03c92f97$a93d2@kf8nh.apk.net>
Subject: Re: The Young Man and the Beach
Message-Id: <34e8dbad$3$ofn$mr2ice@speaker>
In <6ca7qn$19h@fridge.shore.net>, on 02/16/98 at 08:33 PM,
nvp@shore.net (Nathan V. Patwardhan) said:
+-----
| Richard Bellavance (charlot@CAM.ORG) wrote:
| : What I meant to say is that if you have an Internet account, you
| : have the right to post a message to Usenet.
| No, you don't. I've had many accounts over the years, and not one of these
| accounts entitled me to "right to service" on Usenet or
| *anywhere*. Don't forget that even if you have your *own* newsserver, you
| still need to get someone who will feed to you.
+--->8
(tagging onto the above, not responding to it)
Don't forget that in the U.S., it is widely believed that merely existing
automatically entitles you (a) to do anything you want and (b) to be protected
by the government from anything that anyone (including yourself) does that
might hurt you. :-(
Internet and/or Usenet access is merely a minor special case of this,
naturally, including the assumption that you can say any idiotic thing you
want and everyone is required to protect you from being flamed for it.
(Oh, yes, I know, I'm going to be flamed to hell and back for implying that
this is somehow not the natural, correct, God-given state of affairs. Tough.
If you want your mommy to protect you, run back home.)
--
use 5.004;sub AUTOLOAD{print$_{$_.++$x{$_}}}sub new{my%x;%_=map{++$a%2?$_.++$x{
$_}:$_}split(//,pack('N*',unpack('w*',unpack('u*','M@H*HP\'2"@\C`88+SE/!EA(F!'.
"A'6\$LZV0+(3;C9QRA9NAPG2&D\\G(88:KL=A0\n4AN.5W\"\"&\\[W>;H>3S>0\@A\\N\@PB\$`")
)));bless{}}$b=(new main);map{$b->_}split(//,' Brandon S. Allbery KF8NH') # :-)
------------------------------
Date: 16 Feb 1998 10:57:11 -0500
From: charlot@CAM.ORG (Richard Bellavance)
Subject: Re: The Young Man and the Beach
Message-Id: <6c9nkn$o7n@ocean.CAM.ORG>
In article <m3g1lkkw9s.fsf@windlord.Stanford.EDU>,
Russ Allbery <rra@stanford.edu> wrote:
>
>Of course, Usenet wasn't nearly as widespread when I started, and I didn't
>post until I was a junior in college. Perhaps that made a difference.
>But it doesn't have to. There are several posters to a newsgroup I
>moderate who are 14-16 years old, and while they make some dumb mistakes
>from time to time, they've proven more than capable of handling the
>responsibility of posting to a world-wide network.
^^^^^^^^^^^^^^
Here, here ! If only more people could think of posting to Usenet as not
just a right (which it is), but also as an act that carries responsabilities
and that can affect your reputation (which it is very much also). How do you
make people understand that ?
Richard, afraid the answer is "you can't"...
--
Richard Bellavance -- charlot@cam.org -- http://www.cam.org/~charlot/
"All along this path I tread / My heart betrays my weary head
With nothing but my love to save / From the cradle to the grave"
(Eric Clapton, "From the cradle")
------------------------------
Date: Mon, 16 Feb 1998 14:28:37 GMT
From: joel@wmi0.wmi.com (Joel Coltoff)
Subject: Re: Tom wins flamer of the year award!
Message-Id: <6c9ie5$760@netaxs.com>
Congratulations Tom. This is the earliest in the year anyone
has ever done that. Maybe next year we can give the award
by January 10th.
--
Joel Coltoff
I'd explain it, but there's a lot of math. -- Calvin
------------------------------
Date: Mon, 16 Feb 1998 07:46:44 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
To: Thijs Kinkhorst <thijs@kink.xs4all.nl>
Subject: Re: VB5: Win95 sound volume control
Message-Id: <34E84344.1533005D@mail.uca.edu>
Thijs Kinkhorst wrote:
>
> Hello,
>
> I'm having some questions on manipulating the Windows sound output.
Unususal question for a perl newsgroup, but in the interest of being as
helpful as possible, I suggest you try this:
#/usr/bin/perl -w -satire
Stand up;
Walk over to window;
Unlock;
if (window eq "casement"){
turn crank to 'open' to increase volume ||
turn crank to 'close' to decrease volume;
}
elsif (window eq "double-hung"){
lift window to increase volume ||
lower window to decrease volume;
}
else {
hit window sharply with hammer to increase volume ||
purchase new window to decrease volume;
}
Return to chair;
Leave us alone;
Cameron
camerond@mail.uca.edu
------------------------------
Date: 16 Feb 1998 16:02:57 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: what is exaclty the "_" Variable ?!?!
Message-Id: <slrn6egoll.59j.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, Claus van de Vlierd <vlierd@uni-oldenburg.de> wrote :
# I did not find in Larry Wall's "Programming Perl" - book
# (O'Reilly , second edition , September 1996) a precise
# definition of this (at least for me ..) strange Variable "_" .
#
#
# It seems to me , extracting form his examples , that every
# operator which produces a value in the "LIST"-context automatically
# does "$_ = <the list of the items the operator returns>" .
#
# Consequently "for (1 ..10) { print; }"
#
# prints "12345678910" because the "for"-operator (I think "for"
# is an o p e r a t o r ?!) sets $_="12345678910" and"print"
# prints "$_" .
I recommend reading page 131 in the Programming Perl. It tells you
the significance of $_.
In the above for loop it is the default iterator and is set to each
element of list on each iteration. It becomes an alias for each
element and chnging it will change the element.
Try to put this just before your loop.
$\ = "\n";
and then see your output.
also try this
@names = qw(joe john bar foo);
for (@names) {
print;
$_ = 'foobar' if $_ eq 'bar';
}
for (@names) {
print;
}
#
# Is this basically right ?!
# And what am I missing ?!
#
# if I do "@b=@a" : is the "=" - operator (provided it is one -
# I do not know) putting the "_" - Variable to the list of all
# components of the Array @a ?!
One word - no.
gabor.
--
/* now make a new head in the exact same spot */
-- Larry Wall in cons.c from the perl source code
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 1915
**************************************