[15995] in Perl-Users-Digest
Perl-Users Digest, Issue: 3407 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 18 00:10:24 2000
Date: Sat, 17 Jun 2000 21:10:11 -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: <961301411-v9-i3407@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 17 Jun 2000 Volume: 9 Number: 3407
Today's topics:
Re: filesystem-like data structure (Clinton A. Pierce)
good books for beginning Perl? <NOSPAM@NOSPAM.NET>
Re: good books for beginning Perl? (Abigail)
How to determine a fake email address <aneely@softouch.on.ca>
Re: How to determine a fake email address <rootbeer@redcat.com>
Re: How to determine a fake email address (Abigail)
Re: NET::SMTP (Alan Barclay)
Newbie: Deleting lines in a file <iam007@gofree.indigo.ie>
Re: Newbie: Deleting lines in a file (Clinton A. Pierce)
Re: now this is strange... <kmsproule@worldnet.att.net>
Perl and the WSH <jvm@ysabel.net>
Re: Perl and the WSH <jvm@ysabel.net>
Re: Random number <fabion@sti.com.br>
Re: Random number <godzilla@stomp.stomp.tokyo>
Re: Random number (brian d foy)
Re: why does this code print two spaces? <rootbeer@redcat.com>
Re: Yet Another Abigail Admirer (WAS Re: Crazy enough t (Gwyn Judd)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 Jun 2000 23:59:05 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: filesystem-like data structure
Message-Id: <dhU25.3304$fR2.41064@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <86n1kkhtps.fsf@kronstadt.speakeasy.org>,
Ian Zimmerman <itz@speakeasy.org> writes:
> Hi, I hope to implement something like the interactive mode (-i) of
Sounds nice.
> My question is, how best to represent the filesystem structure?
> Leaving it flat just like the tar listing means unacceptable search
> times, but OTOH something like a recursively nested array (containing
> references to subdirectory contents) might take too much store, I am
> afraid (the typical tar listing I have in mind is between 1 and 5MB),
> and it wouldn't be trivial to construct, either. (Basically I'd need
> to rewrite the kernel namei() routine in perl...)
Didja think this one through? First of all, what's 5MB? When ya think
about it, not much. And 1 MB? I have awk programs that generate that
much data. And are you sure you'll get 5MB in your structure anyway?
If it's a tar listing, a proper strucutre won't have the full pathname
stored in each node, just the nodename and a link back to the parent.
So do it, but use a structure for clarity and because that's what
structures are good for.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sun, 18 Jun 2000 00:24:32 +0100
From: "yft" <NOSPAM@NOSPAM.NET>
Subject: good books for beginning Perl?
Message-Id: <POT25.1557$R5.131570@monolith.news.easynet.net>
Hi
I would like to learn Perl from scratch, can anyone recommend a good book on
it? I have very very little programming experience. So far I've short listed
"Learning Perl" and "Teach yourself Perl in 21 days". Any ideas?
Thanks in advance.
Jonathan Tsu
------------------------------
Date: 17 Jun 2000 19:42:34 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: good books for beginning Perl?
Message-Id: <slrn8ko49g.mlf.abigail@alexandra.delanet.com>
yft (NOSPAM@NOSPAM.NET) wrote on MMCDLXXXII September MCMXCIII in
<URL:news:POT25.1557$R5.131570@monolith.news.easynet.net>:
"" Hi
""
"" I would like to learn Perl from scratch, can anyone recommend a good book on
"" it? I have very very little programming experience. So far I've short listed
"" "Learning Perl" and "Teach yourself Perl in 21 days". Any ideas?
If you don't know how to program, get a text book about programming
first. Pick one that doesn't use a specific language; otherwise it'll
bog you down on nitty gritty details of a language instead of learning
how to program.
Once you know how to program, skip the above mentioned books, and pick
either "Perl: the Programmers Compagnion" or "Elements of Programming
with Perl".
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: Sun, 18 Jun 2000 02:24:54 GMT
From: Amer Neely <aneely@softouch.on.ca>
Subject: How to determine a fake email address
Message-Id: <394C32DB.45200417@softouch.on.ca>
I'm not sure if this is a sendmail question, or a Perl question. My
apologies if I've got it wrong. I'm not an administrator, so answers
involving configuring sendmail will be no good to me.
I'm using Perl to call sendmail to mail information to an address
supplied by a user in the form. I can check to see if the address is in
the correct format, but is there any way I can find out if the message
actually went through or bounced? I'm hoping there is a flag I can check
with Perl? I would like to check for both Host unknown and User unknown
errors. If I can do this *before* sending the message all the better.
Thanks for any help.
--
Amer Neely aneely@softouch.on.ca
Softouch Information Services: http://www.softouch.on.ca/
Research Central: http://www.softouch.on.ca/rc/
"There was a time when I thought I should be like everyone else.
Then there was a time when I thought everyone else should be like me.
Now I just think." - Amer Neely
------------------------------
Date: Sat, 17 Jun 2000 19:54:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to determine a fake email address
Message-Id: <Pine.GSO.4.10.10006171942480.21108-100000@user2.teleport.com>
On Sun, 18 Jun 2000, Amer Neely wrote:
> I'm not sure if this is a sendmail question, or a Perl question.
If it would be essentially the same question if you were using, say, C
instead of Perl, it's probably not a Perl question. This one isn't a Perl
question.
> I'm not an administrator, so answers involving configuring sendmail
> will be no good to me.
You may need to hire an administrator. :-(
> I'm using Perl to call sendmail to mail information to an address
> supplied by a user in the form. I can check to see if the address is in
> the correct format, but is there any way I can find out if the message
> actually went through or bounced?
No. If you don't hear anything back, there's no way to tell in general
what happened to the message. That's a general property of e-mail, not
something peculiar to sendmail.
> I would like to check for both Host unknown and User unknown
> errors. If I can do this *before* sending the message all the better.
Well, with Net::DNS, you could check that there's a MX for the recipient.
But as for the addressee in particular, no, in general, you can't check
without hearing them say "I got it" or "I didn't get it". See the FAQ.
Still, read the docs for Net::SMTP (part of libnet) if you want to connect
directly to the remote mail server, but remember that the remote mail
server may be offline or busy at the time you're trying to send the mail.
sendmail will queue the message for you and try again later, but if you're
going to connect directly, you'll need to do that yourself.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 17 Jun 2000 23:15:50 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: How to determine a fake email address
Message-Id: <slrn8kogpd.ojo.abigail@alexandra.delanet.com>
Amer Neely (aneely@softouch.on.ca) wrote on MMCDLXXXIII September
MCMXCIII in <URL:news:394C32DB.45200417@softouch.on.ca>:
|| I'm not sure if this is a sendmail question, or a Perl question. My
|| apologies if I've got it wrong. I'm not an administrator, so answers
|| involving configuring sendmail will be no good to me.
||
|| I'm using Perl to call sendmail to mail information to an address
|| supplied by a user in the form. I can check to see if the address is in
|| the correct format, but is there any way I can find out if the message
|| actually went through or bounced? I'm hoping there is a flag I can check
|| with Perl? I would like to check for both Host unknown and User unknown
|| errors. If I can do this *before* sending the message all the better.
No, you cannot. Host unknown and User unknown can only be detected after
attempted delivery.
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: 18 Jun 2000 02:18:59 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: NET::SMTP
Message-Id: <961294720.580632@elaine.furryape.com>
In article <8iecif$8eg$2@nntp9.atl.mindspring.net>,
Eric Bohlman <ebohlman@netcom.com> wrote:
>That method depends on being able to directly contact a mail server
>that's set to honor SMTP 'vrfy' requests, something many mail servers
>refuse to do. And of course it doesn't work if the address in question
Even worse, many mail servers will happily verify any address, as long
as it's syntaxically correct.
------------------------------
Date: Sat, 17 Jun 2000 23:25:58 +0100
From: Killo <iam007@gofree.indigo.ie>
Subject: Newbie: Deleting lines in a file
Message-Id: <tmunksoiutulbbc206oke3coafpo5ggppq@4ax.com>
Is there any fuction or easy enough method to delete lines at the
beginning of a text file.
Thanks
------------------------------
Date: Sat, 17 Jun 2000 23:27:56 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Newbie: Deleting lines in a file
Message-Id: <0QT25.3301$fR2.40531@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <tmunksoiutulbbc206oke3coafpo5ggppq@4ax.com>,
Killo <iam007@gofree.indigo.ie> writes:
> Is there any fuction or easy enough method to delete lines at the
> beginning of a text file.
The short answer is no. The long answer is in the FAQ, which is where
you should have looked first.
Found in /usr/lib/perl5/5.00503/pod/perlfaq5.pod
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?
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sun, 18 Jun 2000 00:50:01 GMT
From: "Kevin M. Sproule" <kmsproule@worldnet.att.net>
Subject: Re: now this is strange...
Message-Id: <Z0V25.6329$Uw3.420144@bgtnsc04-news.ops.worldnet.att.net>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:394c5eeb.12590732@news.skynet.be...
> Kevin M. Sproule wrote:
>
> >Oh you were so close!
> >
> >foreach $key (keys(%FORM)) {
> > $$key = $FORM{$key};
> >}
> >
> >Note the extra $ which means use indirection. This will assign the
values
> >to variables generated by $$key. Cool stuff!
>
> Give me one good reason why you want $$key instead of $FORM{$key}, or
> $name instead of $FORM{name}.
>
> It's dangerous. Don't do it.
>
> --
> Bart.
Bart,
You are absolutely correct. Creating dynamic variables "on the fly" can
cause problems. The questions was "how to do it", not "should it be done".
This "Swiss-army chain saw" will let you cut off both arms and legs if you
are not careful. With power comes responsibility.
Digitally yours,
Kevin Sproule
------------------------------
Date: Sat, 17 Jun 2000 02:23:13 +0200
From: Jan van Mansum <jvm@ysabel.net>
Subject: Perl and the WSH
Message-Id: <394AC4F1.84FBDC74@ysabel.net>
Hello all,
I am writing scripts for the Windows Script Host and I take it you can
also use Perl instead of VBScript or JScript. However, how do you work
with the objects that provide basic in- output facilities? (I tried to
call WScript.Echo but that doesn't work.)
I am using ActivePerl.
Thanks for any help.
Regards,
Jan van Mansum.
------------------------------
Date: Sat, 17 Jun 2000 03:23:03 +0200
From: Jan van Mansum <jvm@ysabel.net>
Subject: Re: Perl and the WSH
Message-Id: <394AD2F7.883B482@ysabel.net>
Never mind, examples and answers on the net:
http://pages.infinit.net/che/perlwsh/perlwsh0.html
http://cwashington.netreach.net/script_repository/
Jan van Mansum schreef:
> Hello all,
>
> I am writing scripts for the Windows Script Host and I take it you can
> also use Perl instead of VBScript or JScript. However, how do you work
> with the objects that provide basic in- output facilities? (I tried to
> call WScript.Echo but that doesn't work.)
>
> I am using ActivePerl.
>
> Thanks for any help.
>
> Regards,
>
> Jan van Mansum.
------------------------------
Date: Sat, 17 Jun 2000 18:48:14 -0300
From: Fabio Niski <fabion@sti.com.br>
Subject: Re: Random number
Message-Id: <394BF21E.83277511@sti.com.br>
Use it like larry wall uses it =)
This is a dice roll, the max number is 6, the min is 1
$roll = int(rand 6) + 1;
Chello wrote:
> Hi all,
>
> I have a little problem I have to generate a random number with two limits
> (upper limit and down limit) for example 1 and 4. When I call the script
> this script would have to display "1" or "2" or "3" or "4". Does somebody
> knows how to do it? Do you have an example?
>
> Thanks a lot
>
> Stéphane
--
Fabio Niski - UIN# 2587619 - www.niski.com
"Life would be so much easier if we could just look at the source code."
-- Unknown
------------------------------
Date: Sat, 17 Jun 2000 15:59:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Random number
Message-Id: <394C02B7.C4B66788@stomp.stomp.tokyo>
(some changes and snippage - original article is missing)
(modules group has been removed)
Fabio Niski wrote:
> Chello wrote:
> > I have a little problem I have to generate
> > a random number with two limits
> > (upper limit and down limit)
> > for example 1 and 4. When I call the script
> > this script would have to display "1" or "2"
> > or "3" or "4". Does somebody knows how to
> > do it? Do you have an example?
> Use it like larry wall uses it =)
> This is a dice roll, the max number is 6, the min is 1
> $roll = int(rand 6) + 1;
How funny! Another coincidence today!
Here is a cute little dice game, couldn't be more
simple. Wrap a little html around this, wallah!
Your friends might enjoy this.
sub Roll_Dice
{
local ($roller, $die1, $die2);
&Various_Nickname;
$roller = $various_nickname;
$die1 = 1 + int(rand(6));
$die2 = 1 + int(rand(6));
if (($die1 eq 1) & ($die2 eq 1))
{ $baska = "<BR><BR> $roller rolled a $die1 and a $die2 SNAKE EYES!";
}
else
{ $baska = "<BR><BR> $roller rolled a $die1 and a $die2"; }
}
To produce a random number, 1 to 4 inclusive,
$number = 1 + int(rand(4));
if (!($number))
{
srand;
$number = 1 + int(rand(4));
}
Little tricky on rand, for this it will
randomly generate 0 , 1 , 2 or 3. Easy
to forget 0 (zero) is in there, unless
you think like a mathematician and myself.
Add one to bump all numbers up by one!
My if (!($number)) is to afford you protection
should you run this on early versions of Perl 5
or run this on Perl 4. This 'srand' is needed
for many early versions of Perl. Be careful
if you run comparisons using 'if conditionals'
like I have in my dice routine. Replace ' eq '
with ' = ' and see what happens! This should
prevent flame articles, I hope.
Godzilla!
------------------------------
Date: Sat, 17 Jun 2000 20:12:50 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Random number
Message-Id: <brian-ya02408000R1706002012500001@news.panix.com>
In article <394C02B7.C4B66788@stomp.stomp.tokyo>, "Godzilla!" <godzilla@stomp.stomp.tokyo> posted:
> Here is a cute little dice game, couldn't be more
> simple.
see below, where it is.
> sub Roll_Dice
why is this wrapped in a subroutine?
> {
> local ($roller, $die1, $die2);
my() is much better nowadays.
> $die1 = 1 + int(rand(6));
> $die2 = 1 + int(rand(6));
if anything deserves a subroutine, it's this repetition of code.
subroutines allow for code re-use, unlike this situation.
> if (($die1 eq 1) & ($die2 eq 1))
there's no need for two tests here (especially one that
is logically incorrect - use && to express logical
conditions. & is a bit operator. furthermore, since
you are working with numbers, you might as well use a
numeric comparison ( == ).
you simply need to test to see if the result is 2. there
is ony one way to get that.
if( $die1 + $die2 == 2 )
> { $baska = "<BR><BR> $roller rolled a $die1 and a $die2 SNAKE EYES!";
> }
> else
> { $baska = "<BR><BR> $roller rolled a $die1 and a $die2"; }
> }
more replication of code. this should be abstracted.
#!/usr/bin/perl
my $sum = 0;
my @dice = map { my $n = 1 + int rand(6); $sum += $n; $n } 1..2;
$" = " and ";
print "The dice say @dice => $sum\n";
print "Snake eyes!\n" if( $sum == 2 );
__END__
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Sat, 17 Jun 2000 19:35:36 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: why does this code print two spaces?
Message-Id: <Pine.GSO.4.10.10006171926400.21108-100000@user2.teleport.com>
On Fri, 16 Jun 2000, mark rowlands wrote:
> I edited in place to tidy it up a bit - sorry for the typo
>
> #!/usr/bin/perl
Okay, this is better. But I can't see how this program would produce the
output that you showed originally. Could that output have also been
edited?
Let's try this. Make a small, stand-alone program which others can use to
see the problem you're having. By cutting your code down as far as
possible, you'll make it easier for others to help you. In the mean time,
here are some ideas which may help you to improve your code.
> while (<OLD>){
> (@db) = split(/\|/,$_);
> dostuff();
> }
Although perl doesn't care, using good, consistent indentation will make
your code easier to read, write, debug, and maintain.
It looks as if you're passing parameters to dostuff() via global
variables. That's generally a bad way to do it; use a parameter list, and
your code will be easier to read, write, debug, and maintain.
Also, maybe the name of the sub could be better. do_stuff() would be an
improvement, unless you meant dos_tuff(). Of course, maybe it could be
called something related to its purpose. process_data() would be better,
for example. But what is the sub doing?
> sub dostuff {
>
> $ch_here = $db[0];
> $ch_portnum = $db[1];
> $ch_ports = $db[2];
> $ch_status = $db[3];
> $ch_seqindex = $db[4];
> $ch_os = $db[5];
That could probably be done more efficiently as a list assignment.
my($ch_here, $ch_portnum, $ch_ports, $ch_status, $ch_seqindex, $ch_os)
= @db;
I made these my() variables because those are more appropriate for a
subroutine. Of course, if you were using the "ch_" prefix to distinguish
these from other globals (you weren't, were you?) you could probably
eliminate the prefix now that you've got lexical variables.
> open(NEW, "< sampleb") || die("Can't open
> database sampleb $!\n");
Is this right, that you're going to re-read this second file once for each
line of the first file? Probably a lot more efficient to read it once and
keep it around in memory, unless they're both quite large. (Even then,
though, there are better techniques to use.)
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 18 Jun 2000 03:57:58 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Yet Another Abigail Admirer (WAS Re: Crazy enough that it might just work...) :)
Message-Id: <slrn8koib3.6sh.tjla@thislove.dyndns.org>
I was shocked! How could Abigail <abigail@delanet.com>
say such a terrible thing:
>Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote on MMCDLXXXII September
>MCMXCIII in <URL:news:slrn8kmngd.44i.tjla@thislove.dyndns.org>:
>`` I was shocked! How could Abigail <abigail@delanet.com>
>`` say such a terrible thing:
>`` >Abigail
>`` >--
>`` >perl -Mstrict -we '$_ = "goto E.print chop;\n=rekcaH lreP rehtona tsuJ";E1:eval'
>``
>`` I have looked at this and looked at this and I just cannot see how it
>`` works. Could someone please provide an explanation?
>
>
>Come to YAPC and join my talk about JAPHs.
>
And if all the "if only's" in this world were piled up I'd...I'd...I'd have
a bloody big pile that's what!! Unfortunately I have no money to do such
a thing oh well.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Catproof is an oxymoron, childproof nearly so.
------------------------------
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 3407
**************************************