[13814] in Perl-Users-Digest
Perl-Users Digest, Issue: 1224 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 29 18:10:46 1999
Date: Fri, 29 Oct 1999 15:10:32 -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: <941235031-v9-i1224@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 29 Oct 1999 Volume: 9 Number: 1224
Today's topics:
Re: It is always like this here? <jon@midnightbeach.com>
Re: It is always like this here? (Tad McClellan)
Re: It is always like this here? <aqumsieh@matrox.com>
Re: It is always like this here? <cassell@mail.cor.epa.gov>
Re: It is always like this here? <cassell@mail.cor.epa.gov>
Re: It is always like this here? (Abigail)
Re: It is always like this here? <cassell@mail.cor.epa.gov>
Re: It is always like this here? <cassell@mail.cor.epa.gov>
memory handling in perlguts <patrick@meer.net>
Re: memory handling in perlguts (Ilya Zakharevich)
Need help fixing this multi-file ftp script <dutch@mindspring.com>
Re: Pack function in Active Perl (win32) buggy? <cassell@mail.cor.epa.gov>
Perl assoc. array file database error... help please <SteveS@HTProf.com>
perl safe_mysqld <mikes@athabascau.ca>
Re: Reading a file backwards? (Michael Budash)
Re: Reading a file backwards? <jtolley@bellatlantic.net>
Re: Reading a file backwards? <ramvinod@eng.umd.edu>
Re: Reading a file backwards? <lr@hpl.hp.com>
Re: Reading a file backwards? <uri@sysarch.com>
Re: Reinventing the wheel <cassell@mail.cor.epa.gov>
Re: simplifying a script <lr@hpl.hp.com>
Re: simplifying a script <cassell@mail.cor.epa.gov>
string number conversion <Jing.Shi@usa.alcatel.com>
Re: string number conversion (Brett W. McCoy)
What's an elegant way to populate an array with method <duane@blur.com>
Re: Why extra junk at end of new file? Not anymore!! :) (Jon)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Oct 1999 12:05:53 -0700
From: Jon Shemitz <jon@midnightbeach.com>
Subject: Re: It is always like this here?
Message-Id: <3819F011.61220C0B@midnightbeach.com>
Mark Bluemel wrote:
> Are there techniques we could use to improve things, like frequently
> posted pointers to FAQs etc... (No, not the whole flaming things - if
> people can read news, surely they can find a web page given a hint)? Or
> is it simply that Perl attracts a vast number of <insert your
> uncomplementary epithet here>?
My suspicion is that the FAQ is too big. A 90-10 rule probably applies:
90% of the FAQ's are only 10% of the FAQ's in the FAQ. This can make it
hard to spot your question. Even if I'm wrong about the 90-10, the sheer
number of questions in each section seems to break all sorts of
principles of effective information presentation.
I think it might be a good idea to break each section down into
subsections. Each section would retain the five or so most common
questions, and the remainder would be be parceled out into new
subsections, none of them bigger than five or so questions.
--
http://www.midnightbeach.com - Me, my work, my writing, and
http://www.midnightbeach.com/hs - my homeschool resource pages
------------------------------
Date: Fri, 29 Oct 1999 09:56:02 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: It is always like this here?
Message-Id: <i19cv7.8k.ln@magna.metronet.com>
Mark Bluemel (mark.bluemelNOmaSPAM@siemens.co.uk.invalid) wrote:
: I've been teaching myself Perl for a few weeks, with moderate success,
: so I thought I'd join the newsgroup. After just one day, I'm more than
: half inclined to drop out again.
Larry Wall has.
Tom Christiansen has.
A few dozen others, some of whom work in perl itself, have.
Usenet used to be worth a lot.
It is worth much less nowadays.
Usenet is no longer for geeks.
Now it is "for" consumers, it would seem.
:-(
: Large amount of traffic, huge
: noise-to-signal ratio, cluelessness in abundance and a fair proportion
: of abuse - these all add up to somewhere that I'm not feeling like
: hanging round in.
: Is it always like this, or have I picked a bad time?
Yes, it is always like this.
(ever since Virtual September began a few years ago)
: Are there techniques we could use to improve things, like frequently
: posted pointers to FAQs etc...
There is one posted here twice a week, yet the noise seems
unabated, as you have noticed...
It doesn't seem to help enough.
: (No, not the whole flaming things - if
: people can read news, surely they can find a web page given a hint)?
There you have a faulty assumption.
You don't need any 'net savvy at all to participate in Usenet
nowadays.
If you can pointy clicky, you can posty.
: Or
: is it simply that Perl attracts a vast number of <insert your
: uncomplementary epithet here>?
You are insightful!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 29 Oct 1999 13:41:48 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: It is always like this here?
Message-Id: <x3yd7ty83ok.fsf@tigre.matrox.com>
Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid> writes:
> I've been teaching myself Perl for a few weeks, with moderate success,
> so I thought I'd join the newsgroup. After just one day, I'm more than
> half inclined to drop out again. Large amount of traffic, huge
> noise-to-signal ratio, cluelessness in abundance and a fair proportion
> of abuse - these all add up to somewhere that I'm not feeling like
> hanging round in.
Sometimes I feel the same way. Other times I feel this whole thing is
too amusing to miss :)
> Is it always like this, or have I picked a bad time?
It has been like that for some time now (at least since I started
reading this newsgroup around a year and a half ago).
> Are there techniques we could use to improve things, like frequently
> posted pointers to FAQs etc... (No, not the whole flaming things - if
> people can read news, surely they can find a web page given a hint)? Or
Such things are being done. The complete FAQs are posted regularly on
this group as well as other welcoming messages and weekly messages
that point to where the docs can be found. A few people bother to check
them out. The majority think that their time is too precious, and that
the others are obliged to answer their questions for free.
> is it simply that Perl attracts a vast number of <insert your
> uncomplementary epithet here>?
That is the main problem. Perl has this image of being "easy" to
learn. This is true, but people abuse it. A lot of people want to use
Perl, but they just don't want to read any documentation first. Many
of them simply post to this newsgroup asking for ways to do very
simple things, like opening files, concatenating strings, rounding
variables, and so on. All of these are addressed completely in the
docs and faqs, but people want to use this newsgroup as a help desk
even if it takes longer for them to get replies than simply searching
through the docs.
In a forum discussing the C language, for example, you wouldn't find
people asking stupid questions (or you wouldn't find as many people, I
should say). This is because people don't think of C as an easy
language to grasp, and reading a book or two on C is the only way to
start learning the language. Mysteriously, a lot of them think of Perl
differently.
Lurk around for a while and see the quality of posts. I would estimate
that less than 10% of the posts here are legitimate questions that are
not answered directly in the docs and FAQs. Note, then, that such
questions are answered in a polite, helpful manner simply because the
original poster deserves the help s/he is seeking.
> Mark Bluemel
> Not yet a Perl hacker
Welcome to the club :)
--Ala
------------------------------
Date: Fri, 29 Oct 1999 14:44:22 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: It is always like this here?
Message-Id: <381A1536.AD6263E6@mail.cor.epa.gov>
Chuck Williams wrote:
>
> Chris,
>
> No offense to this great group, but I wouldn't DREAM of trying to learn
> Perl here.
None taken. A rational point of view. This group is not good
at hand-holding, as you have noticed.
But it is an excellent place to hone one's skills. I see that
I learned more about OOP in Perl from reading this newsgroup
[including TomC's posts here in that] then from any other
single source. Some people find Abigail terse and abrasive, but
I have learned a lot from studying Abigail's denser posts.
> Personally, about 11 months ago I set about learning Perl
> and just 12 weeks ago I felt confident enough to get regularly involved
> in comp.lang.perl.misc
I started learning Perl more than four years ago. I only became
active here less than one year ago. Clearly, you're braver
than I. :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 29 Oct 1999 14:52:20 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: It is always like this here?
Message-Id: <381A1714.3E647F84@mail.cor.epa.gov>
Jeff Boes wrote:
>
> In article <000b8d9b.40a12527@usw-ex0101-001.remarq.com>,
> Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid> wrote:
> >
> > Is it always like this, or have I picked a bad time?
[snip]
> Additionally, everybody and his sister seem to be trying to put
> together an e-commerce site with a shopping cart and a counter and a
> search page and a ... All these folks are "self taught" on HTML, and
> maybe even know a bit of Javascript, how to chmod something after they
> FTP it, etc. Now they're ready to take the next step into this rocket-
> fueled CGI stuff they've heard about, and Perl seems to be the tool of
> choice.
So this means that there is a lot of traffic from people with
no real comp-sci training, and often their questions have
deep implications. Something like "how do I write a webcrawler
like the one Yahoo has?" involves a large number of complex
issues which may never have occurred to the poster.
> So we get a lot of questions here from people writing their first line
> of Perl code (for various reasons) and from people who confuse CGI
> questions with Perl questions.
Or HTML questions. Or HTTP questions. Or webserver config
questions. Or OS questions. Or networking questions. Or
protocol questions. Or....
> Personally, I find the attitudes of the newcomers flat out
> amazing. "Why is this stuff so hard? Why can't I get a 25 word answer?"
Because they have no experience. They may not be clueless,
but they are not well-informed. Some of them will become
informed, while others only demand spoon-feeding.. to the
irritation of regular posters.
['nother snip]
> > Are there techniques we could use to improve things, like frequently
> > posted pointers to FAQs etc... (No, not the whole flaming things - if
> > people can read news, surely they can find a web page given a hint)?
> Or
> > is it simply that Perl attracts a vast number of <insert your
> > uncomplementary epithet here>?
>
> There are in fact paragraphs from the FAQ auto-posted here (take a look
> at the subject headers and you'll spot 3-6 of them newly posted every
> day), and a few of the long-time denizens appear to have adopted some
> kind of boilerplate response ("It appears you are asking a CGI
> question, why don't you go to comp.infosystems.www.authoring.cgi?"), so
> one can hope that the S/N ratio improves.
It doesn't. And I predict that on 12/31/99 and for the following
month it will be a lot worse.
> Personally, I skim this
> newsgroup once a day, never expecting to find too much of use to me but
> it's worth the 20 mins I give it. I keep hoping
> for 'comp.lang.perl.novice' or something to draw off the newbies...
Unfortunately, Usenet experience shows that comp.lang.perl.novice
won't work. Ever heard of comp.unix.wizards ? If you know what
happened there, then you need not wonder about the utility
of a comp.lang.perl.experts-only or a comp.lang.perl.novice
group. <sigh>
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 29 Oct 1999 16:54:20 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: It is always like this here?
Message-Id: <slrn81k5rc.66b.abigail@alexandra.delanet.com>
Mark Bluemel (mark.bluemelNOmaSPAM@siemens.co.uk.invalid) wrote on MMCCL
September MCMXCIII in <URL:news:000b8d9b.40a12527@usw-ex0101-001.remarq.com>:
##
## Are there techniques we could use to improve things, like frequently
## posted pointers to FAQs etc... (No, not the whole flaming things - if
## people can read news, surely they can find a web page given a hint)? Or
## is it simply that Perl attracts a vast number of <insert your
## uncomplementary epithet here>?
If you would have waited a day or so longer before you started complaining
you would have see the pointer to the FAQs posted here. There's a twice
a week message from Gnat, and a once a week message from Tom.
Putting FAQs on webpages would be wrong - usenet doesn't mean access to
"the web". Luckely, Perl *comes* with the FAQ. It's right there, on your
hard drive.
Abigail
--
perl -e 'for (s??4a75737420616e6f74686572205065726c204861636b65720as?;??;??)
{s?(..)s\??qq \?print chr 0x$1 and q ss\??excess}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Fri, 29 Oct 1999 15:01:50 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: It is always like this here?
Message-Id: <381A194E.B7C981E0@mail.cor.epa.gov>
Ala Qumsieh wrote:
> Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid> writes:
[snip]
> Sometimes I feel the same way. Other times I feel this whole thing is
> too amusing to miss :)
Ditto. Sometimes I just want to light up the Greek fire and
wind up the catapult. Sometimes I wince at the newbie-abuse.
Most of the time I just try to be the playground monitor.
That way, *everyone* can be ticked at me. :-)
> > Is it always like this, or have I picked a bad time?
>
> It has been like that for some time now (at least since I started
> reading this newsgroup around a year and a half ago).
It's been like that for years. It went to pot when AOL let
*anyone* leap into Usenet newsgroups with no inkling that
they were entering another culture, with its own rules. Or
even that this wasn't one more chat room.
Now the Net permits people to go here from Deja.com and
similar places without any idea of what they are finding.
We had a person asking Python questions this summer, because
Deja's search facility directed him here. He had no idea
he was in a Perl newsgroup.
> > Are there techniques we could use to improve things, like frequently
> > posted pointers to FAQs etc... (No, not the whole flaming things - if
> > people can read news, surely they can find a web page given a hint)? Or
>
> Such things are being done. The complete FAQs are posted regularly on
> this group as well as other welcoming messages and weekly messages
> that point to where the docs can be found. A few people bother to check
> them out. The majority think that their time is too precious, and that
> the others are obliged to answer their questions for free.
Many simply are not reading the newsgroup, but leaping in
unprepared, often from search facilities which do not help
them know about the milieu they will enter. These people
have no way of knowing that this group has expectations
and a FAQ and on-line docs.
> > is it simply that Perl attracts a vast number of <insert your
> > uncomplementary epithet here>?
[snip of rational discussion]
Yes. Perl attracts everything. This is not a gold mine.
It is a diamond mine. You can find diamonds in the rough,
or neat-but-bizarre formations, or lots of breccia. And
everyone wants in, hoping to snatch that big gem before
they have to do any work.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 29 Oct 1999 15:04:35 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: It is always like this here?
Message-Id: <381A19F3.6041D20A@mail.cor.epa.gov>
William wrote:
>
> Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid> wrote
[snip]
> > Is it always like this, or have I picked a bad time?
>
> Seems to be the worst in purely language-related newsgroups.
> I've found that, while the cluelessness is just as high,
> the newbie-toasting is less pronounced in newsgroups
> devoted to creating applications. Don't know why,
> just my observation.-Wm
I find that the cluelessness in the app-creation newsgroups
is about as bad, but most of it is on-target. The poster is
in the right newsgroup, and is asking a nearly-relevant
question. You cannot count on either of those here, and
the people who ask in the wrong newsgroup are often unwilling
to take advice which runs counter to their [incorrect]
guess. This leads to bad behavior all around.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 29 Oct 1999 12:54:45 -0700
From: Patrick McCormick <patrick@meer.net>
Subject: memory handling in perlguts
Message-Id: <3819FB85.FE94432B@meer.net>
I am binding a set of C functions to perl, and I'm not clear on who is
responsible for freeing memory.
For example, in my C glue code (generated by SWIG), I have:
sv_setpv((SV*)ST(argvi++),(char *) _result);
where _result is passed in by the caller.
Is the caller responsible for freeing space used by _result? Or does
perl's garbage collector call libc free() when the refcount on the SV
goes to zero? Is there a special perl malloc() I should use to allocate
memory for _result? What if _result is a static character array?
I read the perlguts manpage, but I didn't see anything about memory
management.
(this is the kind of question that reminds me why I want to use perl in
the first place.)
Thanks for any help.
--Patrick
patrick@meer.net
------------------------------
Date: 29 Oct 1999 21:57:13 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: memory handling in perlguts
Message-Id: <7vd57p$rcq$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Patrick McCormick
<patrick@meer.net>],
who wrote in article <3819FB85.FE94432B@meer.net>:
> I am binding a set of C functions to perl, and I'm not clear on who is
> responsible for freeing memory.
>
> For example, in my C glue code (generated by SWIG), I have:
>
> sv_setpv((SV*)ST(argvi++),(char *) _result);
>
> where _result is passed in by the caller.
>
> Is the caller responsible for freeing space used by _result? Or does
> perl's garbage collector call libc free() when the refcount on the SV
> goes to zero?
There is no such thing as "perl's garbage collector". Otherwise: IIRC
all the Perl API calls (except sv_usepv) copy the string arguments.
Ilya
------------------------------
Date: Fri, 29 Oct 1999 15:52:05 -0400
From: "Dutch McElvy" <dutch@mindspring.com>
Subject: Need help fixing this multi-file ftp script
Message-Id: <7vcte3$e30$1@nntp3.atl.mindspring.net>
I am trying to use the following script to ftp all files contained in a
certain directory and at the same time rename each file being sent to the
remote machine and place it in its own directory according to a portion of
the orginal file name. The orginal filenames are unknown but would all
follow the "$_" pattern below.
The ftp does not fail but reads only as an array on the remote machine also
even though the script does not fail the -w gets an unitialized value for
$newname and $newdir.
Thanks for any ideas.
#!/usr/bin/perl -w
#Main program
use Net::FTP;
$ftp = Net::FTP->new("somemachine.com.somewhere");
$ftp->login("usr",'passwd');
$ftp->binary;
$ftp->cwd("/somedir");
rename();
$ftp->quit;
sub rename {
$dir = "/somedir";
opendir(DIR, $dir ) || die "can't opendir $dir: $!";
(@filenames, $newname, $newdir) = readdir(DIR);
closedir DIR;
foreach ( @filenames ) {
$_ =~ s/(...)(.......)(.....)(....)(...........)/$1$2$3$4$5/;
$newname .= "$2$3";
$newdir = "$1"; #Coult be different for each file
}
$ftp->put("$newdir/$newname") or die "Could not ftp";
}
------------------------------
Date: Fri, 29 Oct 1999 14:15:12 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Pack function in Active Perl (win32) buggy?
Message-Id: <381A0E60.72449D95@mail.cor.epa.gov>
Lars Soderstrom wrote:
>
> Ok, this is the code I have used:
>
> $fields[$j] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
>
> this is to convert the different parts of a command string, received from a
> html-form with get-method, to a readable&printable string.
You might want to try something more like what is suggested
in the FAQ, or else let CGI.pm or URI::Escape do the work
for you. Your code might look and work a bit better with
something more like:
$fields[$j] =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge;
Does this help clear up your problem?
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 29 Oct 1999 15:09:45 -0500
From: "Steve S." <SteveS@HTProf.com>
Subject: Perl assoc. array file database error... help please
Message-Id: <7vcrei$53t$1@nntp6.atl.mindspring.net>
I'm currently creating a web based database from pages we have on our
website... I'm using the dbmopen method and was extremely happy with my
results from my testing up until I started testing with our actual pages
from our site. If I try adding a string longer than about 1000 characters I
get this message:
Length of string being added = 1008
sdbm store returned -1, errno 22, key "key" at addthedb.pl line 39, <STDIN>
chunk 1.
Is there any way past this limitation? or do I have to add these strings
into a seperate txt delimited database file? Thank you all, for any help at
all. SteveS
------------------------------
Date: Fri, 29 Oct 1999 21:16:37 GMT
From: Mike Sosteric <mikes@athabascau.ca>
Subject: perl safe_mysqld
Message-Id: <r9idg8sx.fsf@edlo1.ab.wave.home.com>
I have a problem which is probably easy. I have a perl script that tests to see
if the mysqld is running on the system (uses DBI to connect). If no handle
is returned, we start iterating through a number of strategies to start the daemon. Problem is,
I find mysql and try to start it, but the the perl script hangs because safe_mysqld does not return.
i've tried all manner of permutations
exec("mysqld")
exec("safe_mysqld")
exec("safe_mysqld &")
system("mysqld &")
system("mysqld")
`mysqld`
`safe_mysqld`;
open (PS, "| safe_mysqld &|);
nothing works though and the perl script just hangs. Anyone got an answer?
tia
--
Mike Sosteric <mikes@athabascau.ca> Editor, EJS <http://www.sociology.org/>
Department of Global and Social Analysis Executive Director, ICAAP <http://www.icaap.org/>
Department of Educational Technology Athabasca University
--
This troubled planet is a place of the most violent contrasts.
Those that receive the rewards are totally separated from those who
shoulder the burdens. It is not a wise leadership - Spock, "The Cloud Minders."
------------------------------
Date: Fri, 29 Oct 1999 12:23:34 -0700
From: mbudash@wcws.com (Michael Budash)
Subject: Re: Reading a file backwards?
Message-Id: <mbudash-2910991223340001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <3819D911.7671A5BB@netscape.com>, Jacob Rosenschein
<koby@netscape.com> wrote:
> Can I read a file, line by line, beginning with the last line and moving
> upward towards the beginning of the file? If so, how would I do this in
> Perl?
>
> Thanks,
> Koby Rosenschein (a newbie)
if memory usage isn't a problem, here's one way:
open (FILE, $file) or die ("Can't open $file: $!");
@FILE=<FILE>; # slurp
close (FILE);
foreach (reverse (@FILE)) {
# do something with $_
}
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@wcws.com
------------------------------
Date: Fri, 29 Oct 1999 19:35:59 GMT
From: James Tolley <jtolley@bellatlantic.net>
Subject: Re: Reading a file backwards?
Message-Id: <3819F6A0.9CB2F940@bellatlantic.net>
Jacob Rosenschein wrote:
> Can I read a file, line by line, beginning with the last line and moving
> upward towards the beginning of the file?
open(FILE,"test.txt") or die $!;
for my $line (reverse <FILE>) {
&do_something($line);
}
hth,
James
------------------------------
Date: Fri, 29 Oct 1999 16:45:55 -0400
From: Vinodh R Cuppu <ramvinod@eng.umd.edu>
Subject: Re: Reading a file backwards?
Message-Id: <381A0783.8736FAAF@eng.umd.edu>
> Can I read a file, line by line, beginning with the last line and moving
> upward towards the beginning of the file? If so, how would I do this in
> Perl?
>
use, "seek FILEHANDLE,POSITION,WHENCE", where POSITION can be negative
counter and WHENCE is 2 for setting a position from the EOF. so something
like seek MYFILE, -1, 2 should set it to the last line of the file.
check out 'perldoc -f seek", for exact details.
Cheers
Vinod
------------------------------
Date: Fri, 29 Oct 1999 13:45:09 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading a file backwards?
Message-Id: <MPG.1283a734cdc908f298a15f@nntp.hpl.hp.com>
In article <3819D911.7671A5BB@netscape.com> on Fri, 29 Oct 1999 10:27:45
-0700, Jacob Rosenschein <koby@netscape.com> says...
> Can I read a file, line by line, beginning with the last line and moving
> upward towards the beginning of the file? If so, how would I do this in
> Perl?
The Perl Cookbook, Recipe 8.4: "Reading a File Backwards by Line or
Paragraph"
Also, search this newsgroup using Deja.com for 'backward' or
'backwards'. The subject has been discussed many times.
If the file is small enough to fit comfortably in memory, just read it
all in and use the reverse() function. `perldoc -f reverse`
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 29 Oct 1999 18:00:35 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading a file backwards?
Message-Id: <x7r9idddz0.fsf@home.sysarch.com>
>>>>> "VRC" == Vinodh R Cuppu <ramvinod@eng.umd.edu> writes:
>> Can I read a file, line by line, beginning with the last line and moving
>> upward towards the beginning of the file? If so, how would I do this in
>> Perl?
>>
VRC> use, "seek FILEHANDLE,POSITION,WHENCE", where POSITION can be negative
VRC> counter and WHENCE is 2 for setting a position from the EOF. so something
VRC> like seek MYFILE, -1, 2 should set it to the last line of the file.
sorry, but very wrong. how would seek know the length of the last line?
you just seeked to the last char before EOF which is not useful.
anyhow i was going to stay out this thread but i do have a module (i
gotta get it to cpan already) that does this for you. it is linked from
my site (below) and called Backwards.pm.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 29 Oct 1999 14:21:07 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Reinventing the wheel
Message-Id: <381A0FC3.4D614037@mail.cor.epa.gov>
david.lane@mantech.com wrote:
>
> Greetings,
and felicitations.
[snip of problem description]
> I can get as far as the regex to pull out the directory name and put
> that in a variable for appending, but I cannot skip or get rid of the
> next two lines. With 500 pages of this stuff to sort through, I really
> want to do this in an automated fashion.
An easy way to do this if you're reading your file line-by-line
[lets say for illustration that you have your filehandle in
FILE and are reading lines using <FILE> ] is to throw away
those next two lines. If you're doing this sequentially, you
could just say <FILE> twice and pull those lines out of the way.
Or you could use the structure of the data and say something like:
next if /^Files/;
next if /^-{17}/;
and skip over lines of that form.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 29 Oct 1999 13:21:22 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: simplifying a script
Message-Id: <MPG.1283a19e404a59b198a15e@nntp.hpl.hp.com>
In article <Pine.GSO.4.10.9910291457220.2694-100000@crusoe.crusoe.net>
on Fri, 29 Oct 1999 14:57:42 -0400, Jeff Pinyan <jeffp@crusoe.net>
says...
> > I will use arrays! Just have to read further in my Perl for Dummies-book...
>
> NO!!!!!! NOT THAT BOOK!
Reviewed by Mark-Jason Dominus in the current Perl Journal, #15, p. 40.
"I wanted to like this book. I really did, and I tried hard. ... But I
read it and was appalled. ..."
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 29 Oct 1999 14:29:25 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: simplifying a script
Message-Id: <381A11B5.6C6CB250@mail.cor.epa.gov>
Walter van den Berg wrote:
>
> Greg Bacon writes:
> > my @table;
> >
> > foreach my $file (@table_data) {
> > local $/;
> > open TD, $file or die "$0: open $file: $!";
> > push @table, { file => $file, data => <TD> };
> > close TD;
> > }
> Hm, Greg? It doesn't work with me... I'm just a beginner, but I think it's
> because the handle TD doesn't have a value yet. Could that be?
> (I'm working with windows, but that doesn't make a difference, does it?)
No, it's not Microsoft Windows. Greg was just assuming you
would stick the list of filenames into the array @table_data
first. He did put an ellipsis before and after his snippet,
indicating that there was more needed in both places. But
his intent may not have been clear.
And please, don't go by "Perl for Dummies", unless someone
is holding your family hostage or something. It doesn't
explain as well as an intro book should, and it seems to
want to make you afraid to program. Try this web tutorial
instead:
http://www.netcat.co.uk/rob/perl/win32perltut.html
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 29 Oct 1999 16:26:36 -0400
From: Jing Shi <Jing.Shi@usa.alcatel.com>
Subject: string number conversion
Message-Id: <381A02FC.191D55FE@usa.alcatel.com>
I have a string, $a = 4 2/5
How can I convert to the number 4.4?
Thanks
------------------------------
Date: Fri, 29 Oct 1999 20:56:04 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: string number conversion
Message-Id: <slrn81k2oe.las.bmccoy@moebius.foiservices.com>
Also Sprach Jing Shi <Jing.Shi@usa.alcatel.com>:
>I have a string, $a = 4 2/5
>How can I convert to the number 4.4?
Try this:
#!/usr/bin/perl -w
use strict;
sub frac2dec {
my $fracnum = shift;
(my $int, my $frac) = split(' ', $fracnum);
my $decimal = eval $frac;
return $int + $decimal;
}
print frac2dec('4 2/5');
--
Brett W. McCoy bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek) http://www.foiservices.com
FOI Services, Inc./DIOGENES 301-975-0110
---------------------------------------------------------------------------
------------------------------
Date: Fri, 29 Oct 1999 14:55:15 -0700
From: duane powell <duane@blur.com>
Subject: What's an elegant way to populate an array with method refs?
Message-Id: <381A17C3.DA56AD15@blur.com>
What's an elegant way to populate an array with method refs? Something
better than below? I am asking because ultimately I want to expose
methods of my classes based on user access rights. Thanks, Duane
package MyClass;
use Strict;
sub new {
my($proto) = @_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{MY_METHODS} = [];
bless($self, $class);
return $self;
}
sub someMethod {
my $self = shift;
}
sub someOtherMethod {
my $self = shift;
}
sub getMethods {
my $self = shift;
$self->{MY_METHODS} = undef;
push @{ $self->{MY_METHODS} }, \$self->someMethod();
push @{ $self->{MY_METHODS} }, \$self->someOtherMethod();
$self->{MY_METHODS};
}
1;
------------------------------
Date: Fri, 29 Oct 1999 19:55:03 GMT
From: jmonroe.easystreet@com.spam.sucks.my.ass.com (Jon)
Subject: Re: Why extra junk at end of new file? Not anymore!! :)
Message-Id: <3819f9f5.62352978@news.easystreet.com>
On Wed, 27 Oct 1999 19:55:08 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:
>I encourage you to try again to cut down the code to a manageable example.
>The error will probably become apparent along the way.
>
>Good luck!
Hmm... well, that's sort of what I ended up doing -- didn't even need
the debugger. Turned out that I was accidentally opening the file
twice. The first time it was supposed be opened, but the second open
was supposed to be a different month/year file. Instead, the file was
being opened again, then written to, then closed after the first file
was written but BEFORE the first open was closed.
Turns out I subtracted one from a number at the wrong place and it
messed the whole thing up... doh!
Thanks for everyone's help!
Jon
------------------------------
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 1224
**************************************