[8252] in Perl-Users-Digest
Perl-Users Digest, Issue: 1868 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 11 22:07:21 1998
Date: Wed, 11 Feb 98 19:00:27 -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 Wed, 11 Feb 1998 Volume: 8 Number: 1868
Today's topics:
Re: <META HTTP-EQUIV="Refresh: QUESTION mbudash@sonic.net
Re: <META HTTP-EQUIV="Refresh: QUESTION mbudash@sonic.net
Re: <META HTTP-EQUIV="Refresh: QUESTION mbudash@sonic.net
Re: Annoying Message Whenever I Read From a File (Martien Verbruggen)
Re: Code Example Needed (Eileen Kortright)
Re: Code Example Needed (Eileen Kortright)
Re: Code Example Needed (O'Shaughnessy Evans)
Re: Code Example Needed (Eileen Kortright)
Cool Site TV Recommender hudson@viconet.com
Re: FAQless Forays (was: Code Example Needed) (Nathan V. Patwardhan)
Re: FAQless Forays (was: Code Example Needed) (Eileen Kortright)
Re: FAQless Forays (was: Code Example Needed) <danboo@negia.net>
Re: FAQless Forays (was: Code Example Needed) <tchrist@mox.perl.com>
Re: FAQless Forays (was: Code Example Needed) <tchrist@mox.perl.com>
Re: Finding the last line in a list? (Michael Wang)
Re: Finding the last line in a list? (Michael Wang)
Re: foreach and my() [GUTS; LONG] <dgoddard@us.oracle.com>
Re: garbage collection in perl <dformosa@st.nepean.uws.edu.au>
Re: Hashes Usage (Steve Linberg)
Re: How Do You Write an Empty While Statement? <dformosa@st.nepean.uws.edu.au>
How the Hell do I...? (Dave Power)
Re: How the Hell do I...? <tchrist@mox.perl.com>
Re: How to "override" modules with -MModule ? (William R. Ward)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Feb 1998 19:53:26 -0600
From: mbudash@sonic.net
Subject: Re: <META HTTP-EQUIV="Refresh: QUESTION
Message-Id: <6btkmm$6j8$1@nnrp2.dejanews.com>
In article <01bd34f0$e681bee0$86d548a6@slip166-72-213-134.ut.us.ibm.net>,
"Charles Wilkins" <thehelm@ibm.net> wrote:
>
> I am a CNE who's not only up against learning perl cgi scripting, but I'm
> doing it from a loadable module
> on a Novell Web Server. The syntax used in the perl script with the
> Perl5.NLM isn't exactly in any of the books that I have. I have been
> adapting code from the samples that I have in order to make do.
>
> I apologize if this isn't the best place for this posting this question:
>
> I have read FAQs and have been all over CGI heaven on the net.
>
> I am aware that <META HTTP-EQUIV="Refresh"
> Content="10;URL=http://www.anywhere.com">
> causes the html doc to refresh the URL line in 10 seconds to
> www.anywhere.com.
>
> Also I am aware of how to use hyperlinks to allow the user to change the
> URL in both html and perl, but
>
> How can I change the URL once I'm in the perl script without using a
> hyperlink?
> Is there an equivalent to <META HTTP-EQUIV="Refresh"
> Content="10;URL=http://www.anywhere.com"> that
> will work in the perl script.
>
print "Location: http://www.domain.com\n\n";
hth -
michael
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 11 Feb 1998 19:57:13 -0600
From: mbudash@sonic.net
Subject: Re: <META HTTP-EQUIV="Refresh: QUESTION
Message-Id: <6btktp$6jl$1@nnrp2.dejanews.com>
In article <01bd34f0$e681bee0$86d548a6@slip166-72-213-134.ut.us.ibm.net>,
"Charles Wilkins" <thehelm@ibm.net> wrote:
>
> I am a CNE who's not only up against learning perl cgi scripting, but I'm
> doing it from a loadable module
> on a Novell Web Server. The syntax used in the perl script with the
> Perl5.NLM isn't exactly in any of the books that I have. I have been
> adapting code from the samples that I have in order to make do.
>
> I apologize if this isn't the best place for this posting this question:
>
> I have read FAQs and have been all over CGI heaven on the net.
>
> I am aware that <META HTTP-EQUIV="Refresh"
> Content="10;URL=http://www.anywhere.com">
> causes the html doc to refresh the URL line in 10 seconds to
> www.anywhere.com.
>
> Also I am aware of how to use hyperlinks to allow the user to change the
> URL in both html and perl, but
>
> How can I change the URL once I'm in the perl script without using a
> hyperlink?
> Is there an equivalent to <META HTTP-EQUIV="Refresh"
> Content="10;URL=http://www.anywhere.com"> that
> will work in the perl script.
>
print "Location: http://www.domain.com\n\n";
hth -
michael
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 11 Feb 1998 19:56:13 -0600
From: mbudash@sonic.net
Subject: Re: <META HTTP-EQUIV="Refresh: QUESTION
Message-Id: <6btkrt$6ji$1@nnrp2.dejanews.com>
In article <01bd34f0$e681bee0$86d548a6@slip166-72-213-134.ut.us.ibm.net>,
"Charles Wilkins" <thehelm@ibm.net> wrote:
>
> I am a CNE who's not only up against learning perl cgi scripting, but I'm
> doing it from a loadable module
> on a Novell Web Server. The syntax used in the perl script with the
> Perl5.NLM isn't exactly in any of the books that I have. I have been
> adapting code from the samples that I have in order to make do.
>
> I apologize if this isn't the best place for this posting this question:
>
> I have read FAQs and have been all over CGI heaven on the net.
>
> I am aware that <META HTTP-EQUIV="Refresh"
> Content="10;URL=http://www.anywhere.com">
> causes the html doc to refresh the URL line in 10 seconds to
> www.anywhere.com.
>
> Also I am aware of how to use hyperlinks to allow the user to change the
> URL in both html and perl, but
>
> How can I change the URL once I'm in the perl script without using a
> hyperlink?
> Is there an equivalent to <META HTTP-EQUIV="Refresh"
> Content="10;URL=http://www.anywhere.com"> that
> will work in the perl script.
>
print "Location: http://www.domain.com\n\n";
hth -
michael
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 12 Feb 1998 00:35:58 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Annoying Message Whenever I Read From a File
Message-Id: <6btg5e$4ho$3@comdyn.comdyn.com.au>
In article <6btbn8$snu@sf18.dseg.ti.com>,
simonsen_nospam@skopen.dseg.ti.com (Kevin M Simonson) writes:
> When I write a "perl" script that reads input from a file, and then
> execute the script, I get this annoying message telling me my file handle
> might be zero, and suggesting that I use the "defined()" command to test
> for it. For example, when I executed program "Hmm" listed below I got the
> message listed below, and it didn't go away until I had inserted my refer-
> ence to the "defined ()" command inside my "while" condition, like I have
> it in "Mdfd" below. Obviously that's going to slow me down and is unneces-
> sary. But I also don't want users of my script to keep getting this annoy-
> ing message.
Have you actually tested how much it is going to slow you down? I
imagine that you won't be able to find a difference at all. Just use
the defined() as the warning suggests, or turn of the -w flag for the
production version of this. Mind you, the warning is there for a good
reason
Alternatively, you can do it this way, which will do an implicit
defined()
while (<HMM>)
{
# Either work with $_ here, or assign $_ to some other variable
}
It will still 'slow you down' though.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Advertising: The science of arresting
Commercial Dynamics Pty. Ltd. | the human intelligence long enough to
NSW, Australia | get money from it.
------------------------------
Date: Thu, 12 Feb 1998 01:12:12 GMT
From: mystra@torilmud.com (Eileen Kortright)
Subject: Re: Code Example Needed
Message-Id: <34e24abb.255296178@news.mw.mediaone.net>
On 11 Feb 1998 15:05:49 -0800, Russ Allbery <rra@stanford.edu> wrote:
>> Take the Julian date to the lowest value of the current key range and
>> subtract the key from the Julian date
>
>> Result: 42-32= 10
Sigh, this should be 11, not 10. Add 1.
Not a good idea to write this stuff when you have a pounding headache
and a baby that won't take her naps. Sigh.
>Personally, I would simply brute-force this. Brute-force is quite often
>the most elegant solution to a problem, and in this case you only *have*
>365 days to worry about. So if you do something like this:
This looks good, but wouldn't this be hard to change? I wanted other
fantasy worlds to be able to use the same code if they wanted. They
may or may not have 365 days in them. Lemme try what you suggest and
see how it works.
I was considering having an input page where people could customize
the code to correspond to their own world. That would be in the
future, but I don't want to limit myself.
I really appreciate you comments. Thank you, sir.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
pixel persuasions, presence providers
World Wide Web Hosting and Design Services, Plymouth, Michigan USA
Set your browser to: http://www.pixel-persuasions.com/
Check out our MUD Site at: http://www.torilmud.com
------------------------------
Date: Thu, 12 Feb 1998 01:04:36 GMT
From: mystra@torilmud.com (Eileen Kortright)
Subject: Re: Code Example Needed
Message-Id: <34e24a26.255146708@news.mw.mediaone.net>
On 11 Feb 1998 23:08:15 GMT, mgjv@comdyn.com.au (Martien Verbruggen)
wrote:
>In article <34e1b633.217265825@news.mw.mediaone.net>,
> mystra@torilmud.com (Eileen Kortright) writes:
>> On 11 Feb 1998 15:16:49 +0100, Calle Dybedahl
>> <qdtcall@esb.ericsson.se> wrote:
>>
>>>But you obviously missed the recurrent posting about chosing a
>>>relevant subject line.
>>
>> Well, obviously I did, since it wasn't included in the messages I
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>You read 217 messages and not one of those contained something like:
That's right and I see you read as well as I do :P
Meaning: yah, I could have missed it. Just like you seem to have
missed the fact that I already stated I read all the messages and
didn't see it.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
pixel persuasions, presence providers
World Wide Web Hosting and Design Services, Plymouth, Michigan USA
Set your browser to: http://www.pixel-persuasions.com/
Check out our MUD Site at: http://www.torilmud.com
------------------------------
Date: 12 Feb 1998 01:27:07 GMT
From: shaug@callamer.com (O'Shaughnessy Evans)
To: mystra@torilmud.com (Eileen Kortright)
Subject: Re: Code Example Needed
Message-Id: <6btj5b$bq7$2@ha1.rdc1.occa.home.com>
[Posted and mailed]
In article <34e24abb.255296178@news.mw.mediaone.net>,
mystra@torilmud.com (Eileen Kortright) writes:
> On 11 Feb 1998 15:05:49 -0800, Russ Allbery <rra@stanford.edu> wrote:
>
> This looks good, but wouldn't this be hard to change? I wanted other
> fantasy worlds to be able to use the same code if they wanted. They
> may or may not have 365 days in them. Lemme try what you suggest and
> see how it works.
>
> I was considering having an input page where people could customize
> the code to correspond to their own world. That would be in the
> future, but I don't want to limit myself.
Perhaps you could use a per-world calendar file for customization.
Easiest would probably be to just make the table a perl array
definition, but it would be simple enough to have each line be
"month-name start-day end-day", I suppose.
--
O'Shaughnessy Evans
http://www.callamerica.net/shaug/
------------------------------
Date: Thu, 12 Feb 1998 01:50:08 GMT
From: mystra@torilmud.com (Eileen Kortright)
Subject: Re: Code Example Needed
Message-Id: <34e2553c.257985534@news.mw.mediaone.net>
On 12 Feb 1998 01:27:07 GMT, shaug@callamer.com (O'Shaughnessy Evans)
wrote:
>Perhaps you could use a per-world calendar file for customization.
>Easiest would probably be to just make the table a perl array
>definition, but it would be simple enough to have each line be
>"month-name start-day end-day", I suppose.
Good point. Thanks.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
pixel persuasions, presence providers
World Wide Web Hosting and Design Services, Plymouth, Michigan USA
Set your browser to: http://www.pixel-persuasions.com/
Check out our MUD Site at: http://www.torilmud.com
------------------------------
Date: Wed, 11 Feb 1998 19:22:12 -0600
From: hudson@viconet.com
Subject: Cool Site TV Recommender
Message-Id: <887231504.864616461@dejanews.com>
Keywords: tv recommender, information filtering, system, perl, cgi, collaborative filtering
Try my URL http://njcmr.njit.edu/elizabeth/welcome.html I am doing a
project about personal recommendation system in NJIT. I created a web
site to do TV recommendations. Now I need a lot of user data to be able
to prove that my algorithm works. All you have to do is rate a few TV
programs and based on your rates and rates of people that are already in
a database the system will be able to create your own personal
recommendation. Try it and tell others to try. By the way I did it in
perl and cgi. God Bless Perl.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 12 Feb 1998 00:47:34 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <6btgr6$18c@fridge.shore.net>
Phil Jach - Reverse to get address (moc.care@hcajp-Reversetogetaddress) wrote:
: The reason I didn't, is because sometimes I have way to many things going
: on. As most IT professionals know, there is always something to be learned
: and never enough time to read it all.
Then again, once IT professionals find time to read Usenet ... it's
fellatio again and again.
: This ng is great. I hope it will always be available for everyone. Just
: because people speed on the freeway doesn't mean we need to put restrictors
: on everyone's cars, does it?
I remember when it was a discussion group. Ah, those were the days.
--
Nathan V. Patwardhan
------------------------------
Date: Thu, 12 Feb 1998 00:58:22 GMT
From: mystra@torilmud.com (Eileen Kortright)
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <34e2471b.254368154@news.mw.mediaone.net>
On 11 Feb 1998 23:09:12 GMT, Tom Christiansen <tchrist@mox.perl.com>
wrote:
>In comp.lang.perl.misc, mystra@torilmud.com (Eileen Kortright) writes:
>:Horror! I'm using Windows! Horror! Flee! Run! It's FREE AGENT, too!
>
>It's not the tool. It's the culture
Mayhap, but I don't like to be classified with that culture just
because I use the tools. Heaven forbid.
>I have used Perl virtually every day of my life for the last ten years,
>and spent a great deal of my free helping people. More than you can
>imagine.
Hrm, it wasn't in reference to your use of Perl, it was in reference
to your FAQ, man pages, etc.
>:Guess what? It's human nature! As a rule, most people do NOT read help
>:files or FAQs.
>
>Then they have no business here. That's not how Usenet works.
Sigh, that's how Usenet is *supposed* to work. It's how it *did* work.
It doesn't work that way anymore. It's sad, but true.
You -- and I, for that matter -- are like dinosaurs clinging to that
last bit of topical island before the glacier finally takes over. We
either join the genetic gene pool as mammals or face extinction.
They got me.
You can hide in your moderated newsgroup, but evenutally you will be
assimulated.
--------
Let's end this, please? I'm at least getting some good feedback on my
original question and that is what I really wanted. I never meant to
start a war with anyone. Honest. Really. I just felt
PS, btw, if you read my code snippet thingy .. I just read your bio
for the new Perl book. In case you were interested the code is for the
Toril MUD web pages. I wanted to give them a more FR look and feel by
having the Harptos calendar available.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
pixel persuasions, presence providers
World Wide Web Hosting and Design Services, Plymouth, Michigan USA
Set your browser to: http://www.pixel-persuasions.com/
Check out our MUD Site at: http://www.torilmud.com
------------------------------
Date: Wed, 11 Feb 1998 20:11:22 -0500
From: Dan Boorstein <danboo@negia.net>
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <34E24C3A.34EE8851@negia.net>
i realize that tom may not see this since i am posting from a http
client (boy, it'll be amazing if *anybody* in usenet sees this!) on
a program loader/broken gui, so if some kind soul could be sure he
gets this i would be most appreciative.
Tom Christiansen wrote:
[mostly agreeable correlations and observations deleted]
>In short, just because they're the victims of a technically challenged
>system doesn't doesn't mean they can dispense with NETIQUETTE.
i am curious to know what justification you claim, to allow yourself
to not only breach netiquette, but also to be outright offensive
regardless of the forum.
>Then there's the matter of, "I'm not a programmer, but I need to program
>this web page". If you're not a programmer, don't try to program.
i am not sure what this last statement means. can you only be a
programmer if you go to school for it? do you have something against
a non-structured education (i.e., outside of an established
institution)? are programmers born? isn't larry wall a linguist?
how did he become a programmer (honestly, i am interested to know)?
thanks,
--
danboo rstein
------------------------------
Date: 12 Feb 1998 02:11:33 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <6btlol$f6k$1@csnews.cs.colorado.edu>
Keywords: diatribe
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, nvp@shore.net (Nathan V. Patwardhan) writes:
:I remember when it was a discussion group. Ah, those were the days.
That was back in the days of before the invasion of the nonprogrammers
from the hoardware culture who think this is comfy place for them to be
read bedtime FAQs by Bonzo. The clash between them and and us is a big
problem. By us, I mean not just those who've been doing perl for ten
years (I may be the only one reading this who has) or been on the real
Internet for the better part of two decades and who remember the IMPS.
No, I'm not talking about them. I'm talking about any of of us who aren't
ashamed to call ourselves programmers. The people who aren't afraid to
do their own research and investigation into FAQs, manpages, and RFCs.
People who understand subconsciously how the freeware world actually
works. You don't have to be old to be competant and a contribution to
the group effort. I know plenty.
But for each of those, there are a hundred others who don't fit this
pattern, who don't know what Netiquette is or who don't care. They are
the ones who have made Usenet a veritable joke, but not really one to
laugh much about. It's not that funny, just sad.
And the argument that there are more of them than us doesn't matter.
I have tried in the last week to inject the group with something of
what used to be here. That means a small bit of humor now and then.
It very much means posting of actual working programs, small but useful,
and hopefully demonstrative. It means posting treatises on your thoughts
and ruminations on matters technical relating to Perl.
But it doesn't mean spoonfeeding FAQs to those who won't read the docs.
For them, there can be no mercy. This is not the place to hear greybeards
recite their writings. Why do you think we wrote them, for Heaven's sake?
So we wouldn't have to go through this.
Nobody owes them anything. This isn't a helpdesk for the functionally
illiterate. It's a mutual benefit society of technical professionals.
If they never do anything but beg the quick answer, to get someone
to do their work for them, they aren't contributing to our society.
So they must be pruned. Killfiles are great. But first a decent
round of flamelessons so they get the message.
Killing by newsreader is probably the most effective thing you can do,
but unfortunately, there are perhaps a scant few out of each hundred
who don't really deserve that kind of treatment. But perhaps it's
worth it. I'm sure there are a few people who don't get addicted to
crack cocaine, either but they're not the ones we're worried about.
Plus any real programmer can trivially write their own newsreader,
or forge the posting attribution.
Soon we'll have a moderated group of one sort of another from which
gimme-a-solution-right-nowrequests and the FAQless will find no support.
And this horrible free-for-all will be left to children wondering around
by themselves in the dark because they refuse to turn on the light and
read the manual.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"SPARC" is "CRAPS" backwards --Rob Pike
------------------------------
Date: 12 Feb 1998 02:24:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <6btmhc$f6k$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, mystra@torilmud.com (Eileen Kortright) writes:
:>Then they have no business here. That's not how Usenet works.
:Sigh, that's how Usenet is *supposed* to work. It's how it *did* work.
:It doesn't work that way anymore. It's sad, but true.
No, what you're describing is something that *DOES*NOT*WORK*.
It is a non-thing. Deadness. Thus, it won't be tolerated.
Selection of the fittest, and all.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I am a little more weird today than normal. --Andrew Hume
------------------------------
Date: 12 Feb 1998 01:45:57 GMT
From: mwang@alhena.ibk.ml.com (Michael Wang)
Subject: Re: Finding the last line in a list?
Message-Id: <6btk8l$ch2$1@news.ml.com>
Just using
system "tail -$n $file";
will beat speedwise than most of the posted solutions provided in Perl
for a large file.
------------------------------
Date: 12 Feb 1998 01:33:32 GMT
From: mwang@alhena.ibk.ml.com (Michael Wang)
Subject: Re: Finding the last line in a list?
Message-Id: <6btjhc$cfv$1@news.ml.com>
If you read line by line, then it is too slow. The effective way of doing
this is start from backward with seek, and count the new lines.
The following is my _prototype_ tail program in Perl. As you can see, it is
not any simpler than doing the same in C. As a matter of fact, if you
stripe out the $ signs, then it can be compiled with C compiler. If you
have a quick and *effective* way than mine, let me know. Thanks.
#!/usr/local/bin/perl -w
use strict;
use FileHandle;
my $fh;
my $buf_scalar;
my @buf;
my $buf_size = 1024;
my $cur_buf_size;
my $end_pos;
my $cur_pos;
my $st_pos;
my $nline = 10;
my $nread;
my $nb;
my $nl=0;
my $SEEK_SET=0;
my $SEEK_CUR=1;
my $SEEK_END=2;
if (@ARGV > 0 && $ARGV[0] =~ /^-(\d+)/) {
$nline = $1;
shift @ARGV;
}
my $file=shift;
$fh = new FileHandle "$file", "r";
seek $fh, 0, 2;
$end_pos = tell $fh;
for ($cur_pos = $end_pos - $buf_size;
$cur_pos != -$buf_size;
$cur_pos -= $buf_size) {
$cur_buf_size = $buf_size;
if ($cur_pos < 0) {
$cur_buf_size = $buf_size + $cur_pos;
$cur_pos = 0;
}
seek $fh, $cur_pos, $SEEK_SET;
$nread = read $fh, $buf_scalar, $cur_buf_size;
@buf = split //, $buf_scalar;
for ( $nb = $nread - 1; $nb >= 0; $nb-- ) {
if ( $buf[$nb] eq "\n" ) {
$nl++;
if ( $nl == $nline + 1 ) {
$st_pos = $cur_pos + $nb + 1;
$nb = -1;
$cur_pos = 0;
}
}
}
}
for ($cur_pos = $st_pos; $cur_pos < $end_pos; $cur_pos += $buf_size) {
seek $fh, $cur_pos, $SEEK_SET;
$nread = read $fh, $buf_scalar, $buf_size;
print $buf_scalar;
}
------------------------------
Date: Wed, 11 Feb 1998 18:33:06 -0800
From: Denis Goddard <dgoddard@us.oracle.com>
Subject: Re: foreach and my() [GUTS; LONG]
Message-Id: <34E25F62.17A9E971@us.oracle.com>
Chipmunk wrote:
>
> Why wonder when you can read the documentation?
Why take someone else's word for it when you can pick at the source?
(okay, that's prolly going a little too far in most cases :)
> I already knew that the keywords "for" and "foreach" were equivalent.
Sure, make light of my Great Discovery! :)
> My point was that this loop:
>
> my($a);
> for ($a=1;$a<=3;++$a) {
>
> does not have the same effect as this loop:
>
> my($a);
> foreach $a (1..3) {
Well, again we look at perly.y, this time with an eye on the for(;;)
production:
| label FOR '(' remember mnexpr ';' mtexpr ';' mnexpr ')' mblock
/* basically fake up an initialize-while lineseq */
{ OP *forop = append_elem(OP_LINESEQ,
scalar($5),
newWHILEOP(0, 1, (LOOP*)Nullop,
$2, scalar($7),
$11, scalar($9)));
copline = $2;
$$ = block_end($4, newSTATEOP(0, $1, forop)); }
Looks like we set up a while loop and just run the WHILEOP opcode.
I know that doesn't answer you "real" question, but daggit, I plowed thru it
last time, now it's your turn!
>> You want a new scope to spring up and protect
>> yer fast-acting loop variable at just the right moment, right?
>
> No, I don't want that. :-)
Er, okaaayyyy.....
Well, if you want different behavior, you *do* have the source code...
> That's how I found this "feature" - I had code like this:
[bad code snipped]
UGH!! bad, bad bad!!!
When you write a procedure that has inputs, pass the inputs as parameters
to the procedure and you will have maintainable code.
One must have pride in one's work! We are artists, yes?!
> my($id, $id_iter);
> foreach $id_iter (@ids) {
> $id = $id_iter; # YUCK!
> &do_something();
> }
> sub do_something {
> print "$id\n"; # DOUBLE-YUCK!!
> }
NO!!! Do this instead:
my($id_iter);
foreach $id_iter (@ids) {
&do_something($id_iter);
}
sub do_something {
my $id = $_[0];
# ...do things...
}
And all your problems go away.
Of course, if you were passing a big array or hash, you'd pass
it as a reference, but you knew that.
When a subroutine has inputs, pass the inputs as parameters.
When a subroutine has inputs, pass the inputs as parameters.
When a subroutine has inputs, pass the inputs as parameters.
When a subroutine has inputs, pass the inputs as parameters.
Modularity, reusability, robustness, and readability are *NOT* artifacts
of object-oriented coding. They are artifacts of *DISCIPLINED* coding,
no matter what the language.
> [Note: in my real code, there are about 20 different functions that use $id
> and other related variables.]
All the more reson to code in a disciplined, maintainable fashion.
"Global variables. Hurt people. Bad scene."
> And my code was immediately broken.
When you code using undisciplined, unstructured practices, you find that
your code is a house of cards, easily broken.
Nothing personal;
I'm just trying to start a *REALLY* annoying religious thread :)
And yes, I realize I did not answer your question. But I believe that
from my other annoyingly long post and the abovementioned section of perly.y,
if you are really interested, you can find the answer (and report back!)
-Denis
--
__ __ _ __ __
~~~~(__)|-< /-\(__ |__(-_ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Denis Goddard, Senior Member, Tech. Staff |"I see the heads of men arise
email: dgoddard@us.oracle.com |with hungry minds and open eyes!"
ourworld.compuserve.com/homepages/d_goddard| -Rush, from 2112: _The Oracle_
------------------------------
Date: 12 Feb 1998 01:27:56 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: garbage collection in perl
Message-Id: <887246836.550490@cabal>
In <6bss3q$e99$1@csnews.cs.colorado.edu> Tom Christiansen <tchrist@mox.perl.com> writes:
> [courtesy cc of this posting sent to cited author via email]
>In comp.lang.perl.misc, cberry@cinenet.net (Craig Berry) writes:
[...]
>:Doing OS-visible heap releases tends to be a high-overhead, low-profit
>:operation.
[...]
>It's really very much like a text file. You want to remove a few words
>here and there. Well, you can't actually do that, although you could
>change where EOF fell. You have to make a new copy, crunch down, then
>truncate.
>malloc() is seldom amenable to that kind of thing, and even if it is,
>you can bet your program isn't. And how are you going to go find how
>all the myriad places that mention those pointers and change *them*?
I know that there have been modifactions to the mark and sweep model of
garbige collectors who move around memory so that thay are nicely arranged
on the pages.
Such a GC could do this for perl, but of cause the cost of implermenting
such a beast would probly not be worth the cost of upsetting the code that
depeands on a ref-counter based GC.
BTW I know that a Mark and sweep GC is triggered at the end of perls run,
is there anyway one could cause it to sweep in the middle of a run?
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Wed, 11 Feb 1998 19:53:13 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Hashes Usage
Message-Id: <linberg-1102981953130001@projdirc.literacy.upenn.edu>
In article <34E1ECA4.31816C9C@micro.ti.comSNIP>, Holly Sommer
<SNIPhsommer@micro.ti.comSNIP> wrote:
> For the dates element, if I read it in as a line (dates => $dates),
> and then @dates = split( / /, $dates) , how do I reference the
> individual
> elements of the @dates array, which is in a hash, which is in an array
> of hashes? $records[$i]{$dates[$k]} ?
>
> How do I get a multi-line value associated with one key?
>
> Thanks :)
Saying @dates = split( / /, $dates) creates a new array called @dates
(assuming it wasn't already defined) that contains the space-delimited
elements of your $date string.
What I would say is, why worry about storing it in seperate elements?
Store it as a simple element, then chop it up and play with it when you
need it.
You can reference the individual elements like this: $dates[$i] where $i
is the 0-based index.
Cheers,
--
Steve Linberg | National Center on Adult Literacy
Systems Programmer etc. | University of Pennsylvania
linberg@literacy.upenn.edu | http://www.literacyonline.org
------------------------------
Date: 12 Feb 1998 00:46:29 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: How Do You Write an Empty While Statement?
Message-Id: <887244350.108762@cabal>
Keywords: empty while write
In <6bt62c$qt8@sf18.dseg.ti.com> simonsen_nospam@skopen.dseg.ti.com (Kevin M Simonson) writes:
> while (`ls Hmm.Hmm | wc -l < 1`);
> syntax error at Hmm line 2, near ");"
This should be
while (`ls Hmm.Hmm | wc -l <1`) {};
I hope this helps.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Thu, 12 Feb 1998 02:23:39 GMT
From: dave.power@adpdesign.com (Dave Power)
Subject: How the Hell do I...?
Message-Id: <34e254cd.38087282@news.virgin.net>
This Q is directed towards Gurus, intermediates and to other beginners
who began before me! I make no apologies for being new to the Perl
language and my Q is surely as simple as they come.
I need to create a temp file, process it, then delete it.
My code, so far is something like this:
$i=0;
$filename="tempfile".$i.".ext";
$filename="tempfile".$i++.".ext" while FileExists(TEMP,$filename)==1;
open(TEMP,">".$filename);
# Write some info to the temp file here
close(TEMP);
#Prrocess the file here
#After finish, DELETE the file here - but HOW?
sub FileExists(TEMP,$filename){
if(open(TEMP,$filename)){
close(TEMP);
1;
}
}
How do I delete a temporary file once it's finished with?
My instincts tell me that if a function doesn't exist then it's not
needed. 'DeleteFile' isn't documented - so what's the proper way to
tackle this?
I'm pretty embarrassed to ask such a question. Please don't chastise
me more than nec.
Finally, if the above code is crap or can be done better, I'd be most
grateful if you could suggest alternatives.
DP
------------------------------
Date: 12 Feb 1998 02:33:11 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How the Hell do I...?
Message-Id: <6btn17$f6k$5@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
Futhering the descent into oblivion, Forte Agent 1.5/32.452 helped
dave.power@adpdesign.com (Dave Power) ask in comp.lang.perl.misc:
:I need to create a temp file, process it, then delete it.
You mean like the question from section five of the Perl FAQ?
% man perlfaq5
...
How do I make a temporary file name?
:How do I delete a temporary file once it's finished with?
% man perlfunc | grep -i delete
[amongst other things ...]
XXXXXX Deletes a list of files. Returns the number
of files successfully deleted.
The XXXXXX is left for you to lookup on your now. Although
if you read the FAQ, there's a way to do that (see the POSIX
module or the IO::File module) in which it's not even needed.
In short, the answers to this question, like most on this
group, can be found in the standard documentation included
with every release of Perl.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
There is, however, a strange, musty smell in the air that reminds me of
something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
--Larry Wall in Configure from the perl distribution
------------------------------
Date: 11 Feb 1998 18:32:39 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: How to "override" modules with -MModule ?
Message-Id: <waa67mld03c.fsf@ese.UCSC.EDU>
mgjv@comdyn.com.au (Martien Verbruggen) writes:
> In article <6bqq6b$ec3@nwd2nws1.analog.com>,
> bryan@spd.analog.com (Bryan Bayerdorffer @ Wit's End) writes:
> > I have a skeleton Perl program, written as a set of modules/files,
> > say A.pl, B.pm, C.pm. Now, I want other folks to be able to
> > replace C.pm with their own modules (say X.pm and Y.pm) WITHOUT
> > having to modify A.pl or B.pm. The only thing they should have to
> > worry about is that X and Y export the same symbols that C
> > exports.
>
> The best way to do this is to have these people inherit everything
> from your module. Of course, you will need to write your module the
> right way for people to be able to do that.
>
> perldoc perltoot
> perldoc perlobj
> perldoc perlmod
>
> All of the above should tell you how to do that.
I don't think that what Bryan wants to do is covered there. I have
wondered about how to do this myself. To elaborate Bryan's example as
I understand it, you let's say that A.pl has "use B" and B.pm has "use
C" but you want to change the behavior (but not the API) of C.pm
without having to modify B and tell it to use X instead.
For a more concrete example: let's say that A.pl is your script, B is
an object oriented widget that stores data in a database, and C is the
DBI for Oracle. If you want to use Postgres instead, you would write
a module X that implements the same methods as C but talks to Postgres
instead of Oracle. How do you do this without having to mess around
with B?
The only solution I can think of is to make the front end script
instantiate an object of class C or X or whatever and pass that to B
as an argument. But I find that to be messy, because then you have to
modify A.pl (one of Bryan's "no-nos").
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
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 1868
**************************************