HDTenEightyP/NetNews huggingface dataset:
From: forrie@morwyn.uucp (Forrest Aldrich)
Subject: Porting C programs to Perl (converting)
Keywords: conversion
Organization: Vision Graphics
			  Dover, NH
			  USA
Date: Thu, 12 Nov 1992 11:22:33 GMT
Summary: Seeking information on converting C progs to Perl

I'd like some information regarding the conversion of C programs
to Perl.

As I recently mentioned, I have a menuing/forms program which I
really like, but would prefer to have running under Perl.  I'd 
like some help/info about how to approach this.

Thanks,

Forrest

-- 
	   -----------	      Forrest Aldrich	      -----------
	   -------     morwyn!forrie@unhtel.unh.edu	  -------
	   ----						     ----
	   --	     VISION GRAPHICS --	Dover, NH - USA	       --
	   ------------------------------------------------------
From: chris@yen.IMSI.COM (Chris Payne)
Newsgroups: comp.lang.perl
Subject: Re: Partial RegExp's
Date: 10 Nov 92 16:28:49 GMT
Organization: Moore Capital Management
In-reply-to: chappell@symcom.math.uiuc.edu's message of 9 Nov 92 15:11:20 GMT
Originator: chris@yen


Maintaing search-state is also the desired approach for programs which
read in chunks because only chunks are available -- chat2 / expect,
for example.  This is also a big help for asynchronous programs which
want to match against several chunky streams simultaneously.

/c (chris@imsi.com)
Newsgroups: comp.lang.perl
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: Re: push/pop and memory management
Organization: Motorola Codex, Canton, Massachusetts
Date: Fri, 13 Nov 1992 17:19:00 GMT

majidi@rwja.umdnj.edu (Masoud Majidi) writes:

>Dear netters,

>I have a small perl code whose memory requirement was getting out of
>hand. After studying the code for a while I am convinced that push/pop
>is not working the way I expected. To prove the point I wrote a small
>program which does nothing but pushing and popping from an array:

>for (1 .. 10000)
>{
>	push (@ary, 13);
>	pop (@ary);
>}

>And I checked the memory allocated to this code before and after the
>loop. To my surprise there was more 2.5 Meg difference. Even if the pop
>calls don't free the space I still don't understand how pushing 10,000
>entries can increase the space by 2.5 Megs. I would appreciate it very
>much if somebody would explain the above behavior.

Try this:

for ($i = 1; $i <= 1000; $i++)
{
	push (@ary, 13);
	pop (@ary);
}

I think you'll find it uses much less memory.  The 1..1000 construct builds a
temporary array of 1000 elements, and then 'for' iterates on it.

Michael.
Newsgroups: comp.lang.perl
From: karrer@bernina.ethz.ch (Andreas Karrer)
Subject: Perl4.035 on a Convex
Keywords: suidperl mechanism, perl4.035, Convex
Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
Date: Thu, 12 Nov 1992 18:08:59 GMT


First a little history:

 - Up to ConvexOS 9.0, Convexen were vulnerable to the #!-setuid-script bug.
 - With 9.0, the kernel simply refused to execute scripts with the
   set[u|g]id bit set -- making suidperl unusable. I filed a problem
   report, and, lo and behold:
 - 10.0 made the kernel's behaviour upon encountering setuid script a
   boot-time parameter:
	0) 9.0 style (for the paranoid),
	1) pre-9.0 style (for those who use their convex as a PC)
	2) kernel passes the script to the interpreter, but ignores the
	   setuid bit.
   2) is what is needed for taintperl/suidperl to work.

It was certainly reassuring to see my own words printed in the release notes,
followed by a "Problem fixed". There _are_ vendors who react on user's
complaints. Thanks Convex!

However, when trying to run a setuid taintperl script with the perl4.010
supplied with 10.1, i get:

	% ./setuid-script
	Can't reswap uid and euid

Bummer.  The message comes from perl.c when it tries to invoke setreuid().

So i compiled 4.035 with:

	Any additional cc flags? [] -pcc

	Any additional libraries? [] -lnsl -ldbm -lm -lcrypt
		(Convex does not ship crypt.o in its libc.a anymore (intl.
		 version) so i put mine into /usr/local/lib/libcrypt.a)

	In config.sh, i set:
		groupstype='gid_t'              (was int)
		d_setregid='undef'              (was define)
		d_setreuid='undef'              (was define)

	The last two are neccessary for suidperl to work. Convex _has_
	setreuid(2)/setregid(2), but these work only for "POSIX mode processes".
	I assume the -pcc flag above makes this perl non-POSIX.

After a surprisingly fast compilation (previous C optimizers spent ages on
toke.c and eval.c) i got:

	% cat shscript
	#!/bin/sh
	whoami
	% cat perlscript
	#!/usr/bin/taintperl
	print scalar getpwuid($>) , "\n";
	% ls -l perlscript shscript
	-rwsr-xr-x  1 root           55 Nov 12 18:11 perlscript
	-rwsr-xr-x  1 root           17 Nov 12 18:12 shscript
	% ./shscript; ./perlscript
	karrer
	root

Success!!!

BTW it is unwise to put perl into /usr/local/bin or somesuch on a
Convex. Most of Convex' installation script are now written in perl;
they assume the partition perl lives on is mounted. Also, save a copy
of the perl that comes with ConvexOS.

 - Andi

+-----------
  Andi Karrer, Communication Systems, ETH Zuerich, Switzerland
  karrer@bernina.ethz.ch    - Objects in mirror are closer than they appear
From: glewis@fws204.intel.com (Glenn M. Lewis - ICD ~)
Newsgroups: comp.lang.perl
Subject: Perl Printer Daemon?
Date: 11 Nov 92 20:19:20 GMT
Reply-To: glewis@pcocd2.intel.com
Distribution: comp
Organization: Intel Corporation, Folsom, CA


	I have a peculiar application, for which I think Perl would be
a good candidate to get the job done, but need input and advice.

	I would like to start up a Perl script on my UNIX workstation
that simply looks in a directory for any file.  If no file is there,
sleep for a little while and then check again.  If there *is* a file,
I would like the script to perform an eensy bit of filtering on it
(strip out ^M and ^D), and then send it off to a UNIX printer, using
"lpr" and the "-r" flag to remove the file.  (I have very little
understanding of "cron" or if "cron" could be used by an average-joe
[read: non-super] user to make sure this script is always running, but
that is a side issue that maybe someone could teach me about.)

	I could probably figure out how to do the above part, with a
little time.  Now comes the tricky part...  I would like this script
to also check the printer queue every so often, to see if it is making
progress.  Yes, this sketchy, because huge print jobs will take a long
time, and from the "lpq" standpoint, it is not easy to determine if
progress is being made.  Neglecting this side issue, if the script
determines that progress is *not* being made, I would like it to:

    1) Log into a remote machine with an embedded username and
       password (which should be secure, btw),
    2) Execute commands on the remote machine to get the printer going
       again, and
    3) logout of the remote machine and continue checking the
       directory.

	Does all this seam feasible?  Any e-mail replies would be
greatly appreciated!
	Thanks!

						-- Glenn Lewis

P.S.  If you are saying to yourself "Why does he want to do *that*?"...
      I have a network of PC's I want to print on a UNIX printer.  I
      can write files to a UNIX directory from those PC's, but they
      have crud in them like ^M's and ^D's that I need to strip.  The
      challenge is that this printer daemon goes down about every 2
      hours and needs restarting, and only I know how, in our group,
      and our operations wants to keep it that way.  So I wish to
      automate it.  Does this make sense?  Thanks again.
--
Glenn Lewis | glewis@pcocd2.intel.com | These are my opinions...not Intel's
From: rfs@se28.wg2.waii.com (Robert Starr)
Newsgroups: comp.lang.perl
Subject: an ls -C Perl function
Keywords: perl
Date: 13 Nov 92 20:15:15 GMT
Reply-To: starr@wg2.waii.com
Organization: Western Geophysical

Here is a function to take a list of file names, and sort it as an
ls -C does (sorted down columns).  I find myself spewing out file names
often, and missed having them not be ordered as ls -C does.  If there
was a Unix filter to do this, I couldn't find it.  But it's nice to
have a Perl ditty to do the same thing anyway.

Note the completely non-portable setting of TIOCGWINSZ to get the
window size.  The problem seems to be that proper .ph files cannot be
created on the Sparc, since the computation of TIOCGWINSZ involves
using the size of a data structure.  Any suggestions?

#--------%<----------------
#!/bin/perl
# $Id: lsC.pl,v 1.3 1992/11/13 19:59:25 rfs Exp $
#
# $Log: lsC.pl,v $
#Revision 1.3  1992/11/13  19:59:25  rfs
#Minor cleanup.
#
#Revision 1.2  1992/11/11  23:17:34  rfs
#Added int() to $nrows computation.
#
#Revision 1.1  1992/11/11  23:02:05  rfs
#Initial revision
#

# Usage: @out = &LsC(@filenames);
# Returns an array of filenames, sorted as ls -C would do.  The returned
# array of lines aren't newline terminated.
#
# NOTE: very non-portable setting of $TIOCGWINSZ.  This was for Sparc.
#
# Author: RF Starr (starr@wg2.waii.com)

sub LsC {
	package LsC;
	local(@f) = @_;
	local($maxlen, $_);
	local(@out) = ();

	$nc = &main'_GetNumColumns() unless (defined($nc));
	@files = sort(@f);
	# find widest file name
	$maxlen = 0;
	$cnt = 0;
	foreach (@files) {
		$len = length($_);
		$maxlen = $len if ($len > $maxlen);
		$cnt++;
	}
	$nperline = $nc/($maxlen+1);
	$nperline = int($nperline);
	$nrows = int($cnt/$nperline);
	$nrows++ if ($cnt % $nperline);
	$fmt = "%-$maxlen.$maxlen" . "s ";
	for ($i=0; $i < $nrows; $i++) {
		$out[$i] = '';
	}
	$j = 0;
	for ($i=0; $i < $cnt; $i++) {
		$out[$j] .= sprintf($fmt, $files[$i]);	
		$j++;
		$j = 0 if ($j >= $nrows);
	}
	return @out;
}

sub _GetNumColumns {
	package _GetNumColumns;

	$nc = 80;
	# You may need to change this constant
	$TIOCGWINSZ = 0x40087468;
	$wt = "S S S S";
	$ws = pack($wt, 0, 0, 0, 0);
	ioctl(STDIN, $TIOCGWINSZ, $ws);
	($nrow, $ncol) = unpack($wt, $ws);
	$nc = $ncol if ($ncol);
	return $nc;
}
1;
From: horst@faui63.informatik.uni-erlangen.de (Horst Luehrsen)
Newsgroups: comp.lang.perl
Subject: Re: Problems with multiple-splitting
Date: 10 Nov 1992 11:01:19 GMT
Organization: IMMD 6 - Lehrstuhl fr Datenbanksysteme
Distribution: world
Reply-To: horst@faui63.informatik.uni-erlangen.de (Horst Luehrsen)
NNTP-Posting-Host: faui63.informatik.uni-erlangen.de


In article <ELIAS.92Nov4165430@fitz.TC.Cornell.EDU>, elias@fitz.TC.Cornell.EDU (Doug Elias) writes:
>From: elias@fitz.TC.Cornell.EDU (Doug Elias)
>Newsgroups: comp.lang.perl
>Subject: Problems with multiple-splitting

[stuff deleted]
>The problem i'm seeing is that the $date string, obtained from the
>first split, doesn't seem to be itself splittable.  i can't find
>anything in the Camel Book to lead me to believe that this is
>verbotten, and it seems perfectly in keeping with what the functions
>are supposed to be able to do.
[stuff deleted]

Verbotten??? 

	Verboten!!!

Wenn schon deutsche Wrter, dann auch richtig!

(If you use german words, spell them correct!)

	Horst

 Horst Luehrsen <luehrsen@informatik.uni-erlangen.de> |
 Martensstrasse 3, W-8520 Erlangen                    | Kein Spruch
 Tel: +49-9131-857884  Fax:+49-9131-32090             |
From: sommar@enea.se (Erland Sommarskog)
Newsgroups: comp.lang.perl
Subject: TMF
Date: 9 Nov 92 13:06:34 GMT
Organization: Enea Data AB

When I read the Perl book I said too myself: hey, what a fun
langauge, it's got too many features. Well, I have never advocated
minimalism for its own sake, so why not?

Nevertheless here are two things which have bitten me recently,
which I might be prepared to put on the list of unnecessary features.

1) Saying &Sub2 means that Sub2 does not get its own copy of @_, which
   means that if called from Sub1, Sub2 gets Sub1's @_. In the case
   Sub2 takes parameters which all can be omitted, this may give un-
   exepected results.
     OK, there are some effeciency reasons for this arrangement, and
   it could probably be functionally useful as well.
     Actually, what confused me was a comment to a code example on
   page 100 in the camel book, which says "pass no list at all--
   more efficient". OK, I thought, one shall not put superfluous ()
   in parameterless call. And, since I do not come from the C or 
   Fortran camp, that was the natural thing for me to do anyway.
     So, the suggestion is only that the risk with passing no list at
   all should be highlighted in future editions of the Camel book.

2) @array returns the number of elements in a scalar context, but
   @array[1,2,3] or @array{'a', 'b', 'c'} returns the last element.
   I haven't found it now, but I dimly recall haveing read something 
   of the kind which would explain the result.
     Nevertheless, admit that it's quite confusing, and can lead to
   errors which are difficult find during test. I had:

      if (@result{"changed", "new", "deleted"})

   As "deleted" was empty, but the others not, I immediately got
   suspicious. But had I put "changed" at the end instead, I might
   not have discovered the error until much later when I thought 
   the program to be working.
     I would prefer if scalar on a list, no matter which one, always
   return the number of elements to get consistency, but I suspect
   that it would not be compatible with other people's code, so...
-- 
Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
Newsgroups: comp.lang.perl
From: rdm2@donner.uucp (24337-mcburnett)
Subject: Re: UUDECODE and perl ...
Organization: Bellcore, Livingston, NJ
Date: Wed, 11 Nov 92 21:17:03 GMT

In article <1992Nov11.150851.10057@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
>You shouldn't have to open a pipe to uudecode.  unpack('u', $datum)
>should suffice.
>
>--tom

Ok,  I didn't know about the 'u' option to unpack.  I submit the
following.

-Roe

================cut here================
#! /usr/local/bin/perl -S
#extract will scan for uuendcoded stuff and uudecode it into the right file
line: while (<>) {
	if(/^BEGIN/){
		$p = 'y';
		next line;
	}
	if(/^END/){
		$p = 'n';
	}
	if(/^begin/) {
		($begin,$mode,$file)=split;
		open(OUT,">$file");
	} 
	close OUT if(/^end/);
	if( /^begin/ || /^end/ || /Subject/ ){
		print stderr $_;
	}
	if($p eq 'y'){
		print OUT unpack('u',$_);
	}
}
Roe D McBurnett III Bellcore (908)699-2273 rdm2@chaucer.cc.bellcore.com
#insert <std.disclamer>
Newsgroups: comp.lang.perl
From: glenn@clsi.COM (Glenn Boysko)
Subject: Platform Information from Perl
Organization: CAD Language Systems Inc.
Distribution: comp.lang.perl
Date: 5 Nov 92 10:39:12


Hello All:

Is there a _standard_ way that Perl can identify the platform that it is
running on?  I am looking for a way to consistently produce a short, unique
identifier that indicates the platform (sun3, sun4, vax, etc.) that the script
is running on.  I can use this information to build pathnames, etc.

I am aware that I can inspect the file system for the presence of certain
files, but was wondering if Perl had anything builtin...

Thanks,
Glenn
--
......................... *                           *   
..=====.==....=====..===. | Glenn Boysko              | "An eye for an eye,
.======.==...===.....===. | CAD Language Systems, Inc |  a tooth for a tooth,
.==.....==....===....===. |                           |  vote for me and
.======.====....===..===. | glenn@clsi.COM  OR        |  I'll set you free."
..=====.====.=====...===. | uunet!clsi!glenn          |        -- Daniel Ash
......................... *                           *
From: S.Kille@isode.com (Steve Hardcastle-Kille)
Newsgroups: comp.lang.perl
Subject: Re: PERL-interface to QUIPU?
Date: 7 Nov 92 22:01:01 GMT

I think that this would be an excellent thing to do.   It would be
quite strightforward to do - you could provide a libdsap interface
with the string prarameters defined as for DISH.

In a similar vein, it would be very useful to have an SNMP capable
PERL (something on the lines of the existing SNMP capable GAWK).   I'd
prefer an active interface (the GAWK has a passve interface, relying
on variables with side effects).   

If anyone is interested to write these, I'd be very happy to provide
pointers and encouragement.   A tool with these capabilities would be
very useful for a range of system administration tasks


Steve Hardcastle-Kille   

ISODE Consortium
S.Kille@isode.com
Newsgroups: comp.lang.perl
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: open(FH,"|-") Insecure path?
Organization: Motorola Codex, Canton, Massachusetts
Date: Thu, 12 Nov 1992 01:05:08 GMT

Why does perl complain about an Insecure PATH when I do open(FH,"|-")?
Is this a bug, or am I missing something?

Michael.
From: aahz@hal.COM (Tom Wylie)
Newsgroups: comp.lang.perl
Subject: hoping for a minipatch
Date: 9 Nov 1992 16:24:17 -0800
Organization: HaL Computer Systems, Inc.
Distribution: na
NNTP-Posting-Host: perv.hal.com

We have a problem with getting duplicate frees using a hacked-up
copy of PERL.  It's possible that something we did is causing this,
but I was wondering if there are any unofficial patches after patchlevel
35 out there that fix a duplicate free or anything like that.

Unfortunately I don't think this is a problem of the kind where I
can post to the net about it and not expect it to fill up the
comp.lang.perl article buffer on most sites.  I'm just wondering about
any known, quickfixes dealing with memory leaks and whatnot.

Thanks for any input,

Tom Wylie
aahz@hal.com
From: mab@wdl39.wdl.loral.com (Mark A Biggar)
Newsgroups: comp.lang.perl
Subject: Re: sorting problem
Keywords: sort
Date: 12 Nov 92 22:40:27 GMT
Organization: Loral Western Development Labs

In article <BxM5w2.Iyr@immd4.informatik.uni-erlangen.de> mnrausch@cip.informatik.uni-erlangen.de (Martin Rausche) writes:
>I need a fast sorting routine for the following problem:
>I have a database and the entries look like this:
>keyword;author;title;owner
>My solution:
>sub byname
>{
>        @ah=split(/;/,$a);
>        @be=split(/;/,$b);
>        shift(@ah);
>        shift(@be);
>        $ah=join(";",@ah);
>        $be=join(";",@be);
>        $ah cmp $be;
>}
>@data=sort byname @data;

split take a third parameter that specifies how many item to slipt into.
This can be used to avoid the joins and shifts like so:

sub byname {
	@ah=split(/;/,$a,2);
	@be=split(/;/,$b,2);
	$ah[1] cmp $be[1];
}

The splits also get speed up because they can quit as soon as the first ';'
is seen.

--
Perl's Maternal Uncle
Mark Biggar
mab@wdl1.wdl.loral.com
Newsgroups: comp.lang.perl
From: jsb@cs.brown.edu (John Bazik)
Subject: perl lockf
Organization: Brown University Department of Computer Science
Date: Fri, 6 Nov 1992 22:08:46 GMT

Hi.  I need lockf(2) in perl.  The bible says you can emulate lockf
using fcntl.  Problem is, under SunOS 4.1.1, fcntl'ing F_SETLK appears
to be broken - it returns EINVAL, which isn't true since I can compile
and run the same C test program on a decstation without incident.

Okay, so I'm poking Sun with the bug, but in the meantime, I still need
some nfs-smart file locking.

Anyone out there got something I can use?

Please email me - I can't keep up with news...

Thanks.

John Bazik
jsb@cs.brown.edu
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: $| for stdin?
Originator: tchrist@pixel.convex.com
Date: Sat, 7 Nov 1992 04:58:09 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
Keywords: stdin $| and life
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of turbo@cse.uta.edu (Chris Turbeville):
:I am looking for some way of clearing standard in before every read.
:You know the stdin counter-part of $|.  I have a large program
:responsable for helping non-unices do unix admin things safely but I
:can't seem to keep it from getting a wrong char occasionally.  If the
:enter key is a little sticky then I get default responses when they may
:have wanted to enter something just because their fingers are a little
:heavy.  Does anyone know of a way to flush stdin up to now (by now I
:mean some point in the code) and then read something so these extra \n's
:won't clutter up the place.  I have tried seeks and all sorts of
:trickery but to naught.

Here's how Larry did it:

void
eat_typeahead()
{
#ifdef PUSHBACK
    if (!typeahead && nextin==nextout)  /* cancel only keyboard stuff */
#else
    if (!typeahead)
#endif
    {
#ifdef PENDING
        while (input_pending())
            read_tty(buf,sizeof(buf));
#else /* this is probably v7 */
        ioctl(_tty_ch,TIOCSETP,&_tty);
#endif
    }
}


Conversion into Perl is left as an exercise to the reader. :-(

--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

Besides, it's good to force C programmers to use the toolbox occasionally. :-)
        --Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
Newsgroups: comp.lang.perl
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: explicit sub parameters - a proposal
Organization: Motorola Codex, Canton, Massachusetts
Date: Thu, 12 Nov 1992 01:06:25 GMT

What about this idea: perl should allow this construct:

	sub foo($a, $b, @rest) {
	  # ...
	}

which would be exactly equivalent to

	sub foo {
	  local ($a, $b, @rest) = @_;
	  # ...
	}

That would greatly improve the readability of Perl, I think.  (Not to mention
the fact that people might be less likely to stumble into all the strange
things that can happen when you start playing around with @_.)

Michael.
Newsgroups: comp.lang.perl
From: weingart@inf.ethz.ch (Tobias Weingartner)
Subject: Re: explanation of the camel book code needed
Followup-To: comp.lang.perl
Keywords: sh csh perl ksh running with shells
Reply-To: weingart@inf.ethz.ch
Organization: ETH - Switzerland
Date: Tue, 10 Nov 1992 15:15:14 GMT

In article <nrp.721043320@reading>, nrp@csug3.cs.reading.ac.uk ("Scented fads" Neilski) writes:
|> 
|> I don't have the camel book (a serious shortcoming, I know) but I assume
|> that you're referring to something like the output produced by a2p and s2p:
|> 
|> #!/gnu/bin/perl
|> eval 'exec /gnu/bin/perl -S $0 ${1+"$@"}'
|> 	if $running_under_some_shell;
|> 
[stuff deleted]

How about?

#!/local/bin/perl
eval 'exec /local/bin/perl -S $0 ${1+"$@"}'
	if undef;

I have not tried this, but would it work?


-- 

***************************************************************
* Tobias Weingartner  * Not every man is willing to die...    *                
* c/o Bruno Opprecht  * Some have to be PUSHED out the window *
* Oberdierikoner st.7 * ------------------------------------- *                
* 6030 Ebikon Luzern  *      ...This space for rent...        *
* SWITZERLAND         *      ...This space for rent...        *                
***************************************************************
* +41'041'33'25'40    * ..Midnight the fading, blue Wizrd..   *
***************************************************************
SYSTEM-F-ANARCHISM, the operating system has been overthrown                  

PGP2.0 Public Key available at 'finger weingart@tau.inf.ethz.ch'