[12986] in Perl-Users-Digest
Perl-Users Digest, Issue: 396 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 6 00:17:29 1999
Date: Thu, 5 Aug 1999 21:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 5 Aug 1999 Volume: 9 Number: 396
Today's topics:
Re: Use shell for 'ls *.*' & Create new file ?? <cassell@mail.cor.epa.gov>
Re: Use shell for 'ls *.*' & Create new file ?? <tchrist@mox.perl.com>
Re: Use shell for 'ls *.*' & Create new file ?? <cassell@mail.cor.epa.gov>
Re: Use shell for 'ls *.*' & Create new file ?? <rick.delaney@home.com>
Re: web bot needed <mambuhl@earthlink.net>
Re: WHO IS THIS PERSON? please help <cassell@mail.cor.epa.gov>
Re: Why is it.... [REPOST] (Abigail)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Aug 1999 20:16:37 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Use shell for 'ls *.*' & Create new file ??
Message-Id: <37AA5395.F303E836@mail.cor.epa.gov>
Trond Peter Skjønsberg wrote:
>
> Hi
>
> [script included at the bottom]
Good. So many people ask us what's wrong with their code, but neglect
to show us any code at all.
> Yesterday I made my first perl-script.
Congrats. Are you teaching yourself Perl, or learning it from a book,
or learning it from a web tutorial, or taking a course? If you want to
look at a nice web tutorial, I recommend
http://www.netcat.co.uk/rob/perl/win32perltut.html
which, despite the filename, is not win32-centric. A beginner can
learn a lot from that site.
> It takes any given file (also
> *.*), and modifies it to html with <html><pre>...</pre></html> and
> rename to .html.
Okay. Have you thought about generalizing this? What if you just want,
say, all the *.txt files?
> The script uses 'ls' to determine any matching files if given argument
> is something like '*.*'. E.g. 'ls *.txt'.
>
> Q: Is there any other good way 'ls' without the shell?
A number. Of course, in Perl TMTOWTDI. [There's More Than One Way
To Do It.] I recommend that you take a look at the functions
opendir(), readdir(), and closedir() to get maximal control over your
files.
But you can also do this with the glob() function, as well as by
simply putting your wildcards inside the angle operator like this:
while (<*.*>) {
> Q: Also, I want to create a backup file during modification of a file,
> but how do I create a new file? Do I have to use the shell?
You just open() it for writing. See the docs on open() and be sure
to read Tom Christiansen's perlopentut which now comes along with the
Perl docs that get put on your system when you [or someone you trust]
install Perl. That said, you often want to be defensive and make a
copy of the file [you can use File::Copy to do that quickly] with a
temporary name, make the changes, then save the newly-altered file to
the desired filename [Perl has an mv() function too]. That way, in
case of Bad Things, you still have a copy of your original file.
> Trond Peter
>
> -----------------------------------------
> Here I added the essentials of my script:
Some essentials you left out - the top lines should be
#!/path/to/perl -w
use strict;
Although 'use strict' will require you to learn about my(), it's
well worth the effort.
> $Arg=$ARGV[0];
>
> ..some false-arg checking..
A good idea, but you really don't need this many copies of $ARGV[0] .
Remember that
while (<>) {
will read out of ARGV by default so you don't have to do all this
work.
> $File = $Arg;
> if ( index( $Arg, "*" ) != -1 ) {
> @File_array = reverse( @File_array = `ls $Arg` );
I really don't think you need to work this hard. All of this and
your loop below could have been done using that while loop I
just suggested.
> for ( $i = $#File_array; $i != -1; $i-- ) {
The for loop approach is very C-ish, but not needed in a language
as flexible as Perl.
> $File = $File_array[$i];
> $File_name_endpt = index( $File, "\n" );
> $File = substr( $File, 0, $File_name_endpt );
> $Exit_status = &Make_html( $File );
> if ( $Exit_status.....
> }
> goto Exit;
> } else { &Make_html( $File );}
>
> sub Make_html {
> ...
> ...
> }
>
> Exit:
And if you want a better way to HTMLize your file, take a look at
the Perl scripts that came with your install. pod2html is a good
example.
HTH,
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist
mathematical statistician
------------------------------
Date: 5 Aug 1999 21:21:48 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Use shell for 'ls *.*' & Create new file ??
Message-Id: <37aa54cc@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, David Cassell <cassell@mail.cor.epa.gov> writes:
:[Perl has an mv() function too]
Oh?
--tom
--
There is no reason for any individual to have a computer in their home. --Ken Olsen, 1977
------------------------------
Date: Thu, 05 Aug 1999 20:35:02 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Use shell for 'ls *.*' & Create new file ??
Message-Id: <37AA57E6.6964755F@mail.cor.epa.gov>
Tom Christiansen wrote:
>
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc, David Cassell <cassell@mail.cor.epa.gov> writes:
> :[Perl has an mv() function too]
>
> Oh?
Well, that was poorly written, wasn't it? I of course *meant* to say
something that wasn't totally stupid.. but failed. I was intending to
mention File::Copy's move function, but I got distracted and didn't
go back up to fix that line.
For those playing at home:
File::Copy - Copy files or filehandles
SYNOPSIS
use File::Copy;
copy("file1","file2");
copy("Copy.pm",\*STDOUT);'
move("/dev1/fileA","/dev2/fileB");
^^^^
use POSIX;
use File::Copy cp;
and farther down that same manpage:
You may use the "mv" alias for this function in the same
way that you may use the "cp" alias for copy.
Hmm. Only two tries to convey a one-try concept. Aren't you glad I
don't teach for the Tom Christiansen Perl Consultancy?
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist
mathematical statistician
------------------------------
Date: Fri, 06 Aug 1999 03:53:58 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Use shell for 'ls *.*' & Create new file ??
Message-Id: <37AA5C37.A345EAA4@home.com>
[posted & mailed]
Trond Peter Skjønsberg wrote:
>
> Q: Is there any other good way 'ls' without the shell?
Yes, but that is not relevant here. You want to use the shell, just not
ls.
> Q: Also, I want to create a backup file during modification of a file,
> but how do I create a new file? Do I have to use the shell?
No, but sometimes it's easier.
> Here I added the essentials of my script:
^^^^^^^^^^^^^^
Thank you. This is an excellent example of TMTOWTDI. I'll give you
some other ways, which are mostly better, IMHO.
> $Arg=$ARGV[0];
>
> ..some false-arg checking..
>
> $File = $Arg;
> if ( index( $Arg, "*" ) != -1 ) {
if ($Arg =~ /\*/) { # perldoc perlre
This isn't necessarily better, but it is easier to extend. Don't you
want to allow other wildcards? How about
if ($Arg =~ /[*?]/) {
> @File_array = reverse( @File_array = `ls $Arg` );
reverse() will reverse the *list* it is supplied in list context. It
does not need to be supplied an *array*. So you could write this as
@File_array = reverse `ls $Arg`;# perldoc -f list
# perldoc perldata
# for more on lists and arrays
> for ( $i = $#File_array; $i != -1; $i-- ) {
Okay, I'm not quite sure why the order of the files matters, but even if
it does it seems kind of silly to reverse the order and then iterate
through the array backwards.
You could just have easily done
@File_array = `ls $Arg`;
for ( $i = 0; $i < @File_array; $i++) {
> $File = $File_array[$i];
Since you're just iterating through the elements of @File_array and
don't really need the index, $i, you might as well have used a foreach
loop (which can still be spelled "for").
for $File (@File_array) {
> $File_name_endpt = index( $File, "\n" );
> $File = substr( $File, 0, $File_name_endpt );
You know that the "\n" will be the last character. There is a function
that removes the last character.
perldoc -f chop
There is also a function that removes the input record separator (which
is stored in $/), if it's there.
perldoc -f chomp
Let's use that one:
chomp $File;
You wouldn't need to chomp if you had used glob instead of `ls $Arg`.
@File_array = glob $Arg;
And then you don't even need @File_array:
for $File (glob $Arg) {
> $Exit_status = &Make_html( $File );
> if ( $Exit_status.....
> }
> goto Exit;
> } else { &Make_html( $File );}
This else is pointless, as is the if it goes with.
There is no need to test for wildcards, since if they are not there then
your list of files, whether using glob or ls will just be a list of one
filename.
Now, having said all that, there is no reason for you to use ls or glob
at all. You are assigning $Arg from @ARGV. For any of this to work you
would have to run your program like:
$ your_prog "*.txt"
Don't do this. Let the shell do your globbing for you. Run your
program like
$ your_prog *.txt
and then process the files in @ARGV.
for $File (@ARGV) {
&Make_html( $File );
}
HTH.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Thu, 05 Aug 1999 23:23:20 -0400
From: Martin Ambuhl <mambuhl@earthlink.net>
Subject: Re: web bot needed
Message-Id: <37AA5528.6A9FB5A2@earthlink.net>
Toyin Akinmusuru wrote:
>
> Hi folks,
> I'm in need of a spider bot to pull info from a group of text files on
> different sites and put it into a format my db can handle. We're
> willing to pay at least US$1000 for this.
I'm in need of a roach droid to pull info from a group of text files on
different sites and put it into a format my xlq can handle. We're not
willing to pay anything for this. It must have something to do with C,
C++, or perl. Maybe. Sortof.
--
Martin Ambuhl mambuhl@earthlink.net
__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com
------------------------------
Date: Thu, 05 Aug 1999 20:41:18 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: WHO IS THIS PERSON? please help
Message-Id: <37AA595E.29B8D52A@mail.cor.epa.gov>
BIONICFLE wrote:
>
> http://members.aol.com/betzyjo1/arcbhguy.jpg
>
> reply to sender
Since this is comp.lang.perl.misc, I'll assume your question has some
Perl relevance.
Is it Larry Rosler in disguise?
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist
mathematical statistician
------------------------------
Date: 5 Aug 1999 23:04:00 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Why is it.... [REPOST]
Message-Id: <slrn7qknk8.uij.abigail@alexandra.delanet.com>
Tom Christiansen (tchrist@mox.perl.com) wrote on MMCLXVI September
MCMXCIII in <URL:news:37aa4b6f@cs.colorado.edu>:
[This is quite long, mainly due to quoting. I've tried to trim down
things a bit, but I found it hard to balance between keeping the
meaning and Toms train of thought there, and the necessity of trimming ]
;; In comp.lang.perl.misc,
;; abigail@delanet.com writes:
;; :It's an unworkable situation. If you can't code something because you
;; :haven't had your flash of brilliance yet, you're plain stupid. The smarter
;; :person would make use of the resources available and look up how to do it.
;;
;; Right. And since the people whom the original poster was asking about fall
;; obviously aren't making use of the resources available to look up how
;; to do things, they ceertainly aren't falling into the "smarter" group.
;;
;; :You think programming is something special? It's just a job....
;;
;; Then so, too, are brain surgeons, air-traffic controllers, and piano-bar
;; hacks "just jobs", right? Hm. I'm not sure I agree that "just" is called
;; for there, and I don't know that it's called for in programming either.
Brain surgery and controlling air traffic are just jobs, yes. Although
it might take the better part of a decade studying, before you can do
your job. A brain surgeon doesn't have "the gift". It's years of _hard
work_. As for piano players, it's a bit different. There's certainly
lots and lots of hard work involved, but judging whether played music
is good and enjoyable isn't objective. I won't argue that talent and
gift don't play a factor in this case.
;; I also wonder whether you don't overestimate the abilities of those
;; less gifted or less experienced than yourself; say, someone with half
;; your measured or hypothetical IQ, or without your extensive education
;; in algorithmic design and analysis. I think you'll accept that their
;; gifts and proclivities may not lie where yours do.
Don't overestimate me. Certainly, I spend almost a decade studying
algorithm design and analysis, which helps me when I program. But it was
mostly hard work. Looking back, I've had 2 "flashes of insight" during
those years. And one of them turned out not to be that good anyway;
normal grind work produced a much better result. Which leaves me with
one flash of insight. And not a spectacular one either; delaying of
computation wasn't anything new.
There will be many flocks of people who are able to do the same as I did.
But most of them have other exciting things to do in those years. That
doesn't mean they are unable to.
;; And believe it or
;; not, some of them create webpages. And they're going to have a rather
;; harder time of writing a distributed, high-performance, complex shopping
;; cart program than would you. But they still want to do it. Fear.
Yes. They want to. They shouldn't though. At least, not in this point in
time. They first should *become* a programmer, then write the program.
Not the other way around.
;; I just answered with a large followup posting elsewhere in this thread,
;; and meaning no disrespect, am frankly too tired to provide another
;; response that extensive tonight. Perhaps you could read that posting;
;; I fear I'd be repeating myself here to use the same statements to
;; answer yours.
Tom Christiansen (tchrist@mox.perl.com) wrote on MMCLXVI September
MCMXCIII in <URL:news:37aa4609@cs.colorado.edu>:
;; Let us return to the question, which in effect asked, "How come I who've
;; only been hacking perl for three days can manage to read docs, search
;; old postings, and write useful programmers without having to come here
;; begging, yet there are scads of people here who've obviously been doing
;; this longer than I have, yet these people keep asking the same stupid
;; questions again and again?"
;;
;; My answer was that perhaps it was because the poster was smarter, more
;; resourceful, and more determined than they were. I then proceeded,
;; to express the view that programming was not something that everyone
;; can learn to do. In fact, I don't believe it's something most people
;; can learn to do, not at the level needed.
;;
;; To provide an answer with supporting exposition is no "strawman",
;; and your denouncements to that effect are mystifying. I was simply
;; supporting my point that talent or skill or gifts or brains or whatever
;; you want to call it actualy count, and that lack of the same is one of
;; the root causes about which the original querent inquired.
;;
;; You get people out there who can barely get the quoting right to set a
;; path variable in their login start-up files wanting to write programs to
;; do a complete parse of arbitrary English. You get people who can barely
;; get a semi-colon at the end of a statement want to write a multi-screen
;; shopping card program with authentication, tracking, and database tie-ins.
;; There are not programmers. Whether they will ever become programmers,
;; or even programmers sufficiently proficient to encode their desires,
;; is not always certain. Some will not -- and some really and truly cannot.
;;
;; Some folks just don't have enough juice. Please recognize this. I know
;; people with IQs in the 70s and 80s who use computers. They even make
;; web pages. Guess what? They will never write a compiler, and they will
;; never write a shopping cart program. In fact, it's unlikely they'll
;; ever write a program beyond the proverbial "Hello world".
;;
;; There are plenty of folks sitting here who land in the top one hundredth
;; of one percent -- or even far better in some cases -- of the population
;; in terms of brainpower. These people are gifted in a way that the next
;; 9,999 (or 99,999 or 999,999 etc) of their fellows are not. People like
;; this really can do nearly any task within the realm of human mental
;; abilities, if they merely set their minds and wills to it. But just
;; because some have this gift doesn't mean everyone has it.
;;
;; Some people are just plain in over their heads. Maybe they don't have
;; the basic intellectual firepower, like the ones above. Please don't
;; pretend these people don't exist. They're all around you.
While this is all true, I don't think the union of the top one hundredth
of one percent, and the people that are just plain in over their heads
form the entire populations. You mention both extremes. I do not believe
that falling in the first extreme is a necessity to program. Falling
in that extreme makes it easier to learn programming. Those who are in
over their heads, they will never be able to learn to program. But the
large group in between, can. IF THEY WORK HARD.
I fully agree with you that a lot of the cruft we see in this newsgroup
have no right to call themselves programmers.
;; There are, of course, lots of other reasons for the endless stream of
;; the forlorn and beggarly. Maybe instead they don't have the background.
;; Maybe they don't have the attitude and the dedication. Maybe they have
;; what it takes to do what they're thinking of and actually could do it
;; if they would merely pursue five years of formal training or whatever
;; it would take, but because they're actually brain surgeons or mothers
;; of five, they consequently have far more important things to do.
Indeed.
;; Maybe they hate what they have to do. Maybe their boss has tried to
;; convert a word-processor drone into a software design architect using
;; "here, secretary, write this complicated program or die!". Maybe they
;; don't want to really be doing this. Maybe they just want to use other
;; people to do their work for them.
;;
;; Some of these people can be helped. Some can't.
And don't forget, most don't want to be helped. Because it means they
actually have to do work.
;; Many have completely unrealistic expectations about their own
;; capabilities, the difficulties of complex programming, or the simple
;; requirements of doing their own basic homework. And sometimes, these
;; people need their bubbles burst, because in the long run, it's the
;; kindest thing anyone can do for them. You don't have to drive them
;; to suicide in so doing, but you might coax them into something they'd
;; be more successful at.
;;
;; I could probably have further answered the original question by spending
;; another hundred lines of exposition on each of several additional classes
;; of individual, rather than focusing on only those whose basic gifts or
;; temperaments weren't up to the task. It would not surprise me to learn
;; that there were even more of these additional classes than those that
;; I did cover.
;;
;; But that still doesn't mean that everyone is cut out to be a programmer,
;; which is what the central point was.
I fully agree with that.
;; The lost post here constantly. Not all are lost for the same reason,
;; and of course, as Perl's fairy godfather wrote, not all those who wander
;; are lost. And not all those who are lost shall remain forever that way.
;; But I remind you that the original poster's question was about why so
;; many showed up here so terribly lost, when really it didn't seem all
;; that terribly hard a matter as far as he was concerned.
Abigail
--
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail
-----------== 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: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 396
*************************************