HDTenEightyP/NetNews huggingface dataset:
From: watson@carssdf.UUCP (- Self Empl. Sys.Integrator)
Newsgroups: comp.lang.perl
Subject: Re: how to 'write' cr-nl
Date: 1 Sep 92 17:41:20 GMT
Reply-To: watson@carssdf.UUCP (John Watson -- Self Empl. Sys.Integrator)
Organization: John Watson (Self Employed System Integrator)

In article <ASHERMAN.92Sep1091415@laser.fmrco.com> asherman@fmrco.COM writes:
>
>>>>>> watson@carssdf.UUCP (- Self Empl. Sys.Integrator) said:
>
>watson> Is there an easy way to write CR-NL at the end of the lines
>watson> instead of just "\n".  Sort of like  $\ = "\r\n", except make
>watson> it apply to the write statement?
>
>What's wrong with:
>
>format STDOUT =
>@<<<<<<<<<<<<<<<<<< Test: @>>>>>>>>>>>> ^M
>.

My problem here, besides forgeting to put it in on a line or two, and
creating a debugging mess is possibily

entering spaces after the ^M which are not visible by the vi editor,
creating leading white space on the next line.

With all the printers that don't cr on nl, I just thought there must be
some easy way to do this correctly.

John Watson
Newsgroups: comp.lang.perl
From: lahtinen@gideon.fmi.fi (Kimmo Lahtinen)
Subject: aub and ISC perl 4.019?
Organization: Finnish Academic and Research Network Project - FUNET
Distribution: comp
Date: 31 Aug 92 07:02:20 GMT

I would like to know if it possible to get aub to work with
ISC 3.0 and perl 4.019. I got a fix from Mr. Mark Stantz
and now it compiles but it does not like to talk to our nntp server.

I think I have met similar problems with other programs also,
so I wonder if something is wrong. Or is aub working only with
BSD-type machines. 

--
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Kimmo Lahtinen                      E-Mail : lahtinen@gideon.fmi.fi       
Finnish Meteorological Institute    Phone  : +358 0 758 1322
Possessed by a Spirit               G3 Fax : +358 0 758 1396
From: meyering@cs.utexas.edu (Jim Meyering)
Newsgroups: comp.lang.perl
Subject: portability of chat2.pl from 4.035
Date: 29 Aug 92 22:53:49 GMT
Organization: U of TX at Austin CS Dept
NNTP-Posting-Host: ai.cs.utexas.edu

I've been experimenting with chat2.pl from perl-4.035 and came
across a minor portability glitch.  chat2 has this header:

    ## chat.pl: chat with a server
    ## V2.01.alpha.7 91/06/16
    ## Randal L. Schwartz

The problem is that it assumes stty sets characteristics of its
standard output.  On some systems (e.g. some system V and POSIX)
stty sets characteristics of the input tty.

Here's a patch that worked for me (using the POSIX-compliant stty
from GNU shellutils-1.7 on a Sun4 running SunOS 4.1.1).

--- chat2.pl.~1~	Sat Aug 29 17:40:12 1992
+++ chat2.pl	Sat Aug 29 17:39:58 1992
@@ -323,7 +323,7 @@
 			($tty = $pty) =~ s/pty/tty/;
 			open($_TTY,"+>$tty") || next;
 			select((select($_TTY), $| = 1)[0]);
-			system "stty nl>$tty";
+			system "stty nl<$tty >$tty";
 			return ($pty,$tty);
 		}
 	}
-- 
Jim Meyering             | Member of the League for Programming Freedom
meyering@cs.utexas.edu   | Contact me or league@prep.ai.mit.edu for more info.
From: lwall@netlabs.com (Larry Wall)
Newsgroups: comp.lang.perl
Subject: Re: Using Gotos?
Date: 25 Aug 92 20:40:23 GMT
Distribution: comp
Organization: NetLabs, Inc.

In article <DAVE.92Aug25182357@pipi.iis.u-tokyo.ac.jp> dave@pipi.iis.u-tokyo.ac.jp (David Wuertele) writes:
: P.S. I have been equating "next LABEL;" with GOTO, perhaps mistakenly.
: Please flame if I'm being naive.

OK, prepare to be crispy crittered.  :-)

The generic "goto" has been rightly condemned as obfuscatory.  You really
have no idea where the label is, or whether you're jumping into the middle
of some other control flow that would be better off without your presence.
It's trivial using goto to write a control flow that is too complicated
to think about except when high on Jolt Cola (and maybe not even then).

By contrast, certain customary uses of goto (and goto-like constructs)
are easy to understand because they don't violate the shape of the
control flow, but merely short-circuit it.

In the early days of structured programming, one stated goal was that
every block should have only one entry and one exit.  This is half
right.  Or perhaps twice right.  Every block *should* have only one
entry.  But the one-exit idea is bogus, because most logical branch
structures are in fact tree structures, and not linear.  A block needs
to categorize things, and once it has categorized things, it's more or
less done.  It shouldn't be forced to uncategorize things again.

There is implicit recognition of this in a language like C.  Notice
that the "return" statement can be used anywhere in a subroutine.
There is also the notion of "returning" from the current iteration of a
loop (via "continue") to start the next iteration, and "returning" from
the loop as a whole (via "break") for some reason that wouldn't have
been apparent at the top of the loop.  In real life, many control
structures are tree-shaped, so many loops have multiple (valid!) exits
or short-circuit conditions.

Perl just takes this notion one step further than C, by allowing you to
exit or short-curcuit a named loop.  Note however that, unlike with
goto, you KNOW that you're passing control out to an enclosing
construct.  That fact, together with the fact that Perl encourages you
to use meaningful loop labels, lets you write near-English statements
such as:

    next LINE if /^$/;		# skip blank lines
    next LINE if /^#/;		# skip comment lines

    last FILE if /^end$/;	# reached logical end of file

This is much better even than some proposed C extensions that would let
you specify how many levels you're breaking (as in "break 2").  The
Perl construct maps better onto your mental constuct of what you're
iterating over.  You don't have to count enclosing blocks, or even find
the block label.  You already know it, presuming you named it sensibly.

So there's a good reason you can't rewrite the "findword" example easily:
I'm such a lazy critter that I already did it the easy way!  :-)

Larry
From: lwall@netlabs.com (Larry Wall)
Newsgroups: comp.lang.perl
Subject: Re: fast way to get number of elements in an assoc array?
Date: 28 Aug 92 19:39:15 GMT
Organization: NetLabs, Inc.

In article <ASHERMAN.92Aug27111710@laser.fmrco.com> asherman@fmrco.COM writes:
: Remember, arrays in a scalar context USUALLY return the number of
: items that they contain. 

Close.  I'd say something like, operators that return lists in array
context, when evaluated in a scalar context, USUALLY return the number
of items they would have returned in the array context.

This is often the most useful scalar behavior when you don't know the
number of elements.  But for some operators that return a *known*
number of elements (or none on failure), it's more useful to return a
scalar value derived from one or more of the potential list values.
(As a familiar example, the C comma operator is required to return the
last value.  You might not think of the comma operator as having a
known number of return values, and it doesn't in general, but it does
in *specific* (usually).  It's not often that you type a list of items
into a program only to find out how many there are.  You can see that
just by looking at it.)

If you like general rules, here's another one:  If the array context
would have elicited a null list, the scalar context will elicit a
false value.  So ideally there should rarely be any logical (Boolean)
difference between

    if ($foo = some_operator) {

and

    if (($bar) = some_operator) {

But there's no guarantee that $foo and $bar get the same value.  It all
depends on what some_operator thinks is most useful in a scalar context.
As in English, every Perl verb has its own valence.  But there are patterns.

Larry
From: rod@isi.edu (Rodney Doyle Van Meter III)
Newsgroups: comp.lang.perl
Subject: C cross referencer (was Re: locsym)
Date: 27 Aug 92 05:32:03 GMT
Reply-To: rod@venera.isi.edu (Rodney Doyle Van Meter III)
Organization: Information Sciences Institute, Univ. of So. California


Certainly a marvelously useful tool; I was doing it literally
yesterday. If only I'd been caught on netnews :-).

The next tool I'm looking for is a C cross referencer that will
handle ANSI syntax.  Perl is the obvious choice for writing
such a tool; has anyone done it?  I invested about two hours
in an extremely primitive one myself, but I don't want to
reinvent the wheel if somebody has designed and written one
already.

It needs to be fairly robust in the case of incomplete code;
I like to use it as I'm writing. cxref supplied w/ SunOS
barfs on my ragged code, and can't handle ANSI.

Pointers to a freely available one in any language are okay,
though Perl is the obvious choice.

		--Rod
From: csa@sw.stratus.com (Chris Arthur)
Newsgroups: comp.lang.perl
Subject: help!
Date: 2 Sep 92 01:45:10 GMT
Organization: Stratus Computer, Inc.

I'm having a problem getting things like %{$var} and ${$var}{$stuff}
to work (I'm not sure what you would call that).  When I run the
following:

$a = "x.c";
${$a} = "hello";
@{$a} = (one, two, threeeee);
%{$a} = (a, apple, b, banana, c, cherry);
print defined (@{$a}) . "\n";
print ${$a} . "\n";
print ${$a}[2] . "\n";
print ${$a}{"a"} . "\n";
$dnt = $a;
print ${$dnt}{"b"} . "\n";
$dnt = "x.c";
print ${$dnt}{"c"} . "\n";

I expect to see:

1
hello
threeeee
apple
banana
cherry

but I get two blank lines instead of banana and cherry.  Am I doing
something wrong or silly, or is this a bug?  (Maybe both. :-)

						chris

-- 
Interface copyrights and software patents will devastate the software
industry.  Join the LPF (mail to league@prep.ai.mit.edu for more info).
Newsgroups: comp.lang.perl
From: Dov Grobgeld <dov@menora.weizmann.ac.il>
Subject: select misses pending data on socket
Reply-To: dov@menora.weizmann.ac.il
Organization: The Internet
Date: Mon, 31 Aug 1992 20:19:31 GMT

Fellow other Perl hackers,

I tried rewriting the client program of the Camel book to use select (with
four arguments) instead of the fork. What I did was to replace the lines

    # Avoid deadlock by forking.

    if($child = fork) {
        while (<STDIN>) {
    	print S;
        }
        sleep 3;
        do dokill();
    }
    else {
        while(<S>) {
    	print;
        }
    }

with the lines

    # This version uses the select call to find out if there is data pending

    $rin = $win = $ein = "\000";
    vec($rin,fileno(S),1) = 1;
    vec($ttyin,fileno(STDIN),1) = 1;
    $rin |= $ttyin;

    print "fileno(S)=", fileno(S), "\n";
    print "fileno(STDIN)=", fileno(STDIN), "\n";
    print "rin=",unpack("b*", $rin),"\n";
    $timeout=1;

    while (1) {
        $nfound = select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
        print "rout=",unpack("b*", $rout),"\n";

        if (vec($rout,fileno(S),1)) {
            $_=<S>;
            print;
        }
        if (vec($rout,fileno(STDIN),1)) {
            $_=<STDIN>;
            print S;
        }
    }

and the rest of the client (i.e. the opening socket part) being the same.

As a trial server I use my lokal SMTP deamon. I connect without any
problems and I get the SMTP greeting message. I type "HELO" on STDIN
and I get a line in return. So far so good. The problem arises when I
enter a command which gives a multi-line answer in return. I type
"help" and I get only the first two lines of the help message in return.
Only when I give an additional carriage-return from stdin do I get
the remaining 4 lines of the "help" return message. The error is not
reproducible, sometimes I get three or four lines before it gets stuck,
and sometimes it only gets stuck the 2nd time I write "help".

The print line of $rout shows that select reports that there is no data
to be read on the socket. How can that be?

The original client program shows no such behaviour. I immediately get
the whole return message.

My system is Perl 4.035 running on AIX 3.1.5 . I tried the script on
an HP9000/820, HPUX 8.05 with Perl 4.019 and got the same behaviour.

--
                                                        ___   ___
                                                      /  o  \   o \
Dov Grobgeld                                         ( o  o  ) o   |
The Weizmann Institute of Science, Israel             \  o  /o  o /
"Where the tree of wisdom carries oranges"              | |   | |
                                                       _| |_ _| |_
                                       
Newsgroups: comp.lang.perl
From: ejk@ux2.cso.uiuc.edu (Ed Kubaitis - CCSO)
Subject: Re: Perl language formatting conventions?
Organization: University of Illinois - Urbana
Distribution: comp
Date: Tue, 25 Aug 1992 17:22:17 GMT

Tom Christiansen <tchrist@convex.COM> writes:
  
  |A friend of mine would like to see a style guide for Perl code 
  |similar to the BSD KNF (Berkeley's Kernel Normal Form), which is
  |actually pretty much what I (and Larry) seem to use.  I'm actually
  |trying to develop this, but it's not ready for publication yet.

Although a minority in the Unix/C world, some of us have been indenting 
the trailing block delimiter the same amount as the block (instead of 
popping it out) since PL/I. I suppose the aesthetics of this style are 
more obvious with the typographically massive 'END;' of PL/I or Fortran
77's ENDIF & CONTINUE than with the minimal '}' of C and Perl, but we have 
been consistent in carrying a reasonable style forward through the years
(decades actually;-)

We despair of winning any converts from the style used in K&R (The C 
Programming Language), but we hope the Perl style guide is as tolerant
in this regard as K&R themselves:

     The position of braces is less important; we have chosen one
     of several popular styles. Pick a style that suits you, then
     use it consistently.

The second edition adds one clause:

     The position of braces is less important, >>>although people hold 
     passionate beliefs<<<. We have chose one of several popular...

For the widest acceptance the style guide probably shouldn't rush in 
where K&R feared to tread;-)

----------------------------------
Ed Kubaitis (ejk@ux2.cso.uiuc.edu)
Computing & Communications Services Office - University of Illinois, Urbana
Newsgroups: comp.lang.perl
From: dhami@cs.ubc.ca (Mandeep S Dhami)
Subject: > easy question?: substrings
Keywords: unpack,hex
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
Date: Wed, 26 Aug 92 23:14:00 GMT

From budnick@ihspa.att.com:
> 
> All I want to do is to change a string in the format of either
> 	0xffffff00 or ffffff00 into the format
> 	of 255.255.255.0 
> 
> The part I'm having trouble w/ is splitting the ffffff00 string
> into an array of: ff ff ff 00.  After I do that I plan to
> change these array elements into decimal from hex and join
> with a ".".  But,  I can't find a good way to successively cut
> 2 chars from the ffffff00 string.
>  

Try -
$x="ffefab30";  # Or whatever way.
$y=join(".",grep($_=hex,unpack("a2a2a2a2",$x)));

Or to print -
print join(".",grep($_=hex,unpack("a2a2a2a2","ffefab30"))),"\n";

Mandeep.

--
__________________________________________________________________
"I'm very brave generally," he went on in a low voice:
"only to-day I happen to have a headache."
                                      -- Lewis Carroll
Newsgroups: comp.lang.perl
From: jgd@acl.lanl.gov (Jerry G. DeLapp)
Subject: Re: Avoiding intermediate variable
Reply-To: jgd@acl.lanl.gov
Organization: Advanced Computing Lab, LANL, NM
	<1992Aug21.003314.13443@odin.corp.sgi.com>
Date: Thu, 3 Sep 1992 21:51:40 GMT

>>>>> On 21 Aug 92 00:33:14 GMT, stantz@sgi.com (Mark Stantz) said:
Mark> Nntp-Posting-Host: sierra.corp.sgi.com

Mark> In article <MARK.MCINTOSH.92Aug20145545@sombrio.UVic.CA> Mark.McIntosh@engr.UVic.CA (Mark  McIntosh) writes:
>Someone out my location would like to avoid the intermediate variable
>in the following piece of code, assuming $y has been set to some value:
>
>       $tmp = $y;
>       $tmp =~ s/xy/zz/;
>       print $tmp;
>
>He wants to retain the value of $y for later use but use a modified
>version of it once - he won't need it later.  Is there a way to do
>this in Perl without using an intermediate variable?

Mark> 		print ((($junk = $y) =~ s/xy/zz/) ? $junk : $y);

Mark> 	should do the job.  You need those outermost parentheses, BTW.

Mark> 		print $junk if (($junk = $y) =~ s/xy/zz/);

Well, you can do it with an automagically generated variable a'la:

    sub foo {
        print ($_[0],zz,$_[1]);
    }
    $y='gortxyflort';
    &foo($y=~/(.*)xy(.*)/);
    exit;

or:

    $y='gortxyflub';
    $y=~/(.*)xy(.*)/;
    print $1,zz,$2;
    exit;

There's still an intermediate variable used here, but I'm assuming the user
objects to having to "invent" his own temporary variable. I've used the first
trick extensively in a package here where the first character of a pattern is
an optional single character switch, and the remainder is a pattern. Whenever
I call a subroutine which doesn't care about the switch, I put a pattern like

$var=~/^[abq](.*)/

in the argument list, and voila, the pattern is handed into the subroutine
sans the switch character, without destroying $var. This makes it easier to
code the subroutine, because I can concentrate on the data value I want to
manipulate, instead of worrying about the optional baggage.
--

Jerry G. DeLapp -- ACL System Scientist -- (505) 665-4531 <jgd@lanl.gov>
Computing beyond the Bleeding Edge -- The Advanced Computing Laboratory
Newsgroups: comp.lang.perl
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: Re: got a symlink checker/chaser for crontab?
Organization: Motorola Codex, Canton, Massachusetts
Date: Thu, 27 Aug 1992 15:32:57 GMT

I wrote:

>If it's an invalid symlink, you can lstat it, but you can't stat it.

>while (<>)
>{
     chop;          # <---- (oops!  you'll need this!) <-----
>    next unless lstat($_);
>    next unless -l _;
>    next if stat($_);
>    print "invalid symbolic link: $_ -> ",
>        (readlink($_) || "[can't readlink: $!]"), "\n";
>}

Michael.
Newsgroups: comp.lang.perl
From: faigin@aero.org (Daniel P. Faigin)
Subject: Re: coding style (was Re: Perl language formatting conventions?)
Organization: The Aerospace Corporation, El Segundo, CA
	<1992Aug25.214800.10825@netlabs.com>
	<1992Aug27.072110.24646@news.Hawaii.Edu>
	<1992Aug27.180029.19638@netlabs.com>
Date: Thu, 27 Aug 1992 22:15:58 GMT

On 27 Aug 92 18:00:29 GMT, lwall@netlabs.com (Larry Wall) said:

> You want religion, I got religion...

And you should never argue religion with the son of a preacher. :-)

Daniel

--
[W]:The Aerospace Corp. M1/055 * POB 92957 * LA, CA 90009-2957 * 310/336-8228
[Email]:faigin@aerospace.aero.org              [Vmail]:310/336-5454 Box#13149
   "You can't be a rationalist in an irrational world. It isn't rational!"
	       Dr. Rance, in Joe Orton's "What the Butler Saw"
Newsgroups: comp.lang.perl
From: lezz@merlin.dev.cdx.mot.com (Lezz Giles)
Subject: Re: What's wrong with system command?
Reply-To: lezz@merlin.dev.cdx.mot.com (Lezz Giles)
Organization: Motorola Codex, Canton, MA
Date: Wed, 26 Aug 1992 17:07:40 GMT

In article <BtK9vp.J79@acsu.buffalo.edu>, yli@acsu.buffalo.edu (Yanhong Li) writes:
|>I used a system command in the following perl script, to my suprise, the
|>print command was not executed, if I remove the system command, print will 
|>be executed, why? and how can I make the print command successful without
|>removing the system command?
|>
|>#!/usr/local/bin/perl
|>
|>open(LEX, "/imagesG/yli/G02.ex" );
|>
|>while(<LEX>){
|>
|>print $_;
|>
|>($word1, $word2)=split;
|>
|>system "/users/usps/yli/stem $word2";
|>
|>}
|>close LEX

I can't answer your question but I can suggest that you rewrite it slightly...

#!/usr/local/bin/perl

open(LEX, "/imagesG/yli/G02.ex") || die "Cannot open /imagesG/yli/G02.ex, $!";

while (<LEX>) {

print $_;      # or even just `print;`

($word1, $word2) = split;

$word2 || die "Unsplittable line at $.\n$_";

$retval = system "/users/usps/yli/stem $word2";

if (($retval >> 8) != 0) {
	die "Execution of /users/usps/yli/stem $word2 failed - $retval\n";
}

}

close LEX;

(sorry about the indentation!)  One of the major joys of perl (in my mind)
is that it is incredibly easy to add error-checking/handling.  In my experience
it has almost always proved worth-while adding as much error-checking as
possible even for short scripts - no program works first time, and comprehensive
error checking really helps you narrow down problems quickly.

Lezz "GIGO" Giles
Newsgroups: comp.lang.perl,comp.mail.sendmail
From: lwall@netlabs.com (Larry Wall)
Newsgroups: comp.lang.perl
Subject: Re: More #! stuff
Date: 25 Aug 92 22:19:32 GMT
Distribution: usa
Organization: NetLabs, Inc.

In article <BtI899.KJ2@world.std.com> dsb@world.std.com (David Boyce) writes:
: In article <1992Aug24.185939.19357@netlabs.com> lwall@netlabs.com (Larry Wall) writes:
: >Similar schemes have been proposed, but the difficulty with it (aside
: >from the fact that not all machines have /bin/env) is that a #! line
: >typically allows you only one argument, and you've already used it up
: >specifying perl.  It's like having to use up your three wishes to get
: >the genie out of the bottle.
: >
: >Larry
: 
:     When I write shell code, I always use (and recommend)
: 
: #!/bin/sh
: set -e
: 
:     rather than
: 
: #!/bin/sh -e
: 
:     because if you happened to run the script via "sh script",
: the second way would lose the flag, which could be dangerous in
: the case of -e. Does perl support anything like the
: set command? I can't find it, but I, at least, would
: like to have it for the reason cited above, as well as to
: obviate the second problem you mentioned.

Most of the options that make sense to set internally can be set
via the corresponding magical variable, e.g.

    $^I = ".bak";

is the same as

    -i.bak

(presuming you set it before you start using <>).

Many switches don't make sense once you've started compiling the
script, however.  In particular, -p, -n, and -a.  And yes, you
do lose these if you invoke perl directly.  I suppose I could make
perl pick those up from the #! line anyway...  Hmmm...

:     As for not every machine having /bin/env; this is true,
: but I think every *ix machine has env, and most of them in
: /bin. I didn't mean that it's the universal solution; just
: that there are probably many local-area networks in the world that
: can count on /bin/env existing across the board. I mean,
: when the alternative is 
: 
: #!/c/cad1/cad/perl/bin/perl
: 
: as it is in one company that I'm working for, I think using env
: is more portable!

Surely.  (Presuming of course, that /c/cad1/cad/perl/bin is in your
PATH.)  But the BSD machines I used to use didn't have /bin/env.  Now,
you may not consider them to be *ix, but it would seem that AT&T still
does...

Certainly, it's easy enough to write env in C if you don't have it.
(But, of course, if you have authority to install /bin/env, you can also
ln -s /c/cad1/cad/perl/bin/perl /usr/bin/perl.)

Larry
Newsgroups: comp.lang.perl
From: dhawk@netcom.com (David Hawkins)
Subject: Source for metaconfig?
Date: Thu, 03 Sep 92 14:40:31 GMT
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
Distribution: ca
Keywords: metaconfig source

In compiling perl I noticed that 'Configure' says to get metaconfig if
I want to make a similar script.  I haven't been able to find it on a
site in the US.  I tried the Canadian site that 'archie' gave me, but
it just has a text file saying to get it at apple - but I didn't find
it at apple.

Suggestions?  (I could try the uk site afterhours, I guess.)

later, david
--
David Hawkins    dhawk@netcom.com
All music jars when the soul's out of tune.  --  Miguel de Cervantes
Newsgroups: comp.lang.perl