[17770] in Perl-Users-Digest
Perl-Users Digest, Issue: 5190 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 23 14:10:25 2000
Date: Sat, 23 Dec 2000 11:10:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977598609-v9-i5190@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 23 Dec 2000 Volume: 9 Number: 5190
Today's topics:
Re: REF: Help with Hash in a loop. Desperate! nobull@mail.com
Re: REF: Help with Hash in a loop. Desperate! <abe@ztreet.demon.nl>
Re: Reverse "append to file" <joe+usenet@sunstarsys.com>
Re: Reverse "append to file" <cyner.mail@sweden.com>
Re: Reverse "append to file" <joe+usenet@sunstarsys.com>
Re: Reverse "append to file" <iltzu@sci.invalid>
Re: Site Up Status (David Efflandt)
Re: Substrings <zarathustra@enviroweb.org>
Where to obtain the perlrtfm podpage? <bbollenbach@homenospam.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Dec 2000 15:24:38 +0000
From: nobull@mail.com
Subject: Re: REF: Help with Hash in a loop. Desperate!
Message-Id: <u94rzvupmx.fsf@wcl-l.bham.ac.uk>
"angel" <angel@reflex-point.com> writes:
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0024_01C06C96.F3BF0410
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> Good Samaritan:
Posting Multi-Part/MIME/HTML in this newsgroup is a good way to drive
away good samaritans. Many of the most knowledgible people here
simply won't see your post because their newsreaders will have ignored
your post.
I can't seem to understand why the following statement will only =
> work once in any loop:
>
> my $fext = $mime{$ext};
> Anytime I try to print $fext in a loop it will only print once no
> matter the size of the loop. What am I missing here?
Err... a consistant description of the problem?
You say you think the assignment statement is only executing once and
yet say that the value only prints once. If the assignment statement
was working only once and the print was working on each iteration
you'd expect to see the same value repeated.
So what actually is happening?
What evidence do you have that your loop is actually iterating more
than once?
> #!/usr/bin/perl5.004
I see you have Perl5 but you are still programming as if you are using
Perl4. You may want to get into Perl5 before Perl6 comes out :-)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 23 Dec 2000 17:27:43 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: REF: Help with Hash in a loop. Desperate!
Message-Id: <s6e94tc4h22pnhf8f790d00f4nakhgctgs@4ax.com>
[ Please take some time to adjust the settings of your news reader to
make it wrap at +/- 72 chars and doesn't send:
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0024_01C06C96.F3BF0410"
]
On Sat, 23 Dec 2000 04:15:15 -0600, "angel" <angel@reflex-point.com>
wrote:
> Good Samaritan:
>
> I can't seem to understand why the following statement will only
> work once in any loop:
>
> my $fext = $mime{$ext};
>
> Anytime I try to print $fext in a loop it will only print once no
> matter the size of the loop. What am I missing here?
I guess the first time only.
There are a few things in your program, that could be changed. Style as
well as efficiency.
> #!/usr/bin/perl5.004
You should use the '-w' flag to let perl help you with warnings.
It's also good practice to 'use strict;', the first two lines of your
program should look like:
#!/usr/bin/perl5.004 -w
use strict;
> require "cgi-lib.pl";
That is an old library, which is now turned into the CGI.pm module that
is regularly updated. You can find more information on:
http://search.cpan.org/search?dist=CGI.pm
But your problem doesn't concern CGI.
> #!/usr/bin/perl5.004
>
> require "cgi-lib.pl";
I hope that is your copy/paste that went wrong ...
> open(X2,"<X2.txt") || &ShitBiskits;
>
> @FILELIST = <X2>;
>
> close(X2);
Usually, you don't have to read a whole file at once if you are going to
process it line by line. (Whilst writing that I think I found your
problem :-)
> while (@FILELIST)
This is a 'strange' (and destructive) way to iterate over the elements
of @FILELIST. Normally one would do something like:
foreach my $file ( @filelist ) {
#do 'stuff' with $file
}
>
> {
To make you program readable, you should indent. It will show the
structure of your program.
>
> undef $mime{$ext};
>
> undef $fext;
>
> undef %mime;
No need for those undef's as you my() them later on.
With '-w' only you would have got a "Name "%s" used only once:..."
warning.
With 'strict' you would have seen that you are addressing the package
globals instead of the lexicals (the ones you later declare with my)
> my %mime = (
< snip of massive reversed 'mime.types' like assignment >
This is a waste of cycles. The contents of the hash won't change during
the loop, so you'd better initialize it outside the loop. The data
actually looks like the reverse of 'mime.types' which might be hanging
around on your machine, you could use that.
> my $file = (pop @FILELIST);
>
> print "<br>File = $file";
>
> my ($ext) = $file =~ m,\.([^\.]*)$,;
At this point $ext still has a "\n" (newline) at the end as you never
chomp()ed it off -- that is your bug --. Except for perhaps the last
entry in the file 'X2.txt', which will be processed first because of the
pop().
I personally don't like the comma (',') as a regex-delimiter, as it
doesn't stand out. I usually use a pipe ('|') or a bang ('!') as an
alternative to the slash.
There is no need escape the dot within a char-class.
my ($ext) = $file =~ m|\.([^.]*)$|;
> print "<br>Ext = $ext";
>
> $ext =~ tr,a-z,A-Z,;
$ext =~ tr/a-z/A-Z/;
> print "<br>Again, $ext";
>
> my $fext = $mime{$ext};
>
> print "---$fext\n";
Had you been using '-w' you would have got a warning here.
This is how your code could look (without the html/cgi stuff):
#!/usr/bin/perl -w
use strict;
my %mime;
init_mime_types();
open X2, 'X2.txt' or die "Can't open 'X2.txt': $!";
while ( my $file = <X2> ) {
chomp($file);
print "File = $file";
my ($ext) = $file =~ m|\.([^\.]*)$|;
print "\tExt = $ext";
$ext =~ tr/a-z/A-Z/;
print "\tAgain, $ext;";
my $fext = $mime{$ext} || 'Unknown';
print "--$fext\n";
}
close X2;
sub init_mime_types {
#do the assignment of %mime here
}
__END__
--
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'
------------------------------
Date: 23 Dec 2000 10:09:35 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Reverse "append to file"
Message-Id: <m37l4rfa34.fsf@mumonkan.sunstarsys.com>
chr1st1an <cyner.mail@sweden.com> writes:
> Tad McClellan wrote:
>
> > You *do* have a manual. That is what Joe was pointing out.
>
> Well, I did search a lot of FAQs and "manuals" on the net, including
> perl.com and perldoc.com, but I couldn't find the answer to my question.
> Therefore I thought maybe you could help me here.
Let's try it your way then. After launching AOL, do a keyword search
for "perl" ( omit the quotes and type it into the url thingy- it's
the blank space between the "Find" button and the down arrow centered
near the top of your screen. You may need to click on this area
a few times before the cursor shows up- and don't forget to hit the
return key once you've got all 4 letters in there).
When I tried this, the first link that came up was
Recommended Sites-
* _Perl.com_ - Official site
Next I clicked on that link, and wound up at
http://www.perl.com/pub
In big red letters on the top left, I see the word *FAQs*- and wouldn't
you know it, when I put the mouse over it, it appears to be clickable.
So I did, and would up at
http://www.perl.com/pub/v/faqs
Thinking about your subject for a moment, after an item-by-item process
of elimination on the 10 main FAQ links there, I decided to click
on item 6, "Files and Formats". That took me to
http://www.perl.com/pub/doc/manual/html/pod/perlfaq5.html
Again using an item-by-item process of elimination, I decided
to read each question and compare it with your subject. The
first one doesn't seem relevant, so I decided to move on
to item #2:
"How do I change one line in a file/delete a line in a file/insert
a line in the middle of a file/append to the beginning of a file ?"
After reading the last part, I clicked on it and up came the
answer. The answer has some code in it, and it sure would be
nice to try and understand how it works. In fact, one of the
local gurus here figured it out for you, and even told you how
to change the code there to make it work for your needs.
And you didn't even bother to thank him.
> > 'perldoc' is installed along with perl. If you have perl, you
> > have perldoc.
>
> I don't have perl. I'm only uploading to my home page. I'm new to this
> and was only testing to see what I could do.
Grab a copy of perl and install it, pronto. You also need a good
book on programming with perl to understand a bit of how and why
Perl works the way it does.
> > He has not displayed any anti-newbie-to-Perl that I can see.
>
> Well, ok. He didn't, but I didn't get an answer either, only some URLs
> and commands that I either had searched before or hadn't access to.
>
> > He showed you how to find the relevant answer (that you claim
> > to have missed).
>
> I still haven't found what I'm looking for. And YES, I've looked. If you
> don't want to answer my question, give me some hints on what to look for
> *on the Internet*, not in perldoc/man.
You must have no idea how offensive that statement is on most newsgroups
in the comp.* heirarchy.
> > You have a strange way of repaying people that answer your questions.
> > That may have an effect on the responses that you can expect for
> > future questions as well...
>
> I'm sorry if I was rude, but I just thought you could spend some more
> time on me than referring to manuals.
Learning to locate documentation is step 0 in your development as a
programmer. It is the best advice you could have possibly received,
and yet you appear uninterested in anything that doesn't amount to a
spoon-feeding.
> And, as I clearly stated in my first message, "I did check your and other's
> FAQs before submitting this question."
Then you didn't do it right, and people tried to help you learn
how.
> But, sure, you don't HAVE TO help me.
Given the rewarding experience you have made it for anyone
that has tried, you can probably take that statement to the
bank.
--
Joe Schaefer
------------------------------
Date: Sat, 23 Dec 2000 17:17:24 GMT
From: chr1st1an <cyner.mail@sweden.com>
Subject: Re: Reverse "append to file"
Message-Id: <3A44DD7F.3040800@sweden.com>
Joe Schaefer wrote:
> http://www.perl.com/pub/doc/manual/html/pod/perlfaq5.html
>
> ...
>
> "How do I change one line in a file/delete a line in a file/insert
> a line in the middle of a file/append to the beginning of a file ?"
I was there before but didn't see that question... Hehe. My mistake.
> In fact, one of the
> local gurus here figured it out for you, and even told you how
> to change the code there to make it work for your needs.
Yes, now that you've shown me the code I see that, but I had no idea of
what he was referring to before.
> Grab a copy of perl and install it, pronto. You also need a good
> book on programming with perl to understand a bit of how and why
> Perl works the way it does.
Ok, I'll do that.
>> I still haven't found what I'm looking for. And YES, I've looked. If
you
>> don't want to answer my question, give me some hints on what to look
for
>> *on the Internet*, not in perldoc/man.
>
> You must have no idea how offensive that statement is on most newsgroups
> in the comp.* heirarchy.
No. I haven't got a clue. I don't even understand what you're meaning.
But nevermind.
> Learning to locate documentation is step 0 in your development as a
> programmer. It is the best advice you could have possibly received,
> and yet you appear uninterested in anything that doesn't amount to a
> spoon-feeding.
Well, yes. And as I have said I tried, but I didn't have much patience,
so I asked in here instead (the easier solution).
> Then you didn't do it right, and people tried to help you learn
> how.
Sure. (Not that I found the answer to my question, but, sure. They did.)
>> But, sure, you don't HAVE TO help me.
>
> Given the rewarding experience you have made it for anyone
> that has tried, you can probably take that statement to the
> bank.
You know, I've been posting messages quite regularly the last few years
(mostly in other programming groups), and nowhere have I gotten such a
harsh response. But I'm glad I got response as such, I thought it'd take
days for anyone to answer. But since you all seem bound not to help me
ever again, I feel somewhat uneasy. Was I really that rude? I'm sorry
for whatever I did. Merry Christmas.
And, Joe, thanks for your help. Now I'll solve my problem.
--
|
| chr1st1an
| cyner.mail@sweden.com
|
------------------------------
Date: 23 Dec 2000 13:41:52 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Reverse "append to file"
Message-Id: <m366kbc74f.fsf@mumonkan.sunstarsys.com>
chr1st1an <cyner.mail@sweden.com> writes:
> Joe Schaefer wrote:
>
> > http://www.perl.com/pub/doc/manual/html/pod/perlfaq5.html
> >
> > ...
> >
> > "How do I change one line in a file/delete a line in a file/insert
> > a line in the middle of a file/append to the beginning of a file ?"
>
> I was there before but didn't see that question... Hehe. My mistake.
Everyone makes mistakes- but until now, noone could tell you even tried
to find it yourself (except taking your word for it, but usually
people don't pay much attention to that because experience often
proves otherwise).
> > In fact, one of the local gurus here figured it out for you,
> > and even told you how to change the code there to make it work
> > for your needs.
>
> Yes, now that you've shown me the code I see that, but I had no idea of
> what he was referring to before.
Now that you know, I trust you'll do the right thing...
> > Grab a copy of perl and install it, pronto. You also need a good
> > book on programming with perl to understand a bit of how and why
> > Perl works the way it does.
>
> Ok, I'll do that.
Great!
> >> I still haven't found what I'm looking for. And YES, I've looked.
> >> If you don't want to answer my question, give me some hints on
> >> what to look for *on the Internet*, not in perldoc/man.
> >
> > You must have no idea how offensive that statement is on most newsgroups
> > in the comp.* heirarchy.
>
> No. I haven't got a clue. I don't even understand what you're meaning.
> But nevermind.
Stick around this newsgroup, and you'll see what I'm talking about.
It's the "gimme" tone that's so unpleasant, and unfortunately too
near the norm in this newsgroup. Many people abuse c.l.p.misc by
treating it as their own free personal "customer support" desk, and
some commercial websites contribute to this error by providing a
web-interface to usenet and calling it their Help site, thus
profiteering off the labors of others.
> > Learning to locate documentation is step 0 in your development as a
> > programmer. It is the best advice you could have possibly received,
> > and yet you appear uninterested in anything that doesn't amount to a
> > spoon-feeding.
>
> Well, yes. And as I have said I tried, but I didn't have much patience,
> so I asked in here instead (the easier solution).
Overexuberance is quite forgivable, and we are all victims to
it from time to time. However, you have to recognize that it's
the *wrong* thing to do. This newsgroup is deluged with impatient,
overexuberant young programmers that often show no deference to the
people that actively contribute to the well-being of the language.
For your own benefit, you should make every effort to distinguish
yourself from these parasites.
> > Then you didn't do it right, and people tried to help you
> > learn how.
>
> Sure. (Not that I found the answer to my question,
> but, sure. They did.)
Had you provided more context to your question (e.g. I don't
have perl installed on my computer, but I was poking around
the perl.com website looking for an answer to the following
question ... Could anyone help me find it?), you likely would
still have been excoriated a bit for a premature question, but
within 2-3 replies, a direct and helpful answer would have come
out of it. It is the _wrong_ thing to do to ask a technical
question in a technical newsgroup about software that you haven't
yet installed (unless you're asking how to install it :)
> >> But, sure, you don't HAVE TO help me.
> >
> > Given the rewarding experience you have made it for anyone
> > that has tried, you can probably take that statement to the
> > bank.
>
> You know, I've been posting messages quite regularly the last
> few years (mostly in other programming groups), and nowhere
> have I gotten such a harsh response. But I'm glad I got
> response as such, I thought it'd take days for anyone to answer.
> But since you all seem bound not to help me ever again, I feel
> somewhat uneasy. Was I really that rude? I'm sorry
> for whatever I did. Merry Christmas.
>
> And, Joe, thanks for your help. Now I'll solve my problem.
Most of the harshness was simply due to unfortunate timing-
keep in mind that none of it is personally directed at you.
It's an effort to try and prevent people from asking a dumb
question that's been asked twice before on the same day for
the many years. Personally I believe the entities that ask
these reduntant questions were spontaneously generated and
usually exist just long enough to recollide with the
appropriate antiparticle. That collision is often witnessed
firsthand in this newsgroup.
Don't be afraid to ask future questions here, but be sure
you make it damn clear to everyone that you've done
everything possible to resolve your problem yourself-
checking the FAQ's thoroughly and doing a dejanews search
in this newsgroup is an absolute necessity unless you're
prepared for some potential embarassment. Whever possible,
post code that illustrates exactly what you're stuck on.
You may be lucky enough to get an answer from one of the
developers of perl. It can be a mixed blessing, though ;)
Assuming you'll do the right thing w.r.t. the person that
actually answered your question best- welcome to clp.misc.
:)
Happy Holidays, Christian.
--
Joe Schaefer
------------------------------
Date: 23 Dec 2000 18:51:56 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Reverse "append to file"
Message-Id: <977596406.25786@itz.pp.sci.fi>
In article <3A44DD7F.3040800@sweden.com>, chr1st1an wrote:
>
>Well, yes. And as I have said I tried, but I didn't have much patience,
>so I asked in here instead (the easier solution).
And I don't have much patience reading posts from impatient people, so
I just gave a -999 score to your posts (the easier solution).
>You know, I've been posting messages quite regularly the last few years
>(mostly in other programming groups), and nowhere have I gotten such a
>harsh response. But I'm glad I got response as such, I thought it'd take
Clpm is special. We have people here who could authoritatively answer
just about any Perl question that could be asked. We are also flooded
with questions that are in the FAQ, too incredibly silly to have made
it into the FAQ, or just completely irrelevant to Perl.
The latter don't seem to be going away, but some of the former do.
I've heard stories that, long before I got here, Larry Wall used to
participate in this newsgroup. At least Tom Christiansen is back, and
appearently determined to drive away the FAQ askers.
>days for anyone to answer. But since you all seem bound not to help me
>ever again, I feel somewhat uneasy. Was I really that rude? I'm sorry
>for whatever I did. Merry Christmas.
Well, yes, you were. But the rudest thing you've said so far was in
the first paragraph I quoted above. Apparently you'd rather have an
entire newsgroup spoonfeed you answers than find them yourself. And
you have the guts to claim that that's the easier solution, which it
of course is for *you*, because someone else has to do the work.
Well, it's not going to be me. Next time you post here, don't be
surprised if none of the experts reply. They probably won't see it.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Sat, 23 Dec 2000 18:07:14 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Site Up Status
Message-Id: <slrn949qe6.ksf.efflandt@efflandt.xnet.com>
On Thu, 21 Dec 2000, robertf57@my-deja.com <robertf57@my-deja.com> wrote:
>Can anyone recommend a publicly available Perl script that will monitor
>a website's (up) status and page the admin if it goes down? Thanks.
Even if you do not have the LWP module you could cobble up something like
this by expanding on the webget example in perldoc perlipc:
#!/usr/bin/perl -w
my $url = "http://localhost/";
use IO::Socket;
my($type,$host,$uri);
my $EOL = "\015\012";
my $BLANK = $EOL x 2;
print scalar(localtime), " ";
if ($url =~ m{(https?)://([^/]*)/*(\S*)}) {
$type = $1;
$host = $2;
$uri = '/'.$3;
} else {
die "URL '$url' is munged!\n";
}
if ($host =~ /^([^:]*):*(\S*)/) {
$remote = $1;
$port = $2;
} else {
die "Host '$url' is munged";
}
$port = getservbyname($type, 'tcp') unless $port;
die "Can't determine port\n" unless $port;
$remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => $host,
PeerPort => "$type($port)"
);
if ($remote) {
$remote->autoflush(1);
print $remote "HEAD $uri HTTP/1.0$EOL\Host: $host" . $BLANK;
my @lines = <$remote>;
close $remote;
if ($lines[0] =~ /HTTP/i) {
print "$host is online\n";
print "$url reply: $lines[0]"; # optional
exit;
}
}
print "$host is down\n";
# Insert pager dialer routine
# Use the Win32::SerialPort module to dial the pager
# or Device::SerialPort for Linux or Unix systems.
--
David Efflandt efflandt@xnet.com 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: Sat, 23 Dec 2000 18:52:07 GMT
From: "Zarathustra" <zarathustra@enviroweb.org>
Subject: Re: Substrings
Message-Id: <rv616.9844$G4.423377@newsread2.prod.itd.earthlink.net>
"Adam Levenstein" <cleon42@my-deja.com> wrote in message
news:91lrqs$8u0$1@nnrp1.deja.com...
> Hey all,
>
> Here's the line, read from a file:
>
> USER:username
>
> followed by a newline, and the username is of varying lengths. I'm
> trying to get the username and put it into $user. Here's the line I've
> been using, but doesn't seem to work:
>
> $user = "VALUE=\"" . ($data[3] =~ /USER:\S{1,}\n$/) . "\"";
> The goal here is to make $user equal
>
> VALUE="username", for an HTML input field.
>
Considering you have a file user.txt:
USER:someone
USER:someelse
you could get them with:
open F, 'user.txt' or die 'Failed to open user.txt: ', $!;
my @users = map{join(q<>, q<Value=">, /^USER:(.+)\n$/, q<">)} <F>;
close F or die 'Failed to close user.txt:', $!;
and @users would contain ("Value=someone", "Value=someoneelse").
------------------------------
Date: Sat, 23 Dec 2000 17:38:27 GMT
From: "Brad Bollenbach" <bbollenbach@homenospam.com>
Subject: Where to obtain the perlrtfm podpage?
Message-Id: <nq516.54363$Z9.3266472@news1.rdc1.mb.home.com>
Hello,
I've seen Tom Christiansen mention his newly penned "perlrtfm" podpage.
Where can I obtain this? I've search clpm on deja, tried google, and also
tried my own perl installation to see if I could find it, but have had no
luck yet.
Thanks for your time,
Brad
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5190
**************************************