[12480] in Perl-Users-Digest
Perl-Users Digest, Issue: 6080 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 21 16:07:14 1999
Date: Mon, 21 Jun 99 13:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 21 Jun 1999 Volume: 8 Number: 6080
Today's topics:
[Req:] Date::Abigail (Lee)
Re: cgi query error <uucon@my-deja.com>
Re: Cure for document deficiency (Lee)
Docs for cmdline switches - where? <no.spammarkh@mailandnews.com>
Re: Docs for cmdline switches - where? (Greg Bacon)
Re: Fixed format fields: help needed! (J. Moreno)
Help me compile cooledit on Redhat 5.2 vod@writemail.com
How do I delete lines from a file <carter@computer.org>
Re: HOW DO I PAD A STRING IN PERL?? (Dave Cross)
Re: HOW DO I PAD A STRING IN PERL?? (Larry Rosler)
Re: Perl "constructors" <jdporter@min.net>
Perl Hash-DMB problem <tcthiel@athenet.net>
perl help <nsunitha@cse.unl.edu>
Re: perl help (Greg Bacon)
Re: Perl tutorial <cassell@mail.cor.epa.gov>
Re: Perl tutorial (Greg Bacon)
Re: Statistics for comp.lang.perl.misc (Greg Bacon)
To obfuscate or not? <cbarnett@idirect.com>
Re: To obfuscate or not? (Greg Bacon)
Re: Trying again... (Greg Bacon)
Re: What is First line in Perl5 in Sun Micro... <craig@mathworks.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Jun 1999 14:44:27 -0500
From: rlb@intrinsix.ca (Lee)
Subject: [Req:] Date::Abigail
Message-Id: <B394004B9668E2912D@204.112.166.88>
Have you considered making your date functions available to the great
unwashed masses? And may I request an update for WebTV time?
It seems that AOL was but playing John the Baptist to the new millenium of
WebTV, though it will never show strongly in the comp.* hierarchy.
Lee
------------------------------
Date: Mon, 21 Jun 1999 18:07:22 GMT
From: Ryan Corder <uucon@my-deja.com>
Subject: Re: cgi query error
Message-Id: <7klv0g$h42$1@nnrp1.deja.com>
Got it! I figure it out now :) thanx everyone for the help
ryan
In article <7kb5r9$mmi$1@nnrp1.deja.com>,
Ryan Corder <uucon@my-deja.com> wrote:
> In my browser, when i run a script using CGI.pm i get the following error:
>
> Software error:
> Can't call method "param" without a package or object reference at
> /home/domain/public_html/dwctest/upload.cgi line 124.
>
> this is line 124:
>
> if ($query->param) {
>
> this is the line to check if the form is submitted, right?
>
> any ideas?
>
> ryan
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 21 Jun 1999 14:14:31 -0500
From: rlb@intrinsix.ca (Lee)
Subject: Re: Cure for document deficiency
Message-Id: <B393F9479668E0EB2B@204.112.166.88>
In article <tgzp1twftc.fsf@noise.bsd.uchicago.edu>,
Darrin Edwards <d-edwards@uchicago.edu> wrote:
>abigail@delanet.com (Abigail) writes:
>
>>
>> Uri Guttman (uri@sysarch.com) wrote on MMCXIX September MCMXCIII in
>> <URL:news:x7r9n68x72.fsf@home.sysarch.com>:
>> ##
>> ## tom c. reciting the perl docs on tape or cd.
>>
>> In English, Spanish, French, German and Portuguese!
>>
>>
>> [Batteries not included]
>> [Void were prohibited]
>> [Costs more in Canada]
>> [5c value in DE]
>
>I'm happy to help with the Russian translation. :)
>Darrin
I can do the Icelandic, Gende, Biyom and Tok Pisin.
Also Old Norse and Gothic, although the pronunciation involves a bit of
guesswork.
Lee
------------------------------
Date: Mon, 21 Jun 1999 15:31:03 -0400
From: Mark Holmes <no.spammarkh@mailandnews.com>
Subject: Docs for cmdline switches - where?
Message-Id: <376E92F3.9AAB9CDD@mailandnews.com>
Where can I find documentation for Perl's command line switches?
I can't find this anywhere in the manpages or faqs. There are
scattered references (esp. for -w ;^) in the shipped docs but I
could see no official writeups for the switches shown on the very
first lines of perl.pod. I divined some like -d and -e but am
daring to want it all.
Also, I'm new to this NG and am wondering if y'all find it safe
to post with your real reply addresses? Do the spambots haunt us
here? I'll look in the group for any replies to this post, but
to reply directly remove 'no.spam' from my address. I have
somehow managed to keep this mailbox completely spam-free and
want to savor the moment! Thx,
Mark.
------------------------------
Date: 21 Jun 1999 19:34:59 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Docs for cmdline switches - where?
Message-Id: <7km453$gm6$6@info2.uah.edu>
In article <376E92F3.9AAB9CDD@mailandnews.com>,
Mark Holmes <no.spammarkh@mailandnews.com> writes:
: Where can I find documentation for Perl's command line switches?
% man perlrun
Greg
--
In my opinion MS is a lot better at making money than it is at making good
operating systems.
-- Linus Torvalds
------------------------------
Date: Mon, 21 Jun 1999 15:53:38 -0400
From: planb@newsreaders.com (J. Moreno)
Subject: Re: Fixed format fields: help needed!
Message-Id: <1dtr98v.36gpzdpecr0hN@roxboro0-0057.dyn.interpath.net>
Lee <rlb@intrinsix.ca> wrote:
> planb@newsreaders.com (J. Moreno) wrote:
>
> >Assuming input more like:
> >
> >12- .34- 456.0- 123-
> >
> >and this works better
> >s/( ?)(\d*\.?\d+)-/-$2$1/g;
>
> s/ ([\d.]+)-/-$1 /g
>
> will do. The initial 12-, if found, can't be repaired without breaking the
> format preservation spec.
It changes the placement but not the total field width, that was the
point of putting it in parenthesis.
> >Of course if I'm wrong about the possible input, then it's not any
> >better, and I should keep my mouth shut.
>
> Where's the fun in that?
:)
--
John Moreno
------------------------------
Date: Mon, 21 Jun 1999 18:28:34 GMT
From: vod@writemail.com
Subject: Help me compile cooledit on Redhat 5.2
Message-Id: <7km082$hm0$1@nnrp1.deja.com>
HI folks,
I am trying to compile cooledit on my machine and having trouble.
I do ./configure.
But when i do make it gives the following error.
I have gtk1.2.3 and glibc etc. on my machine.
Could any explain what the error means and what could be th solution.
....
gcc -O2 -s -Wall -pipe -fomit-frame-pointer -I/usr/X11R6/include
-L/usr/X11R6/lib -o .libs/cooledit cooledit.o find.o editoptions.o
mancmd.o
options.o debug.o cooleditmenus.o shell.o mail.o complete.o manpage.o
percentsubs.o _coolpython.o ../widget/.libs/libCw.so -lX11 -Wl,--rpath
-Wl,/usr/local/lib
cooledit.o: In function serone_handler':
cooledit.o(.text+0x26): undefined reference to cgettext__'
cooledit.o(.text+0x62): undefined reference to cgettext__'
cooledit.o: In function uit_handler':
cooledit.o(.text+0xe6): undefined reference to cgettext__'
cooledit.o: In function et_next_hint_message':
cooledit.o(.text+0x1fa): undefined reference to cgettext__'
cooledit.o(.text+0x234): undefined reference to cgettext__'
cooledit.o(.text+0x2a0): more undefined references to cgettext__'
follow
make[2]: *** [cooledit] Error 1
make[2]: Leaving directory /usr/local/cooledit-3.10.0/editor'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory /usr/local/cooledit-3.10.0'
make: *** [all-recursive-am] Error 2
--regards--
--V0D--
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 21 Jun 1999 15:54:22 -0400
From: Carter Hamilton <carter@computer.org>
Subject: How do I delete lines from a file
Message-Id: <376E986D.B860900B@computer.org>
I am a beginner in PERL programming. None of the references I have
demonstrate how to remove lines from a file. What I am attempting to do
is open a text file, delete certain lines from the file, then close it.
Does anyone know how to do this?
Thanks,
Carter
------------------------------
Date: Mon, 21 Jun 1999 19:24:12 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: HOW DO I PAD A STRING IN PERL??
Message-Id: <37719092.5853360@news.demon.co.uk>
On Mon, 21 Jun 1999 18:42:24 GMT, nospam.newton@gmx.net (Philip 'Yes,
that's my address' Newton) wrote:
>On Sun, 20 Jun 1999 11:24:12 GMT, dave@dave.org.uk (Dave Cross) wrote:
>
>>Was there something in perlfaq4 - "How do I pad a string with blanks
>>or pad a number with zeroes?" that was unclear?
>
>This doesn't seem to be in my copy of perlfaq4 (5.005_02, ActiveState
>build 509).
Some versions of ActivePerl had a less than ideal documentation tree.
It's been fixed in the more recents versions so you could grab the
latest versnio fro the ActiveState site.
Alternatively, open the ActivePerl docs in your browser and find the
link for perlfaq. When this document opens in the right hand frame, do
whatever you need to do in your browser to get it in a frame by
itself. Now edit the location to open perlfaq4 rather than perlfaq and
you'll (hopefully) see that it *is* on your sytem - just very
effectively hidden.
hth,
Dave...
--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>
------------------------------
Date: Mon, 21 Jun 1999 12:45:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: HOW DO I PAD A STRING IN PERL??
Message-Id: <MPG.11d8363fe7d4fcd6989c0f@nntp.hpl.hp.com>
In article <376dd65c.259631658@news.nikoma.de> on Mon, 21 Jun 1999
18:42:24 GMT, Philip 'Yes, that's my address' Newton
<nospam.newton@gmx.net> says...
> On Sun, 20 Jun 1999 11:24:12 GMT, dave@dave.org.uk (Dave Cross) wrote:
>
> >Was there something in perlfaq4 - "How do I pad a string with blanks
> >or pad a number with zeroes?" that was unclear?
>
> This doesn't seem to be in my copy of perlfaq4 (5.005_02, ActiveState
> build 509).
Upgrade!
How do I pad a string with blanks or pad a number with zeroes?
(This answer contributed by Uri Guttman)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 21 Jun 1999 18:14:57 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7klvek$ha7$1@nnrp1.deja.com>
In article <7kf99o$jou$1@nnrp1.deja.com>,
armchair@my-deja.com wrote:
> > > First Perl strings were different than C++ strings,
> > > and now it is easy
> > > to write a C++ string that does the same thing.
> then we can throw out Perl's string as a feature that makes it a
> higher level language.
The difference is that Perl's strings are a built-in type.
> > > Are you suggesting
> > > that no current C++ string class does what a Perl string does?
> >
> > No.
>
> Great, then we can throw out Perl's string as a feature that makes it
a
> higher level language.
But you're missing the essential problem. There may be, somewhere,
a C++ string class that has the same features as Perl's strings.
It might even be in the STL. But it might not be. We can say for
sure that there are thousands (at least) different, mostly
incompatible string classes written in C++. Because strings are
not a built-in type. The ability to write a class that does this
or that in C++ doesn't make it a higher-level language than it is.
Part of being a HLL is having built-in types of greater abstractness
and power.
> You have to try and come up with some way that
> C source code is merely "portable assember".
No, I never claimed that "C source code" is "assembler" -- "portable",
"merely portable", or otherwise. I have very little to say about
"C source code". I was talking about the C language. And until
you apprehend the difference between "the C language" and "C source
code", this argument will be very fruitless indeed.
> Well then get back to the subject. We are talking about source code.
No we're not, despite your insistence to the contrary.
Source code is a very trivial thing.
Language design and implementation are what is interesting and
important.
> > > And we were comparing C++ and Perl source code,
> >
> > Not at the time the subject of the complexity of C++ came up.
>
> Yes we were. That's what was always being discussed - C++ versus Perl
> source code. Nothing more, nothing less.
You are so wrong.
> You happened to make some statements regarding C++ source code
I never made any statements about "C++ source code".
I made statements about the design and implementation of the C++
language, and how they relate to the design and implementation
of other languages.
> > And in fact I was never talking about "source code".
> > That seems to be your bailiwick.
>
> You were talking about it
You have misunderstood (intentially, I suppose) what I was talking
about.
> > > > $foo = bless {}, 'Foo'; # make an object of class Foo.
> > >
> > > class Foo {};
> >
> > It's true that objects have primacy over classes in Perl, which is
> > the opposite of C++.
>
> I don't know what this means. Can you give an example to illustrate
the
> point you are trying to make?
I thought the two examples above would have served as sufficient
illustration, but perhaps I overestimate your abilities.
In C++, you can have a class that has no instances;
the definition of the class is meaningful even when no instances
of it exist.
In Perl, you can have instances of a "class" even when no
definition for that class exists.
> How are Perl's classes more dynamic than C++'s?
In the same way that *everything* about Perl is more dynamic
than C++.
In the case of classes, they're more dynamic in Perl because the
inheritance tree, the member functions, and the data structures
can be defined and modified at run time.
Similarly, the class membership of an object can be modified
after its initial construction.
$o = bless {}, 'Foo'; # make an object of class Foo
bless $o, 'Bar'; # now it's an object of a different class
This can be useful if, for example, Bar is a descendent of Foo.
> So what does it do that you couldn't do in C++. Explain your benefit.
Catch calls to undefined methods, and map them into useful functions.
For example, if Foo has-a Bar, you might want any method calls on
a Foo object which are not defined subroutines to map to calls to
the corresponding function of the contained Bar. I.e.
sub Foo::AUTOLOAD {
my $self = shift;
# get the name of the method which found no definition:
my $name = $Foo::AUTOLOAD;
# the name is qualified, e.g. "Foo::googly",
# so remove the qualification:
$name =~ s/.*:://;
# call method of that name on the contained 'Bar' object:
$self->{'bar'}->$name( @_ );
}
$self->googly( @args );
will result in a call like
$self->{'bar'}->googly( @args );
(assuming no sub Foo::googly has been defined).
> "End of story" means "let's put an end to your story about why you
can't
> write the assembler equivalent to a C nested for loop
That story ended long ago, when I said was unwilling, not unable.
> > But the point, originally, was that C++ was so much
> > more complex than C because of this extra machinery. Not sure why
> > you find it so hard to believe.
>
> class a {
> private:
> int m_number;
> public:
> void SetNumber(int number) { m_number = number; }
> int GetNumber(void) { return m_number; }
> }
>
> That's why.
If you think that's all there is to it, then you have no inkling
of what the C++ compiler has to go through to make this code "work".
> > > Maybe you can get the Java creators to help
> > > you demonstrate the complexity of creating classes in C++.
> >
> > They would be more than happy to; simply go make this request
> > for info in comp.lang.java.
>
> No doubt because you intend to trail along and chime in
"No doubt"? You're more of an idiot than I supposed.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 21 Jun 1999 18:33:10 GMT
From: TC <tcthiel@athenet.net>
Subject: Perl Hash-DMB problem
Message-Id: <7km0h6$hq2$1@nnrp1.deja.com>
I'm using an Array, inside a hash, which is tied to a DBM file.
Is this even possible? The following is a short piece of code
that shows the problem:
#!/usr/local/bin/perl
dbmopen (%TEST, "/usr/local/bin/test", 0644) || die "Cannot Open.\n";
$TEST{"A"}=[1,2,5];
$value = $TEST{"A"}[2];
print "VALUE is $value\n";
$hash{"A"}=[1,2,5];
$value=$hash{"A"}[2];
print("VALUE is $value\n");
The output I get is: VALUE is
VALUE is 5
Where, I should get 5 for both. It's like the dbm file doesn't
understand how to store the array in the hash. Is this a known problem?
Thanks in advance, -Todd
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 21 Jun 1999 14:14:03 -0500
From: Sunitha <nsunitha@cse.unl.edu>
Subject: perl help
Message-Id: <376E8EFA.1D1AE7F@cse.unl.edu>
Hi:
I am new to perl and am trying t dynamically create a hash table
from values from a file.
Scenario: i am reading from a file
Name:Marks is the contents
tommy:10
sunitha:0
I have been able to do this:
I am reading line by line.Splitting the line for name and marks.
so, $name, $marks has the respective values.
I am unable to do this:
now, i want to create a hash-table of values.
%marksheet where names is the key and marks is the value.
Each value of name and marks read from the file.
I want to be able to answers queries like
what is the marks of sunitha?
$marksheetr{"sunitha"}
Please advise.
Thanks and Regards
sunitha
------------------------------
Date: 21 Jun 1999 19:34:08 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: perl help
Message-Id: <7km43g$gm6$5@info2.uah.edu>
In article <376E8EFA.1D1AE7F@cse.unl.edu>,
Sunitha <nsunitha@cse.unl.edu> writes:
: I am new to perl and am trying t dynamically create a hash table
: from values from a file.
On behalf of comp.lang.perl.misc, I bless you a thousand times over for
not wanting to have $tommy = 10 and $sunitha = 0. :-)
: Scenario: i am reading from a file
: Name:Marks is the contents
:
: tommy:10
: sunitha:0
:
: I have been able to do this:
:
: I am reading line by line.Splitting the line for name and marks.
: so, $name, $marks has the respective values.
Something like the following?
my($name,$marks);
while (<MARKS>) {
chomp;
($name,$marks) = split /:/;
$marksheet{$name} = $marks;
}
: I am unable to do this:
:
: now, i want to create a hash-table of values.
: %marksheet where names is the key and marks is the value.
: Each value of name and marks read from the file.
I guess your code is different from mine. How are you reading in the
data?
: I want to be able to answers queries like
: what is the marks of sunitha?
Using the code above, $marksheet{sunitha} would yield the number of
sunitha's marks.
Greg
--
Politically Correct term: 'G(g)od(dess)(es)'
-- The Bruns
------------------------------
Date: Mon, 21 Jun 1999 12:03:48 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: JDDemme <jddemme@technologist.com>
Subject: Re: Perl tutorial
Message-Id: <376E8C94.7411D2BA@mail.cor.epa.gov>
[courtesy cc to poster]
JDDemme wrote:
>
> I'm too cheap to buy a perl book, so does anybody know of a really good
> perl tutorial. More than just CGI and files. more that what
> www.cgi-101.com has.
You might start with:
http://www.netcat.co.uk/rob/perl/win32perltut.html
and then move on to the *real* tutorial: the docs on your
machine. Type 'perldoc perl' at a command prompt, and you'll
get a list of the manpages, and a good order in which to read
them.
Then check out Tom Christiansen's FMTEYEWTK series of
tutorials (available from CPAN among others), and the
http://reference.perl.com page.
By then you'll be a successful, wealthy Perl programmer
with groupies hanging all over you. At that point, pony
up the dough and buy some of the O'Reilly Perl books.
You won't want those Perl-groupies to think you're cheap.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 21 Jun 1999 19:05:15 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Perl tutorial
Message-Id: <7km2db$gm6$2@info2.uah.edu>
In article <376E8295.52CFD687@technologist.com>,
JDDemme <jddemme@technologist.com> writes:
: I'm too cheap to buy a perl book, so does anybody know of a really good
: perl tutorial. More than just CGI and files. more that what
: www.cgi-101.com has.
% man perl
Greg
--
Why do they call it a "building"? It looks like they're finished. Why isn't
it a `built'?
-- Jerry Seinfeld
------------------------------
Date: 21 Jun 1999 19:04:18 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <7km2bi$gm6$1@info2.uah.edu>
In article <m1lnddtq9j.fsf@halfdome.holdit.com>,
merlyn@stonehenge.com (Randal L. Schwartz) writes:
: Usenet is a cooperative anarchy. I don't understand Abi's motivations
: for being uncooperative, but it means tools like Greg's have to catch
: up. :)
It's really just a heuristic, though. The software uses the regular
expression /^\s{0,3}(?:>|:|\S+>|\+\+)/ to match quotes. It doesn't
catch all quotes, and everything it catches isn't necessarily a quoted
line. I though about fixing it to catch Abigail's quoting (with
something similar to Tom's cfoq). To be honest, it's not important
enough to me. If Abigail would rather be on top of the OCR list than
the bottom, then I'm not going to get in her way.
Greg
--
Be warned that being an expert is more than understanding how a system is
supposed to work. Expertise is gained by investigating why a system doesn't
work.
-- Brian Redman
------------------------------
Date: Mon, 21 Jun 1999 15:04:39 -0400
From: "Carey Barnett" <cbarnett@idirect.com>
Subject: To obfuscate or not?
Message-Id: <376e8cc8@diana.idirect.com>
I've noticed posts to newbies with code that is not as readable as it could
be. Some of it is downright cryptic: So... should we, or shouldn't we?
Terse, and thereby cryptic, code used to save bytes and speed in the
executable, so... Does terse Perl save processing time? It certainly isn't
required with modern compilers and other languages.
--
Carey Barnett
Systems.*
cbarnett@intheloop.com
www.intheloop.com
(416)465-4698 voice
(416)465-7769 fax
Toronto, Ontario,
Canada
M4M 3L1
------------------------------
Date: 21 Jun 1999 19:28:37 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: To obfuscate or not?
Message-Id: <7km3p5$gm6$4@info2.uah.edu>
In article <376e8cc8@diana.idirect.com>,
"Carey Barnett" <cbarnett@idirect.com> writes:
: I've noticed posts to newbies with code that is not as readable as it
: could be. Some of it is downright cryptic: So... should we, or
: shouldn't we?
It depends on the intent. If someone is being annoying, sometimes
people will give a cryptic or misleading answer (sometimes both! :-).
If the intent is to be pedagogical, then one might want to water the
code down a little. On the other hand, there's a lot to be learned
(especially with Perl) by staring at a code snippet and figuring out
how it works. On the third hand, if they want Pascal, they know where
to find it. :-)
Still, you have to be careful. There are those among us who are so
filled with self loathing that they accuse people of being obfuscatory
when the alleged deviants are merely writing in Native Perl. Don't fall
victim to the lie that coding a certain way will make your code more
legible to {C,Pascal,Lisp,FORTRAN,COBOL,BCPL,PL/I,...} hackers.
: Terse, and thereby cryptic, code used to save bytes and speed in the
: executable, so... Does terse Perl save processing time? It certainly isn't
: required with modern compilers and other languages.
Perl hackers like to play Perl Golf (fewest strokes wins!) with each
other because it's fun and not because the code will necessarily run
faster. Perl Golf is also a way to start Yet Another Benchmark War. :-(
Greg
--
A lot of people mistake a short memory for a clear conscience.
-- Doug Larson
------------------------------
Date: 21 Jun 1999 19:21:14 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Trying again...
Message-Id: <7km3ba$gm6$3@info2.uah.edu>
In article <376e120b.232518403@24.0.3.71>,
portboy@home.com (Mitch) writes:
: sub read_config
: {
: my $cfg = shift;
: open(CFG, $cfg) or die "damn't $!";
: while(<CFG>) {
: chomp;
: s/#.*//;
: s/^\s+//;
: s/\s+$//;
: next unless length;
: my ($var, $value) = split ' ', $_, 2;
: #$config{$var} = $value;
: ++$config{$var};
Good style dictates that you indent the body of a loop.
: close(CFG);
Why are you closing the file in the body of your loop?
: return;
: }
You have a syntax error: you're missing a right curly.
: while (($var, $value) = each(%config)) {
: print "$var : \n";
: while (($key2,$value2) = each (%{$config}))
: {
: print "\tthe var is $key2 and value is $value2\n";
: }
: }
What is thist %$config business? Is there something you're not telling
us?
Here's a program that works more or less as I think you expect:
#! /usr/bin/perl -w
use strict;
use Carp;
my %config;
sub read_config {
my $cfg = shift;
local $_;
open CFG, $cfg or croak "$0: failed open $cfg: $!";
while(<CFG>) {
chomp;
s/#.*//;
s/^\s+//;
s/\s+$//;
next unless length;
my($var, $value) = split ' ', $_, 2;
#$config{$var} = $value;
++$config{$var};
}
close(CFG);
}
read_config "file";
my($var,$value);
while ( ($var,$value) = each %config) {
print "$var: $value\n"
}
: All of these are simply the variable names...So, being that I am kind
: of braindead and learn better from looking at examples (of stuff that
: will work for me), how can I print out what the settings for coke,
: pepsi, and pass are. Also, how can I add another coke variable like:
:
: coke bites
Assuming you want only one value with each keyword:
sub read_config {
my $cfg = shift;
local $_;
open CFG, $cfg or croak "$0: failed open $cfg: $!";
while(<CFG>) {
chomp;
s/#.*//;
s/^\s+//;
s/\s+$//;
next unless length;
my($var, $value) = split ' ', $_, 2;
$config{$var} = $value;
}
close(CFG);
}
If you want to associate an array of values with each keyword, change
$config{$var} = $value;
to
push @{ $config{$var} }, $value;
and use this to print it
my($var,$value);
while ( ($var,$value) = each %config) {
print "$var: [", join("][", @$value), "]\n";
}
: At the same time, how can I check to see if coke bites already exists?
You could use
if (exists $config{coke}) { ... }
or
if ($config{coke} eq 'bites') { ... }
depending on what you want to do.
Hope this helps,
Greg
--
Politically Correct term: 'G(g)od(dess)(es)'
-- The Bruns
------------------------------
Date: Mon, 21 Jun 1999 15:41:16 -0400
From: Craig Ciquera <craig@mathworks.com>
Subject: Re: What is First line in Perl5 in Sun Micro...
Message-Id: <376E955C.B5C5358E@mathworks.com>
Dave Cross wrote:
> It really depends where Perl has been installed on your system. It's
> impossible for anyone here to know. Best you ask your system
> administrator.
which will tell you where Perl is. If its there at all.
Here is the output on my machine
% which perl
/usr/local/bin/perl
Craig
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 6080
**************************************