[13098] in Perl-Users-Digest
Perl-Users Digest, Issue: 508 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 13 17:07:15 1999
Date: Fri, 13 Aug 1999 14:05:15 -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 Fri, 13 Aug 1999 Volume: 9 Number: 508
Today's topics:
Re: "set -x" equivalent in perl? <tchrist@mox.perl.com>
Re: Another quick question...Arrays...testing against <aqumsieh@matrox.com>
Re: can i read a file backwards? <kangas@anlon.com>
CGI on MS Personal webserver <chen@compsci.cas.vanderbilt.edu>
Re: dot is too precious to be only for string concatena <aqumsieh@matrox.com>
Re: dot is too precious to be only for string concatena <tchrist@mox.perl.com>
Re: HARASSMENT -- Monthly Autoemail <flavell@mail.cern.ch>
Re: HARASSMENT -- Monthly Autoemail <cassell@mail.cor.epa.gov>
Re: hash in record <aqumsieh@matrox.com>
Re: How to delete an element from an array <aqumsieh@matrox.com>
Re: How to delete an element from an array <aqumsieh@matrox.com>
How to determine memory requirements of a variable? <stacy@beast.amd.com>
Re: I guess this is a Misc question: Cgi-bin (J. Moreno)
Internet Technologies Writer Required (Toronto, Canada) <jill@maran.com>
Re: Is this an appropreate use of -i switch? (Tony Kennick)
Re: Looking for a good Perl Book <aqumsieh@matrox.com>
Re: Looking for gibberish generator <cassell@mail.cor.epa.gov>
Re: Making a new web page out of an existing page <cassell@mail.cor.epa.gov>
Re: Newbie question about $_ (Tony Kennick)
Re: Newbie question <cassell@mail.cor.epa.gov>
Re: Newbie question <cassell@mail.cor.epa.gov>
Re: passing perl parameters to CGI script <cassell@mail.cor.epa.gov>
Re: Pedagogical Exercise w/ Symbol Table <cassell@mail.cor.epa.gov>
Re: Perl sort question/help <cassell@mail.cor.epa.gov>
Printing perldoc <ebct@hotmail.com>
Re: Problems connecting to some web servers!!!! <cassell@mail.cor.epa.gov>
regular expression - counting words and quotes (Bill Moseley)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Aug 1999 14:44:41 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: "set -x" equivalent in perl?
Message-Id: <37b483b9@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
mfrost@westnet.com (Mark Frost) writes:
:What I would *love* to have is something that equivalent to the shell's
:"set -x" or "sh -x script.sh" where each line that is executed is
:printed out.
Hidden down in the perldebug manpage:
Here's an example of using the `$ENV{PERLDB_OPTS}' variable:
$ PERLDB_OPTS="N f=2" perl -d myprogram
will run the script `myprogram' without human intervention,
printing out the call tree with entry and exit points. Note that
`N f=2' is equivalent to `NonStop=1 frame=2'. Note also that at
the moment when this documentation was written all the options
to the debugger could be uniquely abbreviated by the first
letter (with exception of `Dump*' options).
Other examples may include
$ PERLDB_OPTS="N f A L=listing" perl -d myprogram
- runs script noninteractively, printing info on each entry into
a subroutine and each executed line into the file listing. (If
you interrupt it, you would better reset `LineInfo' to something
"interactive"!)
$ env "PERLDB_OPTS=R=0 TTY=/dev/ttyc" perl -d myprogram
may be useful for debugging a program which uses
`Term::ReadLine' itself. Do not forget detach shell from the TTY
in the window which corresponds to /dev/ttyc, say, by issuing a
command like
$ sleep 1000000
See the section on "Debugger Internals" below for more details.
--tom
--
Intel chips aren't defective. They just seem that way.
------------------------------
Date: Fri, 13 Aug 1999 12:18:52 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Another quick question...Arrays...testing against
Message-Id: <x3ywvuz1wnp.fsf@tigre.matrox.com>
"(BXTC)" <bxtc@forfree.at> writes:
> I have an array "@numbers" with values as follows (although the $#numbers
> will vary)
>
> @numbers[0] = 5
> @numbers[1] = 9
> @numbers[2] = 19
> @numbers[3] = 12
> @numbers[4] = 6
You've got something wrong up there. @numbers[0] is an array
slice. Remember these as rules:
1) Scalars always start with '$'. If it starts with '$' it's a scalar.
2) Arrays always start with '@'. If it starts with '@' it's an array.
What you actually want is:
$numbers[0] = 5;
etc...
since array elements are scalars. So to get an array element, you need
a '$'.
For more info, check out perlfaq4:
What is the difference between $array[1] and @array[1]?
> Now I need to search each value of @numbers to see if ANY of them equals
> $target.
You can use grep() for that. Although a simple loop might be faster.
for my $number (@numbers) {
if ($number == $target) {
do_your_stuff();
last;
}
}
> I have been reading the book all about arrays, and I have learned
> that I can't test it as @numbers because that would test the WHOLE array,
> and using slices isn't any better. I tried doing something like this
I don't follow you there. What exactly is confusing you?
> my $x = $#numbers - 1;
> while ($x >= 0){
> if ($#target = $numbers[$x]) {
'=' is for assignment. '==' is for equality tests. The above should
be:
if ($#target == $numbers[$x]) {
> DO_MY_FUNCT();
Perhaps you want a 'last;' statemenet here to break from the loop,
since you already found an element that satisfied your condition.
> } else {
> $x - 1;
This does not subtract 1 from $x. It returns a value equal to the
value of $x minus 1. $x is not altered. This should actually be:
$x = $x - 1;
or
$x--;
> }
> }
>
> but it didn't work, as it didn't like my syntax and it was saying something
> about a useless subtraction, on one of the lines that only had "}" on
> it...so that confused me.
Perl sometimes doesn't report the exact line number where the
error/warning occurs. You should look a few lines below and a few
lines above the reported line for the actual error. But, in your case,
since there is only one line where you perform subtraction, then the
error should've been easy for you to find.
> And just so you don't think I am just getting you to do my work for me
> (although the code I've shown you is probably proof enough as it is wrong
> and inefficiant) I have been reading a lot in the perldoc(which is hard to
> understand sometimes) and the Camel book(pretty good, but leaves some
> questions unanswered), and looking at other people code from web sites.
That's the best way to learn Perl. I suggest you also have a look at
the on-line FAQs (perlfaq1 .. perlfaq9), and the Perl CookBook (the
Ram). They contain a wealth of information and useful examples which
you could learn a lot from.
If you think you have looked hard enough, but still couldn't find a
solution to your problem, then do post on clpm. But only when you have
looked REALLY hard :)
> Thanks for the time you have already spent, and for any more you might
> spare.
you're welcome,
Ala
------------------------------
Date: Fri, 13 Aug 1999 15:50:19 -0500
From: Mike <kangas@anlon.com>
Subject: Re: can i read a file backwards?
Message-Id: <37B4850A.8BFC3A5E@anlon.com>
May not be the best way but it works.
#############################
open(FILE, "normal.txt");
@file = <FILE>;
close(FILE);
@backwards = reverse(@file);
foreach(@backwards) {
@line = split(//, $_);
print reverse(@line);
}
#############################
JCEtek wrote:
> hi
> can i start reading at eof, and read up?
--
Michael Kangas
Anlon Systems, Inc.
kangas@anlon.com
------------------------------
Date: Fri, 13 Aug 1999 15:33:00 -0500
From: Jun Chen <chen@compsci.cas.vanderbilt.edu>
Subject: CGI on MS Personal webserver
Message-Id: <37B480FB.93FDD26D@compsci.cas.vanderbilt.edu>
Hi, does any body know how to run CGI on MS personal web server?
It is claimed to support CGI script but I have no idea how to make it
work.
Thanks in advance!
--
Jun Chen
-----------------------------
comped.cas.vanderbilt.edu/~chen
------------------------------
Date: Fri, 13 Aug 1999 14:57:56 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: dot is too precious to be only for string concatenation
Message-Id: <x3yr9l71paj.fsf@tigre.matrox.com>
"John Lin" <johnlin@chttl.com.tw> writes:
> 1. Grab the dot operator so that it won't be treated as string
> concatenation.
> 2. Control the associativity and precedence in a module.
> 3. Tell the compiler to treat $john.name as $john->{name} at compile time.
> 4. Generate error messages for misuse at compile time.
I don't know if this is possible. But the question that springs to my
mind is "WHY do you want to waste your time doing that"?
Perl is a tool to get things done. Some of its symantics may not be
pretty, but that's not the point. Perl was made to be useful, not
elegant.
I don't really care about how ugly dereferencing a hash is, or how
unintuitive the syntax is to create data structures. As long as it
does the job, I'm a happy person.
Don't create a new syntax just for the sake of creating a new
syntax. Don't fall into the Python trap.
Ala
------------------------------
Date: 13 Aug 1999 15:01:24 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: dot is too precious to be only for string concatenation
Message-Id: <37b487a4@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Ala Qumsieh <aqumsieh@matrox.com> writes:
:Don't create a new syntax just for the sake of creating a new
:syntax.
You should go talk to the hookhook people. :-(
--tom
--
* MIME::Lite alone cannot help you lose weight. You must supplement
your use of MIME::Lite with a healthy diet and exercise.
-- MIME-Lite Perl module documentation
------------------------------
Date: Fri, 13 Aug 1999 21:47:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HARASSMENT -- Monthly Autoemail
Message-Id: <Pine.HPP.3.95a.990813214553.5423I-100000@hpplus03.cern.ch>
On Fri, 13 Aug 1999, Summer S. Wilson wrote:
> Tell your ISP and complain to his. Then block the emails.
Join the usenet discussion properly, and there'll be no emails needing
to be blocked. news.announce.newusers isn't there for decoration.
------------------------------
Date: Fri, 13 Aug 1999 14:04:24 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: HARASSMENT -- Monthly Autoemail
Message-Id: <37B48858.72206261@mail.cor.epa.gov>
Summer S. Wilson wrote:
>
> Tell your ISP and complain to his. Then block the emails.
Or stop posting using non-standard style, and Tom will go away.
And stop cross-posting unnecessarily.
When you've written several important computer texts also,
perhaps I'll listen more closely to your concerns.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 14:29:35 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: hash in record
Message-Id: <x3yso5n1qlt.fsf@tigre.matrox.com>
lr@hpl.hp.com (Larry Rosler) writes:
> In article <x3yvham9qbp.fsf@tigre.matrox.com> on Wed, 11 Aug 1999
> 13:31:39 -0400, Ala Qumsieh <aqumsieh@matrox.com> says...
> ...
> > $rec = (
> > total => 10,
> > LOOKUP => { %some_table } ,
> > );
> >
> > uses parentheses which construct a list, and assign the last value (an
> > anonymous copy of the %some_table hash) to $rec.
>
> No, there is no list in that statement. If there were, what would cause
> the *last* value to be assigned?
I really don't understand what you mean there. From perldata:
In a context not requiring a list value, the value of the
list literal is the value of the final element, as with the
C comma operator. For example,
@foo = ('cc', '-E', $bar);
assigns the entire list value to array foo, but
$foo = ('cc', '-E', $bar);
assigns the value of variable bar to variable foo.
And applying that to the example quoted above:
% perl -wl
%some_table = qw/a b c d q e f g/;
$rec = (
total => 10,
LOOKUP => { %some_table } ,
);
print $rec;
print keys $rec;
__END__
HASH(0xb7e84)
aqcf
(I removed three warning messages about constants in void context).
So, $rec got assigned an anonymous copy of %some_table, as I said.
Or am I missing something?
Ala
------------------------------
Date: Fri, 13 Aug 1999 14:12:52 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How to delete an element from an array
Message-Id: <x3yu2q31rdn.fsf@tigre.matrox.com>
QuestionExchange <USENET@questionexchange.com> writes:
> > Could someone please let me know if it is possible to delete an
> > element from an array in perl?
> > @array = ("one","two and three",4,"five");
> > how do I delete '4' and be left with...
> > @array = ("one","two and three","five");
> > Thanks in advance,
> > Dico
>
> splice(@array, 2, 1);
> This removes 1 element at offset 2
> (counting from 0).
Yes, but this assumes that you know exactly the offset of the element
you want to remove, which is not necessarily evident.
Ala
------------------------------
Date: Fri, 13 Aug 1999 14:11:18 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How to delete an element from an array
Message-Id: <x3yvhaj1rga.fsf@tigre.matrox.com>
ced@bcstec.ca.boeing.com (Charles DeRykus) writes:
> In article <37b1d968.8951042@news.attcanada.net>,
> Dico Reyers <dico@internetworks.ca> wrote:
> >Hello there,
> >
> >Could someone please let me know if it is possible to delete an
> >element from an array in perl?
> >
> >@array = ("one","two and three",4,"five");
> >
> >how do I delete '4' and be left with...
> >
> >@array = ("one","two and three","five");
> >
>
> @array = map {$_ == 4 ? () : $_} @array;
Did you bother running this under '-w'?
You'll see many warnings of the form:
Argument "one" isn't numeric in eq at - line 2.
Besides, using grep() instead of map() would be a more natural choice:
@array = grep { !/^4$/ } @array;
HTH,
Ala
------------------------------
Date: Fri, 13 Aug 1999 15:46:02 -0500
From: Stacy <stacy@beast.amd.com>
Subject: How to determine memory requirements of a variable?
Message-Id: <37B4840A.4BF9CCCD@beast.amd.com>
Howdy folks-
I am trying to determine the best data structure for some code of mine.
It would be useful to be able to determine the amount of memory used by
any arbitrary variable. Does any one know how to do this???
Ex:
$nl = "\n";
$bar = "VARIABLE";
$foo = {
key1 => "value1",
key2 => [1, 1, 2, 3, 5, 8, 13],
key3 => {
subkey1 => "neat huh?",
subkey2 => $bar, # This is interesting when
$bar changes below
subkey3 => \$bar, # what happens with this
reference thingy?
},
};
# What I would like is something like this
print sizeof($foo), $nl;
print sizeof(%{$foo}), $nl;
print sizeof($foo->{key1}), $nl;
print sizeof($bar), $nl;
$bar = "CHANGE";
print sizeof($foo), $nl;
print sizeof($bar), $nl;
------------------------------
Date: Fri, 13 Aug 1999 16:10:08 -0400
From: planb@newsreaders.com (J. Moreno)
Subject: Re: I guess this is a Misc question: Cgi-bin
Message-Id: <1dwhff9.sakx3b1st54g0N@roxboro0-0020.dyn.interpath.net>
Ben Quick <newsgroup@bigwig.net> wrote:
> J. Moreno wrote in message
> >Ben Quick <newsgroup@bigwig.net> wrote:
> >
> >> I read the faq, it didn't (to my recolection) say do not ask about file
> >> permissions
> >
> >No, but section 2 of the faq (Obtaining and Learning about Perl) says:
> >
> >comp.lang.perl.misc Very busy group about Perl in general
>
> The general part is very none specific. Maybe a re-wording is on order?
Possibly so -- and I have a suggestion to send to them for doing so, if
I don't forget.
-snip-
> >(But this does bring up a point -- there is an excellent faq about perl,
> >but not for the NEWSGROUP, perhaps a faq for the newsgroup is in order?)
>
> I think that would be a very good idea. The faq is currently not really
> about this group
There's another faq just for the group, but it should be referenced by
that page (one of the things I'm going to suggest).
-snip-
> >the point is that politely giving the right answer or pointing to the
> >right newsgroup gives the impression that the question was reasonable and
> >it was OK to ask it.
>
> No. Giving the answer would imply it is ok to aks. Pointing to the right
> group would imply that where the question was asked was the wrong place
It also implies that the way to find out that a question is off topic is
to post it and then see from the responses.
You should be fairly sure that the question is on topic before asking it
-- and if you know it isn't or that it may not be, then be prepared to
accept the flames that will garner you in good grace.
-snip-
> >A "My mistake, I thought it would be OK to ask here" followed by "Thank
> >you, I appreciate it very much" (snipping everything in between).
>
>
> As would a
> "Sorry, you're in the wrong group. Try in ..."
> or
> "The answer is... but infuture forr this type of question ask in..."
Sure -- but, by posting an off topic question, you incurred an
obligation to acknowledge your mistake (which you have done), but /they/
didn't have an obligation to give you a polite answer.
Basically what I am saying is that the responses you got may have been
rude and/or sarcastic -- but they weren't *unduly* so given your
offense.
--
John Moreno
------------------------------
Date: Fri, 13 Aug 1999 16:21:52 -0400
From: "maranGraphics Inc." <jill@maran.com>
Subject: Internet Technologies Writer Required (Toronto, Canada)
Message-Id: <37b47e28@nemo.idirect.com>
Internet Technologies Writer Required
Canada’s largest computer book publisher, located in Mississauga Ontario,
requires a writer to author advanced computer books. Must have excellent
knowledge in one or more of the following areas: HTML, Linux, Perl, ASP,
Java and JavaScript.
Our books have sold over 6 million copies to date, and are translated into
25 different languages. As an author, your name will appear in books that
are sold around the world. We offer a casual dress environment and regular
Monday to Friday business hours. Contract and full time positions
available.
Send resume to: jill@maran.com
------------------------------
Date: Fri, 13 Aug 1999 20:04:07 GMT
From: tony@showroom.org.uk (Tony Kennick)
Subject: Re: Is this an appropreate use of -i switch?
Message-Id: <37b464bb.35597219@missy.shef.ac.uk>
abigail@delanet.com (Abigail) imparted the following:
:->
:->Indeed. 007 doesn't have kids, so what's he doing with a happy meal?
:->
He needs to complete his Womble collection.
--
From Tony Kennick aka Gonzo The Great
http://missy.shef.ac.uk/users/old-firm/
Gonzo: Slang for "the last man standing
at a drinking marathon"
------------------------------
Date: Fri, 13 Aug 1999 10:10:34 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Looking for a good Perl Book
Message-Id: <x3yzozv22li.fsf@tigre.matrox.com>
abigail@delanet.com (Abigail) writes:
> I have mixed feelings about the documentation. Its size is impressive.
> Perl is a large language when it comes to language constructs, amount of
> functions and operators, and the size of the standard library. Yet you'll
> have to come up with something pretty obscure, or highly experimental,
> to not have any documentation about it. It's a reference guide, *and*
> a tutorial. It's monumental. But it is also a maze, and it sometimes
> assumes quite a lot from a reader.
>
> I wish there was something better than the online documentation. We
> need something better. But I also realize it's damn near impossible to
> create something better.
IMO, it's probably the size of the docs that scare people away. If you
want to find more info on something, you have to figure out which pod
it resides in. And that location is not necessarily obvious as your INIT
example showed. Then you'll have to wade your way through the several
screens of code to get to your target information.
I can see easily where this becomes a tiresome, and frustrating
process. So how about creating even some more documetation ? :-)
Would it be a good solution if the docs were divided into 3 (or
more/less) sections:
1) docs for beginners where things are explained in easy terms with no
assumptions regarding experience. Not everything has to be included
there.
2) docs for semi-experienced users. This can include things like
perlobj, perlmod, perlmodlib, perldsc, perltoot, etc ..
3) docs for advanced users. These include perlguts, perlxs, perlembed,
etc ..
Plus of course the FAQs. Everything should reside in different
directories, to make life simpler. Also, maybe a sort of graphical
perldoc might help. It shouldn't be too hard writing one in
Perl/Tk. Or maybe something like that already exists.
I am not saying that what I am proposing will work. It will certainly
increase the already huge disk space occupied by the perldocs. But it
might be a start. Comments?
> '' OTOH, assembling a car would take me about as much time as it would
> '' take me to uninstall Internet Explorer ;)
>
> So, given that it was a breeze to install RedHat, assembling a car is
> a breeze for you?
No. Uninstalling IE from windows is almost impossible (or made very
hard for a purpose). And assembling a car is an almost impossible feat
for me to accomplish as well.
Ala
------------------------------
Date: Fri, 13 Aug 1999 14:01:06 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Looking for gibberish generator
Message-Id: <37B48792.5234A066@mail.cor.epa.gov>
Kim Eggleston wrote:
>
> Hello there,
>
> I am looking for a perl script which generates "fake" text for use in
> creating publishing mock-ups. I don't want just random characters but
> something that looks like actual english.
>
> Please let me know if you have any idea where I might find something like
> this or some starter code to use.
Well, you can always use something like:
my $mock_up = 'The quick brown fox jumps over the lazy dog. ' x 2000;
That should fill up a reasonable amount of space for you with
English sentences. For something more complicated, try picking
a dozen sentences and using rand() to select them with
replacement over and over until your space is filled.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 13:35:05 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Making a new web page out of an existing page
Message-Id: <37B48179.EDD646E3@mail.cor.epa.gov>
Eddie wrote:
>
> On 13 Aug 1999 01:45:29 -0500, abigail@delanet.com (Abigail) wrote:
>
> >Eddie () wrote on MMCLXXI September MCMXCIII in
> ><URL:news:37b1eddb.102089770@news.cadvision.com>:
> >;; Is it possible to create a web page by "stealing" certain text
> >;; passages from an existing web page on your web server? I've never
> >;; used perl before but if it can do this i'd like to start learning it.
> >;; The script would have to search for certain text in a filename and
> >;; then generate a new web page using an existing template.
> >
> >
> >Perl can. And that's the end of the thread in this newsgroup.
> >Find some l33+ h4X0rz to help you do stealing.
>
> What's l33+ h4X0rz? by 'stealing' I meant getting text from one of my
> own existing pages
That's a deliberate pastiche of the lingo of warez doodz, the
annoying little geek-ettes who do stuff like stealing other
people's work off the web. It translates to "elite hackers".
If what you meant was using your own web pages to create a
new web page using soe sort of template, you would have gotten
much farther by being specific. People actually assumed you
meant 'stealing'.
Now then, if you want to work with web pages in this manner,
you may be interested in some of the following Perl modules,
all of which are available (with documentation and examples)
from CPAN [www.cpan.org]:
CGI.pm
CGI::Lite
Text::Template
HTML::Parser
..as well as the many features which come with Perl already.
HTGYS,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 20:04:07 GMT
From: tony@showroom.org.uk (Tony Kennick)
Subject: Re: Newbie question about $_
Message-Id: <37b45cb4.33541505@missy.shef.ac.uk>
"Trond Michelsen" <mike@crusaders.no> imparted the following:
:->
:->You know, I thought I saw this movie in a theatre a few years ago, but then
:->I realized it was only a bad dream. BB2000 really does not exist. It's just
:->an urban legend. Nobody ever made a sequel to the Blues Brothers.
:->
This is equivalent to Highlander. There can be only one! There were no
sequels and definitely no TV series.
--
From Tony Kennick aka Gonzo The Great
http://missy.shef.ac.uk/users/old-firm/
Gonzo: Slang for "the last man standing
at a drinking marathon"
------------------------------
Date: Fri, 13 Aug 1999 13:41:02 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie question
Message-Id: <37B482DE.4C600816@mail.cor.epa.gov>
Damm Dashing wrote:
>
> Dear Folks,
>
> I apologize if this question inadvertantly takes up anyone's time.
>
> I have a while loop that goes:
>
> while ($line = <IN>) {
>
> chop $line;
>
> #do some processing
> #print the line
> } # while
Well, since you get the first line of the file, the problem
is almost certainly in the code you *didn't* show us. Perhaps
you could try again, including the elided code, and keeping
the lines of code to a reasonable length, say under 20.
Oh, and BTW, you probably ought to use chomp() instead of chop().
Depending on what you do with the line, you might not even need
to do that.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 13:45:38 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie question
Message-Id: <37B483F2.F560C4D5@mail.cor.epa.gov>
Mike wrote:
>
> try...
>
> open(IN, "filename");
You really ought to check returns on open()s .. *especially*
when you're giving advice that might be read by hundreds who
don't know it is not really okay.
> while(<IN>) {
Hmmm. Why is this an improvement over the poster's version?
Especially if you then do this:
> $line = $_; # if you wish
> chomp $line;
Now that's good advice. Thank you. You can leave the
line from the file in $_ and just say:
chomp;
[snip of rest]
> Damm Dashing wrote:
[snip of text placed after the answer]
Umm Mike, could please do me a favor and post your replies
*after* the quoted material instead of before? It's the
Usenet standard, and this group is a bear on such details.
Everyone will be happier, including you - since you won't
be getting flamed to a crackly crunch about it. :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 13:55:07 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Paul Foran <Paul.Foran@analog.com>
Subject: Re: passing perl parameters to CGI script
Message-Id: <37B4862B.6570378D@mail.cor.epa.gov>
[courtesy cc e-mailed to poster]
Paul Foran wrote:
>
> Do I pass parameters to perl script in the
> #!/usr/local/bin/perl
> line of a perl script.
> IWhat parameter do I pass to get perl ro read in a text file. Also How
> do I handle it to split apart a comma delimited file.
Paul, I really think, given the level of questions you're
dealing with, that you would benefit greatly from this
tutorial:
http://www.netcat.co.uk/rob/perl/win32perltut.html
which, depsite its name is not win32-centric;
and by purchasing the book "Learning Perl" by Randal
Schwartz and Tom Christiansen. It's worth it just for the
foreword, IMHO.
You pass parameters into a perl script the same way you
do it in a shell script. But you appear to be thinking
about the flags that can be stuck on the 'shebang' line
of the program. These flags are all listed and discussed
in the doc section called perlrun. You can read it by
typing 'perldoc perlrun' or 'man perlrun'.
To read in a text file, you'll have to learn about open()
and the <> operator. To parse a comma-separated [not
comma-delimited] file, you can either do it the hard
way [as explained in detail in the FAQ], or you can
use a module like Text::CSV or the database module
DBD::CSV . The CSV of course stands for 'comma-separated
values'.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 13:23:48 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Pedagogical Exercise w/ Symbol Table
Message-Id: <37B47ED4.EFD770B4@mail.cor.epa.gov>
K wrote:
>
> Hello.
>
> I've tried out the eample on page 281 of Perl and tried to
> take it one step further. I wanted to print out the key values
> for each symbol in the symbol table. Could anyone comment
> on where I am fouling up? It prints the hashes out in main::
> but I cant find any keys within these hashes.
>
> Thanks,
>
> Kevin Counts
> digicat@(scrap this)mindspring.com
> --------------------------------------------------------
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $symname; #-- symbol name of the specified package
>
> my $element_name; #-- name of each element in top_level hash from
> symbol_table
>
> my ($sym, @sym, %sym); #-- Temp variable to test if_defined-- in
> symname from typeglob
>
>
> foreach $symname (sort keys %main::) {
>
> local *sym = $main::{$symname};
>
> if (defined($sym)) {
> print "\$ " . $symname . " is defined\n"; }
>
> if (defined(@sym)) {
> print "\@ " . $symname . " is defined\n"; }
>
> if (defined(%sym)) {
> print "\% " . $symname . " is defined\n";
> foreach ( keys %sym ) {
> print "$sym{$_}\n";
> }
> }
> }
Now try this piece of kruft, modeled on your own:
#!/usr/bin/perl -w
use strict;
use vars qw /$symname $element_name $sym @sym %sym/;
foreach $symname (sort keys %main::) {
local *sym = $main::{$symname};
print "\$$symname is defined\n" if defined($sym);
print "\@$symname is defined\n" if defined(@sym);
if (defined(%sym)) {
print "\%$symname is defined\n";
print "$_\t=\t$sym{$_}\n" foreach ( keys %sym );
}
}
__END__
Notice any differences? Now you get all the values you
wanted, as well as some package variables you failed to
see before. Remember what my() does. It does lexical
scoping, and it does *not* put those my()'ed variables up
in the package's symbol table.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 13:30:01 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Perl sort question/help
Message-Id: <37B48049.F9A1992D@mail.cor.epa.gov>
Jeff Miller wrote:
>
> I have a sort question/help request - I have read the FAQ and all its
> pointers, but some of the sort information is just not clicking (HUGE
> abuse opening). I want to sort a dataset on different fields, and have
> been able to sort on the second field, but don't completly understand
> why it works, and how to modify to sort on different fields. Sample
[snip of rest of problem]
Jeff, it sounds to me as if you might profit from a quick study
of a web tutorial before reading the Perl docs. So here are my
suggestions:
[1] go to http://www.netcat.co.uk/rob/perl/win32perltut.html
for a nice intro tutorial to Perl [which is not win32-specific];
[2] buy "Learning Perl" or "Learning Perl on Win32 Systems",
whichever you feel is more appropriate;
[3] go to www.perlmonth.com and read Dave Cross' article on
using the perldoc program;
[4] now use perldoc to read the Perl manpages and the Perl FAQ.
You'll probably get more out of Perl if you try to learn
incrementally, rather than attempting a monumental grok.
In your case, you needed to know:
[a] regular expressions (to see what that regex did)
[b] Perl functions (to see that split() was probably a better
answer
[c] about the FAQ [good for you on that one!]
[d] Tom Christiansen's FMTEYEWTK series on aspects of Perl
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 16:14:52 -0700
From: "Irwin M. Feuerstein" <ebct@hotmail.com>
Subject: Printing perldoc
Message-Id: <7p1ucc$h7h$1@autumn.news.rcn.net>
How does one print using perldoc?
If one does:
perl -h > lpt1:
It works fine, but if one tries:
perldoc perldoc > lpt1:
you get nothing. None of the switches seem to help.
Thanks.
------------------------------
Date: Fri, 13 Aug 1999 13:37:32 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Problems connecting to some web servers!!!!
Message-Id: <37B4820C.9071776F@mail.cor.epa.gov>
Dafydd Richards wrote:
>
> I'm having problem communicating with some type of web servers using perl
> sockets.
> I can connect using python or telnet, browser etc, but for some reason it
> will not talk to perl.
> I example servers are NSL and various Netscape servers, Apache is fine.
>
> Does anybody have any ideas what causes the problem, and a solution if there
> is one.
I hate to be the one to tell you, but odds are that it is a
problem with your Perl code. I can't give you much more
help, since I can't see it from way over here. If you
can post a short (less than 30 lines) complete illustrative
example of your code (and please cut-and-paste if you can),
someone here might be able to help.
HAND,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 13 Aug 1999 13:39:22 -0700
From: moseley@best.com (Bill Moseley)
Subject: regular expression - counting words and quotes
Message-Id: <MPG.121e2251623fc9699896ae@nntp1.ba.best.com>
I'm not here to ask what a 'word' is. But I'm counting words with:
$_ = q[This is someone's "quoted" 'text'];
my %words;
$words{$1}++ while /([A-Za-z'_-]+)/g;
print "$_: $words{$_}\n" foreach keys %words;
I want "someone's" but I'd rather have "text" instead of "'text'". Any
way to do this within the regular expression?
Thanks,
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 508
*************************************