[7327] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 952 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 30 18:07:15 1997

Date: Sat, 30 Aug 97 15:00:30 -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           Sat, 30 Aug 1997     Volume: 8 Number: 952

Today's topics:
     Re: #include?! <rootbeer@teleport.com>
     Better than Soundex <david@telekinesys.co.uk>
     Re: changing dir of parent shell (Andrew M. Langmead)
     Re: having a Perl script time out (Your Name)
     Re: How do I create a directory and then create a direc <snaider@galcom.co.il>
     Re: MAIL question <snaider@galcom.co.il>
     Re: New to the business! <rootbeer@teleport.com>
     Re: New to the business! (John Stanley)
     Re: perl and XEmacs (Randy J. Ray)
     Re: PROB: conditional test always true. <rootbeer@teleport.com>
     Problem with win32 system() function (Nim Chu)
     Re: Question about arrays. (Andrew M. Langmead)
     Re: Questions about passing by reference. <rootbeer@teleport.com>
     Re: split() on an empty string (M.J.T. Guy)
     Statistics for comp.lang.perl.misc <gbacon@cs.uah.edu>
     What's wrong with my 'if' statement? <raggmopp@ix.netcom.com>
     Re: What's wrong with my 'if' statement? <rra@stanford.edu>
     Re: Win32::EventLog problem <dave@turfpit.demon.co.uk>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 30 Aug 1997 08:23:34 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ryan Rose <ryanr@poolpros.com>
Subject: Re: #include?!
Message-Id: <Pine.GSO.3.96.970830081651.23053J-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Ryan Rose wrote:

> Newsgroups: comp.lang.perl.tk

[ I don't think you meant to post to c.l.p.tk; these sound like questions
for c.l.p.misc instead. Followups set. ]

> I'm looking to set up a file with my commonly used sub routines, and
> constants etc...

Use 'require', documented in the perlfunc(1) manpage.

> I read that I could do this just like in C by stating
> 
> #include "whatever.file"

That can be made to work, but its use is discouraged.

> However, I have had nothing but trouble.. 

 ...which is why its use is discouraged, so that the programmer won't also
become discouraged.  :-) 

> also, should the begining of the file I am trying to include also have
> the #!/usr.local/bin/perl header?!? 

It usually doesn't make any difference. In the few cases where it does
matter, you'll want it to be there.

Have fun with it!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/




------------------------------

Date: Sat, 30 Aug 1997 16:04:01 +0100
From: David Greaves <david@telekinesys.co.uk>
Subject: Better than Soundex
Message-Id: <34083661.DE714FEB@telekinesys.co.uk>

Hi
I'm after an algorithm thats better than Soundex at generating keys for
words in spoken language (ascii/western encoding) documents.

I'm also interested in language/rule based stuff like removing 'ing' so
that word stems can be created: (handling->handl) <> handle :(

Does anyone know anything about this?
References... gratefully received.

Thanks in advance

David

PS if you reply to the group and cc me, I'd be grateful as, like many, I
don't read that often.


------------------------------

Date: Sat, 30 Aug 1997 15:41:40 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: changing dir of parent shell
Message-Id: <EFqGxH.H09@world.std.com>

Les Schaffer <godzilla@futuris.net> writes:

>How do i get a perl script to change the directory i was just in to another one. 

It (easily) can't be done. See <URL:http://www.perl.com/CPAN/doc/
manual/html/pod/perlfaq8/I_changed_directory_modified_m.html> for
details. (Or if you have a current version of perl, it is distributed
with the package. It is also posted to comp.lang.perl.misc and
comp.lang.perl.announce periodically and since it is posted with an
Expires header, it should be around all of the time. I would think
that it should also be crossposted to news.answers and comp.answers,
but for some reason, it doesn't seem to be.)


>when i had unpack written as a bash script, i could go

>/home/foo: > . unpack
>   [ blah blah blah ] 
>/home/foo/bar: >

>is there an equivalent for perl?

Note when you say ". something" in bash, you are not doing anything
different in the script, you are telling bash to execute it
differently. (To parse and run the script in the current processes,
rather than to create a child process.) Unfortunatly, bash doesn't
understand perl syntax, so that is no way that bash could execute a
perl script in its process.

Now you could arrange (via a shell alias, function or something) to
have bash run another program, have the other (perl or any other)
program do something to tell bash where it would like the directory
changed to (like maybe print it out to a file) and have bash change
there once it is done. If you have problems with the perl part, (how
to output a name of a directory for some other program to read.) let
us know, and we can see if we can help. For the shell part, (how to
have a program really be a sequence of steps.) you're better off
asking in a newsgroup that deals with shells.

-- 
Andrew Langmead


------------------------------

Date: 30 Aug 1997 20:09:58 GMT
From: username@shore.net (Your Name)
Subject: Re: having a Perl script time out
Message-Id: <5u9umm$gn2@fridge-nf0.shore.net>

In article <Pine.GSO.3.96.970826104907.13463K-100000@julie.teleport.com>, 
rootbeer@teleport.com says...
[deletion]
>> Now I'm having a problem as follows, which goes like
>> 
>> while(<STDIN>)
>>     {
>>     do stuff;
>>     last if /^blah/);
>>     }
>> some other stuff;
>> exit;
>> 
>> After a while of running this server, I find a lot of processes hanging
>> for hours, even though the actual script takes a few milliseconds.
>
>That might happen if the STDIN is coming through a pipe, blocked because
>the process at the other end of the pipe is slow. If you can get the 
other
>process to not buffer output, that could help. Or you could use
>non-buffered, non-blocking reads, via sysread.
>
>> Is there any way I can 'time out' these scripts so they exit if X
>> seconds has passed out? 
>
>Yes, with an alarm. But since signals aren't (yet) reliable in Perl, the
>only thing you could really do is some quick, simple cleanup and exit.
>
>  while () {                    # Infinite loop
>    $SIG{ALRM} = sub { die "Timeout!" };
>    alarm 100;                  # Die after 100 seconds
>    last unless defined($line = <STDIN>);
>    alarm 0;                    # Turn off the alarm clock
>    # Process $line...
>  }
>
>Hope this helps!

One approach I've used is to fork before calling the process, then wait
for the child. If the child does not return - via wait() - after a 
$RESONABLE_TIME, I have the option of killing it...

Rick



------------------------------

Date: Sat, 30 Aug 1997 17:05:06 +0300
From: Daniel Schnaider <snaider@galcom.co.il>
To: Drake Raft <drake-@email.unc.edu>
Subject: Re: How do I create a directory and then create a directory within that directory?
Message-Id: <34082892.FDA530F5@galcom.co.il>

Drake Raft wrote:

> #!/usr/local/bin/perl
> mkdir(etc,"/etc1/etc2")
>
> I'm looking to create a directory named etc2 within a directory named
> etc1, but this doesn't seem to work.  How would I go about doing this?
>
> Do I create one, and then somehow switch into it?
>
> Please email me at mcgucken@physics.unc.edu if you know how I might do
>
> this.  Thanks a lot, Elliot

   If etc1 doesn't exist you need to create it first before you want to
create an etc1 subdirectory.
If it something that should make some times... Just write a function
that receive a string and build all the directorys automatic for you.
It is very easy...
Have fun and good luck,

Daniel



------------------------------

Date: Sat, 30 Aug 1997 17:11:27 +0300
From: Daniel Schnaider <snaider@galcom.co.il>
To: Burt Lewis <burt@ici.net>
Subject: Re: MAIL question
Message-Id: <34082A0F.623C5D63@galcom.co.il>

Burt Lewis wrote:

> Hi,
>
> I'm using this bit of code which works nice:
>
> $youmail = 'burt@ici.net';
> open (MAIL, "|$mailprog $youmail");
>
> Question is, I can't seem to add additional receipients to this, it
> only
> seems to work with one.
>
> Any help on this is appreciated.
>
> Thanks!
>
> Burt Lewis
> www.eastonmass.com

   I am not sure that your question were understood...
You would like to concat to $youmail variable another string... and
that's possible. Just add in the end ---> ,mail@somewhere.com

Good Luck and have fun,

Daniel



------------------------------

Date: Sat, 30 Aug 1997 08:06:50 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Joe Mosby <steve@mosby1.force9.net>
Subject: Re: New to the business!
Message-Id: <Pine.GSO.3.96.970830075154.23053H-100000@julie.teleport.com>

On Sat, 30 Aug 1997, Joe Mosby wrote:

> @Info = split(/:/, $formdata{'message'});        # Split the message on
> the colon
> @PrivateTest = split(/ /, $Info[0]);                  # Split the text
> before thecolon
> if($PrivateTest[1]) {                                       # Check to
> see if there is more than one

That's actually not a very good test to see whether there's more than one
word before the colon - if the second word is the single character '0', it
will be fooled. (And if the user uses two spaces between the first and
second word, likewise.) If you don't need to have @PrivateTest for some
other reason, you might be able to use a simple regular expression. 

And I think you've noticed by now that having lines longer than about 72
columns can make them hard to read... :-)

> &Normal;                                                      # word
> before the colon. If there is, do the
> }                                                                   #
> Normal sub-routine
> else {
> &Private;                                                       #
> Otherwise do the private
> }
> 
> sub Private {
> $Recieve = $Info[0];                          # The person the message
> is to is before the colon

In general, it's better for subroutines to be passed parameters and to use
only lexical ("my") variables. Otherwise, before you can use a new
variable $foo, you have to check the entire program's text to make sure
that you haven't used that name already. But Perl lets you use globals -
even though they're slower. :-)

> $Message = $Info[1];                         # The message is after the
> colon
> $Sender = "$formdata{'handle'}";       # The sender is the name the
> person chose first
>
> if($formdata{'handle'} eq "$Reciever") {                  # If the users
> name eqs the $Recieve

Those double quotes are merely misleading, here and in other places.

> print "($Sender whispered to you) $Message";         # scalar print the
> senders name and
> }
> # message
> 
> elsif($formdata{'handle'} eq "$Sender") {                # If your name
> eqs the
> print "(You whispered to $Reciever) $Message";     # $Sender scalar.
> Print who you sent
> }
> # The message to and you message
> 
> else
> {                                                                      #
> If neither of the above are true,
> print "$Sender is whispering";                                  # Just
> print the users name and tell
> 
> }
> # the room they are talking privately
> }

This would be easier to read if it were normally indented. The
perlstyle(1) manpage has some advice on that sort of thing.

>     Now I am pretty certain that there is more than one thing wrong with
> this script. 

Me, too! :-)

> I would appreciate it if you could set me straight. 

Are you saying that there's also something functionally wrong with this
code, in that it doesn't do what you're wanting? There are many functions
which I don't see in this code, such as code to print the CGI headers, or
code to send these messages to the right people. If the problem is that
those lines of code are missing, the solution is to put them in. :-) 

> P.S If the above routine goes wrong when you recieve the E-Mail or
> something, I have attached a file with comments and routine to this
> mail.

Speaking only for myself, the attachments were less convenient than if
you'd simply written plain text. I had to take extra steps to be able to
respond in this way.

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: 30 Aug 1997 19:24:49 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: New to the business!
Message-Id: <5u9s21$so9@news.orst.edu>

In article <34081A22.9A40DAEF@mosby1.force9.net>,
Joe Mosby  <steve@mosby1.force9.net> wrote:
:This is a multi-part message in MIME format.

This is USENET. Please post text. 

:--------------4038213B33CF166FA3E78927
:Content-Type: multipart/alternative; boundary="------------F9F53ACE9CB4EF2F4B446F35"
:
:--------------F9F53ACE9CB4EF2F4B446F35
:Content-Type: text/html; charset=us-ascii
:Content-Transfer-Encoding: 7bit
:
:<HTML:
:Okay,&nbsp;&nbsp;&nbsp; Sorry about the vague description of what I wanted
:yesterday.

You posted it once in simple text. Exactly what reason is there to post
the same message AGAIN in HTML? Please don't. 

:<BR:@PrivateTest = split(/ /, $Info[0]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

Here's the problem. &nbsp is an undefined function. 

:<BR:}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

You managed to get more than 400 characters packed into that one line.
Please keep them to 80 or shorter.

:--------------4038213B33CF166FA3E78927
:Content-Type: application/x-unknown-content-type-cgi_auto_file; name="private.cgi"
:Content-Transfer-Encoding: base64
:Content-Disposition: inline; filename="private.cgi"
:
:QEluZm8gPSBzcGxpdCgvOi8sICRmb3JtZGF0YXsnbWVzc2FnZSd9KTsgICAgICAjIFNwbGl0
:IHRoZSBtZXNzYWdlIG9uIHRoZSBjb2xvbg0KQFByaXZhdGVUZXN0ID0gc3BsaXQoLyAvLCAk
:SW5mb1swXSk7ICAgICAgICAgICAjIFNwbGl0IHRoZSB0ZXh0IGJlZm9yZSB0aGVjb2xvbg0K

I am now in favor of prohibiting such articles. 




------------------------------

Date: 30 Aug 1997 15:43:49 -0600
From: rjray@tremere.ecte.uswc.uswest.com (Randy J. Ray)
Subject: Re: perl and XEmacs
Message-Id: <uowyb5jl52i.fsf@tremere.ecte.uswc.uswest.com>

>>>>> "Jamie" == Jamie Zawinski <jwz@netscape.com>
>>>>> wrote the following on Mon, 25 Aug 1997 21:10:03 -0700

  Jamie> I wrote:
  >>  [ the perl language sucks for these reasons ]

  Jamie> Randy J. Ray wrote:
  >>  [ yeah, well Netscape sucks too! ]

  Jamie> You know, that tactic of changing the subject, and trying to
  Jamie> direct criticisms away from the area that you like and over
  Jamie> into a totally unrelated area that you don't like, is really
  Jamie> only marginally better than comparisons to Hitler.  (Have I
  Jamie> invoked Godwin's Law yet?)

  Jamie> What, I ask, has Netscape Navigator got to do with Perl?

It doesn't, and the aspects of perl we are discussing have nothing to do with
any emacsen, either. And yet the thread persists. I've added
comp.lang.perl.misc, and removed alt.religion.emacs. I've left in
comp.emacs.xemacs, since that is where this seems to have started, and where
people following it are likely to look.

Yes, it was wrong to redirect the argument from Perl to Netscape, but the
real argument I was making was more along the lines of the validity of you
painting Perl so negatively, when I've never seen your name on anything in
any of the Perl newsgroups, or any patches or bugreports. Richard Stallman
once shared with the Tcl and Perl newsgroups why he thought those languages
were dead-ends, and what we all *should* be using was a Scheme-based scripting
language that FSF was designing. Well, the validity of any points he might of
made were lost in the negative feedback that resulted. I have no problems 
accepting the skill and reputation of developers such as yourself and Stallman.
What I have a problem with is wholesale condemnation of a language or paradigm
without any real concession to possible strengths. Throughout this thread, you
list the same complaints over and over, while people respond that those
features are in fact what they like about Perl, or make Perl useful to them.
Your stock reply to these have been, "You're wrong anyway."

  Jamie> I suppose you're making the assumption that because I had
  Jamie> something to do with Netscape, I'm obviously incapable of
  Jamie> having a reasonable opinion about anything.  Guess what,
  Jamie> that's not how it works in the real world.

Never made that assumption. What I was implying, however, is that there is
irony in your criticism of Perl as the "wrong" solution to the problem set it
addresses, when there are critics just as vocal who feel the same way towards
Netscape. That invalidates opinions from neither of us.

  Jamie> I'm very, very sorry.  It must really suck to be you.

  >>  Well, I was going to keep this "debate" fairly civil, but if you
  >> wish to resort to sniping, I'd say working for Netscape and
  >> criticising other software as "brain-dead" must really define
  >> "living in a glass house".

  Jamie> I was not sniping.  I think maybe you don't understand what
  Jamie> "it must suck to be you" means.  It means, "I'm really glad I
  Jamie> don't have your job."  It means, "your job sounds unpleasant
  Jamie> in the extreme."  It is no reflection on you.  It is about
  Jamie> your *task*.

  Jamie> For reference, it very often really sucks to be me.

Maybe I don't think that it sucks to be me? Maybe if I'm not 100% satisfied
with what I do, it has less to do with the Perl aspect than some other factor.
In that context, it sounded as if your were being petty. The medium does some-
times fail to transmit subtlety.

  Jamie> If Perl gets you through the day, great; more power to you.
  Jamie> But as a language, and as an application platform, it still
  Jamie> sucks.

  >>  Compared to what? C?

  Jamie> AGAIN, it doesn't have to be compared to *anything*.  Just
  Jamie> because A is better than B, doesn't mean that A is good.

And again, because *you* don't like it doesn't mean that it really does in
fact suck. There are a lot of people out there besides me writing commercial-
grade code in Perl not because it's the only choice, but because they chose
it out of a pool of several options. That's the point I keep trying to make;
If you don't like Perl for goodness' sake don't use it. Even for the tasks
you admit it is good for, you can surely find an alternative that works
reasonably as well. But your wholesale criticism of Perl in particular and the
Perl programming community in general has no grounding; Your like or dislike
does not make a tool "suck" any more than mine makes it "right". But I'm not
telling you, "No, you're wrong. Read the Perl book again." If you don't like
it, fine.

  Jamie> I claimed Perl's syntax is obscure, and encourages bad style.

  Jamie> I *will* claim that it is obscure compared to *any* of those
  Jamie> languages (and saying that any language is more obscure than
  Jamie> C++ is fairly harsh, in my opinion.)

But that is not an attribute of Perl, that's an attribute of poor programming
style. I suppose in terms of clarity, the best language would be COBOL, given
the wordiness of it. There are other languages that force more strict structure
and style, I suppose.

  Jamie> I brought that up as an example of why things like Perl and C
  Jamie> are *realisitically* the things that one has to use,
  Jamie> *regardless* of how unpleasant they are to use and maintain,
  Jamie> and *regardless* of the fact that they are inferior on this
  Jamie> metric or that.

But the unpleasantness of use, maintainability, and relative inferiority on
any given scale are subjective measures. Personally, I'm a very exacting,
attentive-to-detail sort of person. Usually, my sort is called anal-retentive.
I may not always have the best code solution to a problem, but what I write is
in general damned easy to read and maintain. That's a function of *me*, not
C or Perl or Lisp or COBOL. You can write Perl that reads like human language,
and you can write English that cannot be read. The aspect is not in the
language it is in the person whose hands compose.

  Jamie> Practicality and cleanness of design have little to do with
  Jamie> each other.  In fact, in most cases, they're at odds.  This
  Jamie> is what "Worse Is Better" is all about.

This line of reasoning crosses over more into Software Engineering than any
particular language or environment. I personally think that they can co-exist,
but this would be a completely different branch of conversation, only 
marginally related to the trunk.

  >> Yes, the regex engine is one of the strongest features. I'd much
  >> rather do any form of data processing in Perl than Lisp.

  Jamie> *Any* form?  There's that hammer-and-nail thing again.

  Jamie> For *most* forms of data processing, I'd much rather use any
  Jamie> language with clear syntax, and automatic storage management.
  Jamie> And that's about as big a generalization I'd want to make
  Jamie> without knowing a lot more particulars about the task in
  Jamie> question.

No, between Perl and Lisp only, I'd prefer Perl for any sort of data 
processing. With more choices than those two, I'd continue to select the
best tool for the job.

  Jamie> Regexps are clear as mud.  They have many things to recommend
  Jamie> them, but clarity is not one.

  Jamie> The heavy use of regexps in Perl is due to them being far and
  Jamie> away the most obvious hammer in the box.

  Jamie> The heavy use of regexps in Emacs is due almost entirely to
  Jamie> performance issues: because of implementation details, Emacs
  Jamie> code that uses regexps will almost always run faster than
  Jamie> code that uses more traditional control structures.

  Jamie> Based solely on how lame the syntax is, and how generally
  Jamie> unmaintainable regexp-based code is, Perl would be very close
  Jamie> to the bottom of my list of choices for most tasks.

A lot of aspects of programming are clear as mud. CPU timing issues on
multi-user servers, resource race conditions, etc. Lots of things about
home construction are clear as mud, too, if that's your vocation. Regular
expressions have evolved in the field of programming to give a consistent (if
obfuscated) method to approaching a certain problem set. Are regex's hard to
read? Yes. Does Perl improve this? No. Could it? I doubt it, though some
people have experimented with object classes to abstract some of the regex
noise. Perhaps you are associating Perl's syntax too closely with the general
syntax of regular expressions. Any language that has support for regular
expressions is going to be subject to the syntactic challenge associated with
them. Even if you are using re_comp() and re_exec() (or equivalent) in C.

Imagine that a task has no need for regular expressions. What aspect of Perl's
syntax will still be so troublesome as to have you resist using it?

  Jamie> Yet, I sometimes write programs in Perl.  Why?  Because in
  Jamie> those situations, issues of portability, speed of
  Jamie> development, footprint -- whatever -- outweighed the other
  Jamie> issues.  Tradeoffs get made.  Everything gets popped off of
  Jamie> the list until Perl is the best option left.  And sometimes
  Jamie> it sucks to be me.

And we all continue to use tools that we don't necessarily like, if those are
the best tools for the job. Maybe I should be more vocally critical of the
tools I think are badly designed, but since I don't have the time to write
replacements, I just shrug it off and make do. Which is what it sounds like
you do, as well. But this vehement argument against Perl just doesn't serve
any purpose unless you are also prepared to offer sound alternatives. As I
said before (and this is an analogy, *not* an effort to redirect *sigh*), I
don't like Netscape. But I wouldn't run Internet Explorer even if I were on a
Win32 box. So until I can offer an alternative (preferably someone else's),
I'll limit my criticism of Netscape to bugs that can theoretically be 
addressed.

  >> Maybe programmers with less experience take simplistic
  >> approaches; that doesn't make a language itself bad.

  Jamie> Actually, I think it does!  A good language encourages good
  Jamie> style, readable code, and proper use of tools.  A good
  Jamie> language helps build good programmers by making common
  Jamie> operations easy to understand, and uncommon operations
  Jamie> possible.

I disagree. It is not the job of the tool to make the person using it
proficient. It is the responsibility of the person to develop proficiency
with the tool. A car cannot make a bad driver good. Buying the finest quality
paints and brushes will not make a bad artist better. And using a language
with complete clarity of syntax and no room for ambiguity will not make a
bad programmer better. You can see bad LOGO, bad Forth, anything. I have
seen SmallTalk code that was almost obvious in form and function, and I
have seen SmallTalk that made Perl look crystal clear. The language does
not make the programmer.

Randy
-- 
===============================================================================
Randy J. Ray -- U S WEST Technologies IAD/CSS/DPDS         Phone: (303)595-2869
                Denver, CO                                     rjray@uswest.com
"It's not denial. I'm just very selective about the reality I accept." --Calvin


------------------------------

Date: Sat, 30 Aug 1997 08:26:44 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Robert Dickow <dickow@uidaho.edu>
Subject: Re: PROB: conditional test always true.
Message-Id: <Pine.GSO.3.96.970830082400.23053K-100000@julie.teleport.com>

On 30 Aug 1997, Robert Dickow wrote:

> Newsgroups: comp.lang.perl.tk

[ I think you meant to post this to c.l.p.misc instead. Followups set. ]

>   if ( $foo == 'somethingelse' ){

Not using warnings (-w) are you? :-)  You're using a numeric comparison on
a string; to find out what to do next, see the perlop(1) manpage or the
other dozen replies you'll get about this. :-) 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: Sat, 30 Aug 1997 22:47:13 GMT
From: nimchu@hal-pc.org (Nim Chu)
Subject: Problem with win32 system() function
Message-Id: <5u9teq$puo$1@news.hal-pc.org>

After installing perl for win32 on a win95 system, everything seems to
work fine, including the debugger. However the following perl codes:

system("dir");
print "Error_msg=",$!;

gives the error message:

Error creating cmd file (2)
Error_msg=cannot find file or directory

At first, I thought perl cannot find the command.com. I check that
there it is in the c:\windows directory and the env var PATH includes
c:\windows and c:\windows\command and f:\from_net\perl\bin
directories. I also check @INC array (likely this has nothing to do
with the problem), it includes:
f:\from_net\perl\lib
 .
That is where the perl system is installed. I appreciate any help to
solve this problem.



------------------------------

Date: Sat, 30 Aug 1997 15:10:57 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Question about arrays.
Message-Id: <EFqFI9.6FI@world.std.com>

nigelr@convex.hp.com (Nigel Reed) writes:

>For example.

>Andy,1,6,5,3,6
>Andy,5,6,3,5,2
>Bill,5,3,1,4,6
>Bill,6,7,3,3,1
>Ted,1,5,9,7,5
>Tom,4,5,6,2,1

>I need to end up with an array like this
>Andy,6,12,8,8,8
>Bill,11,10,4,7,7
>Ted,1,5,9,7,5
>Tom,4,5,6,2,1


>And so on. Has anyone already written a routine to do this?
>(The file is already pre-sorted alphabetically) and I can easily
>read in the file in perl, it's just the code to produce the
>new array )

I doubt anyone has anything pre-written, because most of the work
would be unique to your record format. It would be hard to make a
generic framework that would work for every case. Maybe what you want
is something like this:

while(<>) {
  ($name, @scores) = split /,/;
  for($i = 0; $i < @scores; $i++) {
     $list{$name}[$i] += $scores[$i];
  }
}

for $name (sort keys %list) {
   print(join(",",$name, @{ $list{$name} }),"\n");
}

(Note: Most of this is taken care of by a hash containing references
to arrays, or a "hash of lists". For more info, see the perlref,
perldsc, and perllol man pages.)

The only drawback to this is that it keeps all of the records in
memory until the file is read completely, where it could print a
record (and release or reuse the memory it occupies) as soon as the
first field  changes.


$current_name = '';
while(<>) {
  ($new_name, @record_scores) = split /,/;

  # if this is a different key than the one in the last record,
  # print total stats of the old key and reset the data.
  if($new_name ne $current_name and $current_name ne '') {
      print join(",",$current_name, @total_scores),"\n";
      @total_scores = ();
  }

  # fill in the data from the current record.
  $current_name = $new_name;

  for($i = 0; $i < @record_scores; $i++) {
     $total_scores[$i] += $record_scores[$i];
  }
}

# all through with data, dump out whatever we have left.
print join(",",$current_name, @total_scores),"\n";
-- 
Andrew Langmead


------------------------------

Date: Sat, 30 Aug 1997 08:15:25 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter de Vroomen <peterv@valkieser.nl>
Subject: Re: Questions about passing by reference.
Message-Id: <Pine.GSO.3.96.970830080906.23053I-100000@julie.teleport.com>

[ Stop! You've posted this at least three times! :-)  Also, the copy which
I got by email didn't indicate that it was also posted; with that
information, I wouldn't have replied privately and then again in the
newsgroup. ]

On Sat, 30 Aug 1997, Peter de Vroomen wrote:

> It seems I didn't read far enough, because it turns out the big
> difference between local and my variables is just the scope :-)). 

In one sense, their scope is the same. But to me, the big difference
is their implementation.

> I just have to accept that a reference is just some kind of pointer into
> a symbol-table, that makes things a lot easier.

Actually, globs are pointers into a symbol table. Reference may point to
something in a symbol table or not. (my() variables aren't in a symbol
table, but you can have references to them.)

> It seems Perl variables never get cleaned up (maybe they
> do when Perl finds out there's no reference to them altogether). 

That's it; when there are zero references, they're cleaned up. This has
the big advantage that there's never a pause for a garbage collection
cycle (like lisp does) but it has the disadvantage that you need to
explicitly break any circular references to prevent memory leaks. That's
not usually a problem.

> So if you have a reference, the thing the reference points to is allways
> valid. 

Right. There's no (normal) way to have a broken reference, so you can't
accidentally (or intentionally) dereference arbitrary memory locations. 

Take another look through the perlref(1) manpage, and I think it'll make
more sense to you now. Have fun!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: 30 Aug 1997 16:12:48 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: split() on an empty string
Message-Id: <5u9gq0$83h$1@lyra.csx.cam.ac.uk>

Ken Williams <ken@forum.swarthmore.edu> wrote:
>There's a behavior that I don't like in the split() function, and seems to
>contradict the documentation (from new Camel book):
>
>  "If the PATTERN doesn't match at all, split() returns the original
>string as a 
>   single substring."
>
>Here's where that's not true:
>
> @array = split(/not_here/, '');
>
>The result: @array is set to (), rather than ('') as the above statement
>would indicate.
>
>I know that split() is a funny function with lots of exceptions to its
>rules, but I can't find any documentation that explains this one.  I would
>really like it if this bug were fixed (or feature taken away), because as
>the function is now, it necessitates special cases in my code.

Here is the documentation, taken from  `perldoc -f split':

                                   If LIMIT is unspecified, trailing null
fields are stripped (which potential users of pop() would do well to
remember).  If LIMIT is negative, it is treated as if an arbitrarily large
LIMIT had been specified.

So the second sentence tells you that you should write

  @array = split(/not_here/, '', -1);

to get the effect you want.   No special cases.


Mike Guy


------------------------------

Date: 30 Aug 1997 18:27:00 GMT
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: Statistics for comp.lang.perl.misc
Message-Id: <5u9olk$e70$1@info.uah.edu>

Following is a summary of articles spanning a 7 day period,
beginning at 23 Aug 1997 09:51:28 GMT and ending at
30 Aug 1997 06:24:29 GMT.

Notes
=====

    - A line in the body of a post is considered to be original if it
      does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
    - All text after the last cut line (/^-- $/) in the body is
      considered to be the author's signature.
    - The scanner prefers the Reply-To: header over the From: header
      in determining the "real" e-mail address and name.
    - Original Content Rating is the ratio of the original content volume
      to the total body volume.
    - Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
    - Find the NewsScan junkyard at http://www.cs.uah.edu/~gbacon/clpm/

Excluded Posters
================

perlfaq-suggestions@mox.perl.com

Totals
======

Total number of posters:  447
Total number of articles: 1107 (455 with cutlined signatures)
Total number of threads:  434
Total volume generated:   1792.0 kb
    - headers:    761.6 kb (15,251 lines)
    - bodies:     944.1 kb (30,311 lines)
    - original:   652.8 kb (21,961 lines)
    - signatures: 83.4 kb (1,944 lines)
Original Content Rating: 0.6914

Averages
========

Number of posts per poster: 2.5
Number of posts per thread: 2.6
Message size: 1657.6 bytes
    - header:     704.5 bytes (13.8 lines)
    - body:       873.3 bytes (27.4 lines)
    - original:   603.8 bytes (19.8 lines)
    - signature:  77.2 bytes (1.8 lines)

Top 10 Posters by Number of Posts
=================================

         (kb)   (kb)  (kb)  (kb)
Posts  Volume (  hdr/ body/ orig)  Address
-----  --------------------------  -------

  144   254.5 (127.1/ 95.6/ 58.8)  Tom Phoenix <rootbeer@teleport.com>
   31    59.9 ( 16.7/ 38.4/ 29.3)  Greg Bacon <gbacon@CS.UAH.Edu>
   30    40.5 ( 19.4/ 19.7/ 11.4)  Tom Grydeland <tom@mitra.phys.uit.no>
   28    39.9 ( 19.0/ 20.9/ 11.6)  Doug Seay <seay@absyss.fr>
   17    27.8 ( 10.3/ 17.4/ 10.2)  Jeremy D. Zawodny <jzawodn@wcnet.org>
   15    23.6 (  9.1/ 14.5/ 11.4)  Rael Dornfest <rael@zx81.dnai.com>
   14    19.4 ( 10.0/  9.4/  5.0)  petri.backstrom@icl.fi
   14    19.4 (  7.3/ 11.8/  8.6)  Andrew M. Langmead <aml@world.std.com>
   12    21.9 (  7.5/ 14.4/  9.9)  Tad McClellan <tadmc@flash.net>
   12    20.3 (  7.6/ 12.7/  9.4)  M.J.T. Guy <mjtg@cus.cam.ac.uk>

Top 10 Posters by Volume
========================

  (kb)   (kb)  (kb)  (kb)
Volume (  hdr/ body/ orig)  Posts  Address
--------------------------  -----  -------

 254.5 (127.1/ 95.6/ 58.8)    144  Tom Phoenix <rootbeer@teleport.com>
  59.9 ( 16.7/ 38.4/ 29.3)     31  Greg Bacon <gbacon@CS.UAH.Edu>
  40.5 ( 19.4/ 19.7/ 11.4)     30  Tom Grydeland <tom@mitra.phys.uit.no>
  39.9 ( 19.0/ 20.9/ 11.6)     28  Doug Seay <seay@absyss.fr>
  27.8 ( 10.3/ 17.4/ 10.2)     17  Jeremy D. Zawodny <jzawodn@wcnet.org>
  23.6 (  9.1/ 14.5/ 11.4)     15  Rael Dornfest <rael@zx81.dnai.com>
  21.9 (  7.5/ 14.4/  9.9)     12  Tad McClellan <tadmc@flash.net>
  20.3 (  7.6/ 12.7/  9.4)     12  M.J.T. Guy <mjtg@cus.cam.ac.uk>
  19.4 ( 10.0/  9.4/  5.0)     14  petri.backstrom@icl.fi
  19.4 (  7.3/ 11.8/  8.6)     14  Andrew M. Langmead <aml@world.std.com>

Top 10 Posters by OCR (minimum of five posts)
==============================================

          (kb)    (kb)
OCR       orig /  body  Posts  Address
------  --------------  -----  -------

1.0000     0.8 /   0.8      5  nick@wireedm.com
0.8498     5.7 /   6.7      6  Anagrams of the Word 'A' <jefpin@bergen.org>
0.8320     2.7 /   3.2      5  Michael Schuerig <uzs90z@uni-bonn.de>
0.7843    11.4 /  14.5     15  Rael Dornfest <rael@zx81.dnai.com>
0.7632    29.3 /  38.4     31  Greg Bacon <gbacon@CS.UAH.Edu>
0.7629     8.2 /  10.7      9  Terry Michael Fletcher - PCD ~ <tfletche@pcocd2.intel.com>
0.7424     7.1 /   9.6      5  faust@wwa.com
0.7421     9.4 /  12.7     12  M.J.T. Guy <mjtg@cus.cam.ac.uk>
0.7236     8.6 /  11.8     14  Andrew M. Langmead <aml@world.std.com>
0.7229     5.2 /   7.1      8  Ronald L. Parker <ron@farmworks.com>

Bottom 10 Posters by OCR (minimum of five posts)
=================================================

          (kb)    (kb)
OCR       orig /  body  Posts  Address
------  --------------  -----  -------

0.5664     4.1 /   7.3     10  Josh Purinton <joshp@silmaril.com>
0.5626     7.0 /  12.5      8  Jot Powers <news@bofh.com>
0.5578     1.0 /   1.7      6  chip@pobox.com
0.5551    11.6 /  20.9     28  Doug Seay <seay@absyss.fr>
0.5356     5.0 /   9.4     14  petri.backstrom@icl.fi
0.4725     1.5 /   3.1      6  Martin Fischer <mf@fishbone.ruhr.de>
0.4550     2.1 /   4.6      6  abigail@fnx.com
0.4520     2.2 /   4.8      5  dmouse <gt1535b@acmez.gatech.edu>
0.4300     3.0 /   6.9      7  David Efflandt <efflandt@xnet.com>
0.3706     1.8 /   4.8      7  Tom Fawcett <fawcett@nynexst.com.spam-me-not>

Top 10 Threads by Number of Posts
=================================

Posts  Subject
-----  -------

   14  'abandon' hope (was: Re: Need help: how to exit a sub)
   12  When to use "use strict"
   12  Help on Final Exam (Perl class)
   12  cardinality of an array given a reference
   11  help displaying a large number with commas
   11  Returning a hash list (associative array)
    9  [Q] Awk's "s in A" Hash Test In Perl?
    8  Bizarre result with regex in -i -pe
    8  Perl Regular Expression has a bug?
    8  Easy Question: Dont Care.

Top 10 Threads by Volume
========================

  (kb)   (kb)  (kb)  (kb)
Volume (  hdr/ body/ orig)  Posts  Subject
--------------------------  -----  -------

  26.3 (  8.5/ 16.8/  8.8)     12  When to use "use strict"
  24.7 ( 12.3/ 11.3/  7.0)     14  'abandon' hope (was: Re: Need help: how to exit a sub)
  23.2 ( 10.1/ 11.8/  6.9)     12  cardinality of an array given a reference
  21.5 (  8.6/ 12.2/  7.2)     12  Help on Final Exam (Perl class)
  19.8 (  7.4/ 11.2/  7.8)     11  Returning a hash list (associative array)
  18.6 (  4.6/ 13.3/  8.1)      7  <> operator memory leak?
  16.2 (  4.6/ 11.3/  4.0)      6  Building a (very?) complex data structure....
  16.2 (  7.2/  8.1/  4.7)      8  Wrong status from system() in child process ?
  15.2 (  2.7/ 12.3/ 10.7)      4  Perl (kind of) math question.
  14.6 (  7.9/  6.7/  3.9)     11  help displaying a large number with commas

Top 10 Targets for Crossposts
=============================

Articles  Newsgroup
--------  ---------

      35  comp.lang.perl.modules
      16  comp.lang.perl
       8  comp.lang.perl.tk
       7  microsoft.public.inetserver.iis
       6  comp.security.unix
       6  comp.unix.solaris
       6  comp.security.ssh
       5  comp.sys.hp.hpux
       3  alt.fan.e-t-b

Top 10 Crossposters
===================

Articles  Address
--------  -------

       6  Ramon Castillo <ramon@ramonc.icix.net>
       4  Scott Henry <scotth@sgi.com>
       4  Mark Harrison <mark@purple.tmn.com>
       4  John D Groenveld <groenvel@cse.psu.edu>
       4  Guido van Rossum <guido@eric.cnri.reston.va.us>
       4  Jiri Koutnik <koutnik@pdb.pdb.bnl.gov>
       4  Shaun Flisakowski <flisakow@fontina.cs.wisc.edu>
       4  Mike Drons <Michael_Drons@ins.com>
       4  chris abraham <chris@purple.tmn.com>
       3  SJK <knetsch@golden.net.no.spam>


------------------------------

Date: Sat, 30 Aug 1997 13:10:32 -0600
From: Rick Garland <raggmopp@ix.netcom.com>
Subject: What's wrong with my 'if' statement?
Message-Id: <34087028.15621203@ix.netcom.com>

Greetings all:

I am an admitted newbie to perl (programming in general) and I have come
across an issue I cannot seem to solve. This is on Perl 5.002.

The script I'm trying to complete is below;

   print ("Please enter the user login to disable:\n");
   $disablelogin = <STDIN>
   $disablelogin =~ s/^\s+|\s+$//g;

   @login = <PW>:
   @line = grep(/^disablelogin/, @login);
   $retval = @line;

   ...

   open (PW)		|| die "Can't open $PW: $!\n";
   open (NPW, ">NPW")	|| die "Can't create $NPW: $!\n";

   while (<PW>) {
      if ($retval == /^1/) {
         ($name,$pw,$uid,$gid,$comment,$home,$shell) =
getpwnam($disablelogin);
         s/:$pw:/:*:/;
	 print NPW;
      } else {
         print ("\n\t$disablelogin NOT FOUND\n");
      }
   }

   system("mv $NPW $PW");
   ...

   close PW;
   close NPW

The problem is when I add the 'if' statement to a while loop. (It works
fine, but there is no way to tell the user that a $disablelogin does not
exist or there is incorrect typing.) If the $disablelogin is correct the
script will work correctly. If a non-existing $disablelogin is input,
the PW file becomes larger and incorrect info is added to the PW file.
Also, the $retval seems incorrect; it produces '0' no matter what value
@line has.

(Parts of the script has been omitted for brevity.)

Any help is greatly appreciated.


Rick
raggmopp@ix.netcom.com


------------------------------

Date: 30 Aug 1997 14:49:32 -0700
From: Russ Allbery <rra@stanford.edu>
To: Rick Garland <raggmopp@ix.netcom.com>
Subject: Re: What's wrong with my 'if' statement?
Message-Id: <m390xjbatv.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

Rick Garland <raggmopp@ix.netcom.com> writes:

> I am an admitted newbie to perl (programming in general) and I have come
> across an issue I cannot seem to solve. This is on Perl 5.002.

I'd recommend upgrading if you can.  Lots of bugs have been fixed since
5.002.

>    while (<PW>) {
>       if ($retval == /^1/) {

This isn't at all what you want to do.  What this line is doing is
performing a regular expression match against the current contents of $_
and seeing if they match /^1/ (something starting with a 1).  It then
takes the result of that match, which is going to be either 1 or ''
depending on whether $_ begins with a 1, and comparing them to $retval
numerically.

That's not even close to the same thing as checking if $retval is 1, which
is what I *think* you wanted to do.  Try:

        if ($retval == 1) {

If you *really* wanted to check to see if $retval begins with a 1 (which
is sort of odd, given your code, but ah well), do:

        if ($retval =~ /^1/) {

(Note the ~ there.)

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


------------------------------

Date: Sat, 30 Aug 1997 20:50:01 GMT
From: "David Richards" <dave@turfpit.demon.co.uk>
Subject: Re: Win32::EventLog problem
Message-Id: <01bcb586$307bb4f0$0101010a@turfpit>

Sorry - Should be 

 http://www.inforoute.cgs.fr/leberre1/

> 
> for excellent and accurate Eventlog & Registry documentation for Perl for
> Win32.
> 
> David 
> 
> > Build 306) on my WinNTW4 system and I an experiencing an error 
> > in the EVENTLOG.PM module. The following program:
> >     Open Win32::EventLog( $EventLog, $LogName, $ComputerName );
> > 
> > produces the following error:
> > 
> >     Modification of a read-only value attempted 
> >       at D:\PERL\LIB\WIN32\EVENTLOG.PM line 81.
> 
> 


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 952
*************************************

home help back first fref pref prev next nref lref last post