[17809] in Perl-Users-Digest
Perl-Users Digest, Issue: 5229 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 4 16:16:20 2001
Date: Thu, 4 Jan 2001 13:15:59 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978642959-v9-i5229@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 4 Jan 2001 Volume: 9 Number: 5229
Today's topics:
file open +append <jhall@ifxonline.com>
Re: file open +append <joe+usenet@sunstarsys.com>
Re: file open +append (Abigail)
Re: file open +append <flavell@mail.cern.ch>
Files in Perl <vidulats@yahoo.co.uk>
Re: Files in Perl <lauren_smith13@hotmail.com>
Re: Files in Perl (Abigail)
Re: Files in Perl grishaa@my-deja.com
Re: Files in Perl grishaa@my-deja.com
finding the filesize of a remote (http://) file? (Michael Friendly)
Re: finding the filesize of a remote (http://) file? <Peter.Dintelmann@dresdner-bank.com>
Re: flat file database question <waltman@netaxs.com>
Follow-up <mark@marknw.com>
Re: Follow-up (Tad McClellan)
fork() and waitpid() question <davesisk@ipass.net>
Re: fork() and waitpid() question <uri@sysarch.com>
formated regex tunneling@my-deja.com
Re: formated regex <mischief@velma.motion.net>
General Personal Development Strategy <jhall@ifxonline.com>
Re: General Personal Development Strategy (Steven Smolinski)
Re: General Personal Development Strategy (Martien Verbruggen)
Re: General Personal Development Strategy (Abigail)
Re: General Personal Development Strategy <jhall@ifxonline.com>
Get arbitrary number of random lines from a file neil@brevity.org
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Dec 2000 17:53:19 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: file open +append
Message-Id: <jc436.103765$I5.2533066@news1.rdc1.sdca.home.com>
This doesn't work:
_____________________________________
open(HISTORY,"+>>$histFile");
@histList=<HISTORY>;
_____________________________________
So I have to do this:
_____________________________________
open(HISTORY,"$histFile");
@histList=<HISTORY>;
close(HISTORY);
open(HISTORY,">>$histFile");
_____________________________________
Any shortcuts? Thanks!
http://moron.shutdown.com
------------------------------
Date: 29 Dec 2000 13:34:44 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: file open +append
Message-Id: <m3vgs36pq3.fsf@mumonkan.sunstarsys.com>
"John Hall" <jhall@ifxonline.com> writes:
> This doesn't work:
Sure it does:
> open(HISTORY,"+>>$histFile");
^^ ^^^^^^^^^^^
or die $!;
file position (cursor) is at EOF - nothing left
to read,
> @histList=<HISTORY>;
hence @histList is empty.
> So I have to do this:
% perldoc -f open
% perldoc -q open
and use "non-destructive version" of O_RDWR:
open HISTORY, "+<$histFile" or die $!;
@histList = <HISTORY>; # reads lines into @histList
# cursor at EOF now, can append
HTH.
--
Joe Schaefer
------------------------------
Date: 30 Dec 2000 16:08:37 GMT
From: abigail@foad.org (Abigail)
Subject: Re: file open +append
Message-Id: <slrn94s245.8df.abigail@tsathoggua.rlyeh.net>
John Hall (jhall@ifxonline.com) wrote on MMDCLXXVII September MCMXCIII in
<URL:news:jc436.103765$I5.2533066@news1.rdc1.sdca.home.com>:
&&
&& This doesn't work:
&& _____________________________________
&& open(HISTORY,"+>>$histFile");
&&
&& @histList=<HISTORY>;
&&
&& _____________________________________
Bzzzt. Wrong. Thanks you for playing.
Of course it "works". It just does something else that you expect it
to do. You open something for append, so your seek pointer is at the
end of the file. Guess how many lines follow?
&& So I have to do this:
No you don't. You just have to seek. Or, if you are going to read
first, then write afterwards, just open the file for read/write,
using +<, read, then write.
Abigail
--
print v74.117.115.116.32;
print v97.110.111.116.104.101.114.32;
print v80.101.114.108.32;
print v72.97.99.107.101.114.10;
------------------------------
Date: Sat, 30 Dec 2000 18:23:11 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: file open +append
Message-Id: <Pine.LNX.4.30.0012301807560.5630-100000@lxplus003.cern.ch>
On 30 Dec 2000, Abigail wrote:
> && open(HISTORY,"+>>$histFile");
[...]
> Of course it "works". It just does something else that you expect it
> to do. You open something for append, so your seek pointer is at the
> end of the file. Guess how many lines follow?
>
> && So I have to do this:
>
> No you don't. You just have to seek.
Indeed. And if you do it that way, the scheme can be self-starting,
since if the file doesn't yet exist, then +>> will be happy to create
it for you - and in such a fashion that file locking is usable, no?
> Or, if you are going to read
> first, then write afterwards, just open the file for read/write,
> using +<, read, then write.
Yup, but in this case you'd have to seed the process by creating the
file (maybe empty, depending on your requirements) beforehand, right?
If this is being done in a situation where multiple processes might be
contending for the file, it's harder to make it self-starting, because
there isn't an atomic way of testing for, and if necessary creating,
the file before locking it.
So, for that one could either use an auxiliary locking-file (which is
messy); or you might decide to try a sysopen with the O_RDWR and
O_CREAT bits set - but as I understand it, this isn't as portable...?
Comments, insights, please? I seem to have made this work for me (by
appropriate reference to perldoc perlopentut and so on), but I'm still
sufficiently vague about some of the details (especially portability)
that further guidance is entirely welcome.
cheers
------------------------------
Date: Thu, 04 Jan 2001 05:30:13 -0000
From: <vidulats@yahoo.co.uk>
Subject: Files in Perl
Message-Id: <t582j56ukca066@corp.supernews.com>
Hello,
I want to modify the contents of the file.
The file which I want to modify is a another Perl file. I'm displaying the
contents of that file where the variable declaration is there line by line
and I'm giving a flexibility to the user to change the values of the
variables.
If my line no 5 is:
$x = 10;
If the user enter 20 then, I want to change the contents of line number 5
to:
$x = 20;
I tried to open the file with ">>", "+>", "<<", but its not working.
Without using another file as a temporary file, I want to modify the file.
Will any one help me please.
Thanks in advance,
Regards,
Vidula
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Thu, 04 Jan 2001 06:51:48 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Files in Perl
Message-Id: <74V46.1740$6F6.588429@paloalto-snr1.gtei.net>
<vidulats@yahoo.co.uk> wrote in message
news:t582j56ukca066@corp.supernews.com...
> Hello,
>
> I want to modify the contents of the file.
>
> The file which I want to modify is a another Perl file. I'm displaying
the
> contents of that file where the variable declaration is there line by
line
> and I'm giving a flexibility to the user to change the values of the
> variables.
>
> If my line no 5 is:
> $x = 10;
>
> If the user enter 20 then, I want to change the contents of line
number 5
> to:
> $x = 20;
It sounds like you want to do what is explained in
perlfaq5: 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?
perldoc perlfaq5
Lauren
------------------------------
Date: 4 Jan 2001 15:19:18 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Files in Perl
Message-Id: <slrn95953m.qdu.abigail@tsathoggua.rlyeh.net>
vidulats@yahoo.co.uk (vidulats@yahoo.co.uk) wrote on MMDCLXXXIII
September MCMXCIII in <URL:news:t582j56ukca066@corp.supernews.com>:
<> Hello,
<>
<> I want to modify the contents of the file.
<>
<> The file which I want to modify is a another Perl file. I'm displaying the
<> contents of that file where the variable declaration is there line by line
<> and I'm giving a flexibility to the user to change the values of the
<> variables.
<>
<> If my line no 5 is:
<> $x = 10;
<>
<> If the user enter 20 then, I want to change the contents of line number 5
<> to:
<> $x = 20;
<>
<> I tried to open the file with ">>", "+>", "<<", but its not working.
<> Without using another file as a temporary file, I want to modify the file.
<>
<> Will any one help me please.
It's a FAQ.
If you don't want to use a temporary file, you need to read in the file
and store it into memory.
<> Thanks in advance,
But wouldn't it be much easier to use command line arguments?
Abigail
--
print 74.117.115.116.32, 97.110.111.116.104.101.114.32,
80.101.114.108.32, 72.97.99.107.101.114.10;
------------------------------
Date: Thu, 04 Jan 2001 16:14:50 GMT
From: grishaa@my-deja.com
Subject: Re: Files in Perl
Message-Id: <9327hg$fij$1@nnrp1.deja.com>
In article <t582j56ukca066@corp.supernews.com>,
<vidulats@yahoo.co.uk> wrote:
> Hello,
>
> I want to modify the contents of the file.
>
> The file which I want to modify is a another Perl file. I'm
displaying the
> contents of that file where the variable declaration is there line by
line
> and I'm giving a flexibility to the user to change the values of the
> variables.
>
> If my line no 5 is:
> $x = 10;
>
> If the user enter 20 then, I want to change the contents of line
number 5
> to:
> $x = 20;
>
> I tried to open the file with ">>", "+>", "<<", but its not working.
> Without using another file as a temporary file, I want to modify the
file.
>
> Will any one help me please.
>
> Thanks in advance,
>
> Regards,
> Vidula
>
> --
> Posted via CNET Help.com
> http://www.help.com/
>
In-place editing is what you are looking for. Lookup info on -i command
line option of perl and/or $^I variable.
It should be both in pod and camel book.
HTH
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 04 Jan 2001 17:17:44 GMT
From: grishaa@my-deja.com
Subject: Re: Files in Perl
Message-Id: <932b7d$j5o$1@nnrp1.deja.com>
In article <t582j56ukca066@corp.supernews.com>,
<vidulats@yahoo.co.uk> wrote:
> Hello,
>
> I want to modify the contents of the file.
>
> The file which I want to modify is a another Perl file. I'm
displaying the
> contents of that file where the variable declaration is there line by
line
> and I'm giving a flexibility to the user to change the values of the
> variables.
>
> If my line no 5 is:
> $x = 10;
>
> If the user enter 20 then, I want to change the contents of line
number 5
> to:
> $x = 20;
>
> I tried to open the file with ">>", "+>", "<<", but its not working.
> Without using another file as a temporary file, I want to modify the
file.
>
> Will any one help me please.
>
> Thanks in advance,
>
> Regards,
> Vidula
>
> --
> Posted via CNET Help.com
> http://www.help.com/
>
In-place editing is what you are looking for. Lookup info on -i command
line option of perl and/or $^I variable.
It should be both in pod and camel book.
HTH
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 4 Jan 2001 14:29:29 +0000 (UTC)
From: friendly@hotspur.psych.yorku.ca (Michael Friendly)
Subject: finding the filesize of a remote (http://) file?
Message-Id: <9321c9$7jc$1@sunburst.ccs.yorku.ca>
I'm using some of the code from wwwis to get size info for a database of
images, some local, some on the web, which I need in the form
(120 x 340; 28K)
where the first two are the width and height in pixels. I can't figure out
how to get the file size in bytes, say of a remote (http://) image file.
Any ideas?
thx,
-Michael
--
Michael Friendly Email: friendly@yorku.ca (NeXTmail OK)
Psychology Dept
York University Voice: 416 736-5115 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA
------------------------------
Date: Thu, 4 Jan 2001 16:13:51 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: finding the filesize of a remote (http://) file?
Message-Id: <93240h$9eg2@intranews.bank.dresdner.net>
Hi Michael,
"Michael Friendly" <friendly@hotspur.psych.yorku.ca> wrote in message
news:9321c9$7jc$1@sunburst.ccs.yorku.ca...
> I can't figure out
> how to get the file size in bytes, say of a remote (http://) image file.
have a look at the HTTP headers. A HEAD request for
http://www.perl.com/images/sourceforperl_85.gif yields
e.g.
HTTP/1.1 200 OK
Date: Thu, 04 Jan 2001 15:31:06 GMT
Server: Apache/1.3.12 (Unix) PHP/4.0.1pl2 mod_perl/1.24
Last-modified: Thu, 25 Mar 1999 19:52:01 GMT
Etag: "386bfb-168b-36fa93e1"
Accept-ranges: bytes
Content-length: 5771
Connection: close
Content-type: image/gif
and Content-length is what you are looking for (why is their
server time wrong???).
Regards,
Peter Dintelmann
------------------------------
Date: 29 Dec 2000 12:41:27 -0500
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: flat file database question
Message-Id: <87ofxvm8fs.fsf@netaxs.com>
Bart Lateur <bart.lateur@skynet.be> writes:
> Gregory Spath wrote:
>
> >IIRC, there is a DBI module that allows use of flat files. Check out
> >CPAN.
>
> There's even more than one.
>
> * DBD::CSV
>
> * DBD::RAM
>
> * DBD::Sprite
And you're probably much better off using one of these instead of
writing your own. If nothing else, should you ever upgrade to a real
DBMS the porting process should be relatively trivial.
Walt
------------------------------
Date: Tue, 2 Jan 2001 05:00:24 -0800
From: "Mark@MarkNW.com" <mark@marknw.com>
Subject: Follow-up
Message-Id: <rgk46.7331$Uv2.1477342@nntp2.onemain.com>
For those of you that offered help, I thought I'd add a short post-- Thanks.
It's a PERL thanks, so it's not off topic. Rewrote as Uri suggested and
dropped the 'die "<HTML... stuff and it works.
Mark
------------------------------
Date: Tue, 2 Jan 2001 07:30:29 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Follow-up
Message-Id: <slrn953if5.e6p.tadmc@magna.metronet.com>
Mark@MarkNW.com <mark@marknw.com> wrote:
>For those of you that offered help, I thought I'd add a short post-- Thanks.
You have done it wrong though. Please don't break stuff like that.
1) If this is in reference to some post you have made here, then
the ID of the previous post should be in a References: header.
(your software should do this automatically when you do a
followup)
This post does not have that header. You started an entirely
new thread instead of posting it in the thread that you
are talking about.
2) You did not put a subject in your Subject header. Most posts
(a hundred or more) are "Follow-ups". Your Subject adds no
useful information, neither did the subject for your original post.
For more info on choosing a Subject so as to increase your
chances of getting folks to open and read it, see:
http://www.perl.com/CPAN-local/authors/Dean_Roehrich/subjects.post
Due the above, it is quite possible (likely even) that the people
you are trying to thank will never even see your message.
Please learn how to post properly if you plan to post to Usenet.
>It's a PERL thanks, so it's not off topic.
No, it is a "Perl thanks" or a "perl thanks", not a PERL thanks :-)
Perl FAQ, part 1:
"What's the difference between "perl" and "Perl"?"
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 03 Jan 2001 18:52:38 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: fork() and waitpid() question
Message-Id: <WxK46.76493$sr6.13520546@typhoon.southeast.rr.com>
OK, I've found an example of how to fork() one child process and waitpid()
for it to complete. Now, how do fork() 3 child processes, and waitpid() (or
wait()) for all 3 to complete before the parent proceeds? If you have an
example or know where I can find an example, please post or email!
Best regards,
Dave
------------------------------
Date: Wed, 03 Jan 2001 20:51:28 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: fork() and waitpid() question
Message-Id: <x7k88c8ilr.fsf@home.sysarch.com>
>>>>> "DS" == David Sisk <davesisk@ipass.net> writes:
DS> OK, I've found an example of how to fork() one child process and
DS> waitpid() for it to complete. Now, how do fork() 3 child
DS> processes, and waitpid() (or wait()) for all 3 to complete before
DS> the parent proceeds? If you have an example or know where I can
DS> find an example, please post or email!
the perl cookbook has examples of forking servers
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: Thu, 04 Jan 2001 14:53:06 GMT
From: tunneling@my-deja.com
Subject: formated regex
Message-Id: <9322oe$aq6$1@nnrp1.deja.com>
Here is what I am trying to achieve:
Starting with:
t=r1233
t=r1
t=r159
t=rd22
t=r1000
After the // I would like to see the following results:
t=r100
t=r101
t=r102
t=rd22
t=r103
Where my // searchs for t=r(any digit) and begins numbering these
occurences with a 3-digit number. I realized I can initialize my count
variable to 100(just now) however, since I have written this much thus
far, I would like to know how to format a variable. I have read about
formating the STDOUT and outputing a format to a file. Is there a simple
way to format a variable?
I am using:
if (s/t=r(\S*)/t=1$count/ig) {
$count++;
}
With this I get:
t=r1
t=r11
t=r12
t=rd22
t=r13
Thanks in advance for any offerings.
Tunneling
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 04 Jan 2001 16:26:46 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: formated regex
Message-Id: <t59926dqqti4bf@corp.supernews.com>
tunneling@my-deja.com wrote:
> Here is what I am trying to achieve:
> Starting with:
> t=r1233
> t=r1
> t=r159
> t=rd22
> t=r1000
> After the // I would like to see the following results:
> t=r100
> t=r101
> t=r102
> t=rd22
> t=r103
> Where my // searchs for t=r(any digit) and begins numbering these
> occurences with a 3-digit number. I realized I can initialize my count
> variable to 100(just now) however, since I have written this much thus
> far, I would like to know how to format a variable. I have read about
> formating the STDOUT and outputing a format to a file. Is there a simple
> way to format a variable?
You can use sprintf() pretty much the same as printf(), except that it
returns the value instead of sending it to STDOUT. perldoc -f sprintf
> I am using:
> if (s/t=r(\S*)/t=1$count/ig) {
> $count++;
> }
Assuming you really want a 1 to always be the first digit and $count
to be just the last two digits, needing a zero padding, you could do
something like this:
$count = 0;
while(<>) {
if( m/t=r\d+/ ) {
$count++;
}
$count = sprintf('%02d', $count);
s/t=r\d+/t=r1$count/;
print "$_";
}
This will work line by line and will change only those lines
where the t=r is immediately followed by only digits. Everything
else remains the same.
Using the \d+ in the match makes sure you only match digits.
perldoc perlre
If you really have the exact data you show, with everything lower
case and only one substitution per line, and you are working a line
at a time, then both the /i and the /g modifiers are superfluous.
perldoc perlop
I'm not sure why you have an if(){} in your code.
> With this I get:
> t=r1
> t=r11
> t=r12
> t=rd22
> t=r13
> Thanks in advance for any offerings.
You're welcome.
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Thu, 04 Jan 2001 01:29:53 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: General Personal Development Strategy
Message-Id: <lmQ46.130526$I5.3269544@news1.rdc1.sdca.home.com>
I see a lot of "you work stupid" and "RTFM" on this list.
I am curious if someone can give me a more constructive method/procedure for
figuring out ways of writing perl code.
Case in point:
I have been programming for ~2 weeks. Prior to my extensive career as a perl
coder, over the past few months, I had used inductive reasoning to hack up a
few existing perl scripts based on trial and error and my existing knowledge
of HTML. Because of a new [much larger] project I was assigned I spent a day
reading an excellent beginner's perl tutorial at
http://www.perl.com/pub/2000/10/begperl1.html and buying a _not so
excellent_ perl book. "Perl 5.0 CGI Web Pages".
I needed to figure out how to spit out a date gleaned from localtime() and
make sure it always had a 2 digit length. [IE 09 instead of 9 for september,
after adding 1 of course]
I read perldoc -f localtime, which didn't address my issue [as far as I can
tell? It only showed me a few pages of stuff I had already gleaned from
looking at another piece of code] And I didn't know about the function
printf, or to search for something like "format specifier" - so I wrote a
nasty subroutine that checked the number of digits and padded a prepending 0
if the result was 1.
Of course I am interested in learning the "right way", so I read everything
on this list that I can understand.
In a nutshell, how do I get from "I need this data to print out always as 2
characters" to "perldoc -f printf" - What tools did you people use when you
were starting out? Will the fact that I don't know C cripple me? [I notice a
lot of things in perldoc say 'similar to how it's done in C']. Are there any
preferred sites that have useable search features, that will work for me as
I am developing an understanding of the terminology?
I have an outdated manual bookmarked at
http://www-cgi.cs.cmu.edu/cgi-bin/perl-man but I can't find the perl5
version; something like that would probably help me more than 100 people
saying "perldoc -f
thsfunctionthatialreadyknewaboutandiamjustusingperldoctoseehowthesyntaxworks
!"
Thanks in advance.
------------------------------
Date: Thu, 04 Jan 2001 03:59:41 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: General Personal Development Strategy
Message-Id: <slrn958182.2t8.sjs@ragnar.stevens.gulch>
John Hall <jhall@ifxonline.com> wrote:
> I see a lot of "you work stupid" and "RTFM" on this list.
You see a lot of people post on this newsgroup who, from a programmer's
point of view, are working stupidly; e.g., not reading the manual of the
tool they're using.
And get a thick skin; learn to take correction. For example, this isn't
a "list," but a newsgroup. See? That wasn't so bad.
> I am curious if someone can give me a more constructive method/procedure for
> figuring out ways of writing perl code.
[... snip "where do I start?" story ...]
Here's what I always do for learning anything in the realm of technology:
1) STFW. Read through the newsgroups, FAQs, etc. to find the most
authoratative books on the subject. Go buy [one|two|three] of them.[1]
2) Read the book(s). Over and over if must be. Practice all the while.
3) Read the newsgroups/websites of the online community for
idioms/shortcuts/best practices. This is dangerous considering the
crap out there, [2] so one must use one's best judgment.
Plus, most of the books/FAQs for Perl properly explain that the most
up-to-date, voluminous, and complete documentation one could ever wish
for is *installed right on the computer* when perl is installed.
Don't just grep through these docs when you have an issue: read them.
Really. Even if you haven't got a problem to solve. They contain so
much info that you learn something every time you go back to them. Plus,
if you encounter a problem later, you may remember that you have read
something similar in a manpage. Hell, even being familiar with some of
the names of the manpages can set off an idea of where to look.
One last note: if you're also beginning programming, then you're in for
a lot more work. Try _Elements of Programming with Perl_ by Andrew
Johnson, which is a programming intro which happens to use Perl.
If you take this seriously, people in the community will take you
seriously. Don't cut corners and expect c.l.p.m. to pick up the slack.
As you've seen, it begets appropriately terse responses. Good luck.
Steve
[1] For Perl, start with _Programming Perl_ 3rd ed., Wall, Christiansen,
Orwant.
[2] Including this newsgroup post. I'm just some random hacker you'll
never meet.
--
Steven Smolinski => http://www.steven.cx/
------------------------------
Date: Thu, 4 Jan 2001 19:45:14 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: General Personal Development Strategy
Message-Id: <slrn958e0q.edk.mgjv@martien.heliotrope.home>
On Thu, 04 Jan 2001 01:29:53 GMT,
John Hall <jhall@ifxonline.com> wrote:
> I see a lot of "you work stupid" and "RTFM" on this list.
Mostly when it is deserved. It is deserved, in most people's eyes, when
the poster doesn't _show_ that he or she has looked at doucmentation, or
rea dthe newsgroup, or consulted the FAQ, etc.. Anyone who demonstrates
that they have at least tried gets much more friendly pointers.
> I am curious if someone can give me a more constructive method/procedure for
> figuring out ways of writing perl code.
The key is to get familiar with the language. The only way to do that is
by practice, and repeated reading of documentation, and maybe the Camel
(especially the third edition is full of jewels of information).
Something like the Perl Cookbook is a good one to work through as well,
once you get a bit more comfortable. To learn Perl as well as
programming, Andrew Johnson's 'Elements of Programming with Perl' is
good, to learn Perl when you already know programming, the Llama is good
(Randal Schwartz and Tom Christiansen, "Learning Perl").
But nothing beats reading the FAQ, followed by understanding each
answer, and reading the relevant parts of the documentation, browsing
through perldata, perlsyn, perlref, perlfunc, and some others. Reading
other people's code, and understanding exactly what theyre doing and
why.
Once you become more familiar with Perl, and start to know how to
navigate the documentation, you will just know which piece of
documentation to scan. You'll know wich builtin function does what sort
of stuff. You'll think to yourself, often: "Didn't I read something
about this in the FAQ or documentation somewhere?", and you'll find it
again.
> In a nutshell, how do I get from "I need this data to print out always as 2
> characters" to "perldoc -f printf" - What tools did you people use when you
> were starting out? Will the fact that I don't know C cripple me? [I notice a
See above, and yes, knowing C is helpful, because Perl borrows much from
it.More useful even is knowing Unix and its standard set of tools (sed,
awk, grep, etc.).
> lot of things in perldoc say 'similar to how it's done in C']. Are there any
> preferred sites that have useable search features, that will work for me as
> I am developing an understanding of the terminology?
Don't use sites to search the documentation. Use grep. Learn to use
grep. If you don't have grep, get one (a perl version can be obtained
from http://language.perl.com/ppt/).
If you want sites with all kinds of other stuff, start at www.perl.com,
and look at the list of links at the bottom.
> I have an outdated manual bookmarked at
Don't use webbified manuals. he original pod documents on your hard disk
are much more useful, and they're up to date. And you can easily search
them.
All it takes is patience and practice. You can't be a good programmer,
in any language, without practice, and lots of it. Juts like you can't
be a good medical doctor, astronomer, chemical engineer, or printer
withouit lots of practice, and ready-to-use knowledge. And aquiring
those takes time.
Martien
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: 4 Jan 2001 15:39:41 GMT
From: abigail@foad.org (Abigail)
Subject: Re: General Personal Development Strategy
Message-Id: <slrn95969t.qdu.abigail@tsathoggua.rlyeh.net>
John Hall (jhall@ifxonline.com) wrote on MMDCLXXXIII September MCMXCIII
in <URL:news:lmQ46.130526$I5.3269544@news1.rdc1.sdca.home.com>:
:} I see a lot of "you work stupid" and "RTFM" on this list.
:}
:} I am curious if someone can give me a more constructive method/procedure for
:} figuring out ways of writing perl code.
More constructive than reading the manual? Except for private tutoring,
I don't think there is.
:} I have been programming for ~2 weeks. Prior to my extensive career as a perl
Then I doubt Perl is suitable for you. Using Perl as your first language
is doing it the hard way - it might get you killed. Schumacher didn't
learn to drive in a Formula I car either!
:} In a nutshell, how do I get from "I need this data to print out always as 2
:} characters" to "perldoc -f printf" - What tools did you people use when you
:} were starting out? Will the fact that I don't know C cripple me? [I notice a
:} lot of things in perldoc say 'similar to how it's done in C']. Are there any
:} preferred sites that have useable search features, that will work for me as
:} I am developing an understanding of the terminology?
It's a good idea to read `man perlfunc' from top to bottom. Not to learn
all the details of all function, but just to see what functionality Perl
provides. Then if you need any of it, you can study the appropriate section
in detail.
Also at the beginning of perlfunc, you find all the functions listed by
category. You wanted to have something related to input/output. And guess
what? print and printf are mentioned ....
You are not crippled if you don't know C, but knowing C/Unix does help.
Abigail
--
sub A::TIESCALAR{bless\my$x=>A};package B;@q[0..3]=qw/Hacker Perl
Another Just/;use overload'""'=>sub{pop @q};sub A::FETCH{bless\my
$y=>B}; tie my $shoe => qq 'A';print "$shoe $shoe $shoe $shoe\n";
------------------------------
Date: Thu, 04 Jan 2001 17:38:51 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: Re: General Personal Development Strategy
Message-Id: <Ly256.132942$I5.3377363@news1.rdc1.sdca.home.com>
I'm replying to myself so as not to single out any one reply to my original
post;
Thanks to all for your help. I know what I need to do now to get from point
a to point z.
Apprently I really do have to go through the rest of the alphabet!
See you in a few months when i'm done reading. :)
John
http://moron.shutdown.com
------------------------------
Date: Tue, 02 Jan 2001 19:06:42 GMT
From: neil@brevity.org
Subject: Get arbitrary number of random lines from a file
Message-Id: <92t8rr$br0$1@nnrp1.deja.com>
In perlfaq5, also described in the Perl Cookbook, there's a nifty
recipe for quickly choosing a random line from a file, without
reading the whole file into memory:
# PCB recipe 8.6, p.284
rand($.) < 1 && ($line = $_) while <>;
# $line is the random line
Here's a way to do the same thing, but also pick an arbitrary
number of random lines, guaranteed, in one pass:
rand($.) < $d && ($line[$.<=$d ? $.-1 : rand $d]=$_) while <>;
die "not enough lines in input" if $d > $.;
# @line now contains $d random lines, unordered
Or, more clearly, as a complete program:
#!/usr/bin/perl -w
use strict;
(@ARGV >= 2) or
print STDERR "usage: $0 number file1 [ file2 ... ]\n"
and exit;
my $d = shift;
my @line;
while (<>) {
if ($. <= $d) {
push @line, $_;
} elsif (rand($.) < $d) {
$line[rand $d] = $_;
}
}
if ($d > $.) {
die "not enough lines in input; wanted $d, got $.";
}
print @line;
I don't have a rigorous proof that it works, but it seems to
choose fairly in my testing.
Argument that this works:
Assume that the PCB algorithm is correct (and a proof is given
in PCB, which I won't restate here).
Call the desired number of lines D and the total number of lines
in the input file N.
In the case of D > N, an error is generated. If D == N, it
simply reads in all the lines of the file.
In the more common D < N case:
If you look at a single element of the @line array, it's similar
to the PCB algorithm. A "first line" is guaranteed to be read
in, and then possibly replaced many times. Replacements happen
less and less often as we read through the file.
What's different is that when a replacement is triggered, an
element only has a 1/D chance of being replaced. However,
replacements occur D times more often.
So, from the perspective of a single element of the array, we
can imagine the PCB algorithm is simply being fed lines from
a subset of the file which has roughly N/D lines.
Since each line is individually shunted to one element or the
other, there's no danger of picking the same line twice.
--
Neil Kandalgaonkar <neil@brevity.org>
Sent via Deja.com
http://www.deja.com/
------------------------------
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 5229
**************************************