HDTenEightyP/NetNews huggingface dataset:
From: c_brown@csd.brispoly.ac.uk (Chris Brown)
Newsgroups: comp.lang.perl
Subject: How do I edit files with Perl
Date: 15 Sep 92 11:40:46 GMT
Reply-To: c_brown@csd.bristol-poly.ac.uk
Organization: Bristol Polytechnic (The Magic Roundabout)

I have a script which generates password file details and creates a home
directory for new user accounts.
I need to modify my script to ensure the contents of input data files will
be unique (in particular the logname) to the password file before altering
the password file.

I've written a noddy script to test my ideas.
What I've decided to do is grep the password file for lognames obtained from
the input files. If I come across any I save them to a list and print the
details in a file for later reference.
I then use a line adapted from the "Common Tasks with Perl" chapter to remove
the line in each file where the offending string occurs.

$SysFile = "/home/staff/csm/c_brown/Scripts/Perl_scripts/pass";
$Tmp = "/home/staff/csm/c_brown/Scripts/Perl_scripts/";
$Dups = "/home/staff/csm/c_brown/Scripts/Perl_scripts/dups";
@WordList = ();

# This section finds the duplicates
$Date = `date`;
@data_files = (test_data1, test_data2, test_data3);
open(Duplicates, ">>${Dups}");
print Duplicates $Date;
foreach $new_data (@data_files) {
  print STDOUT "Doing $new_data .... \n";
  open(NewData, "+<${Tmp}${new_data}");
  while(<NewData>) {
    ($Login) = split;
    chop($crud = `grep $Login $SysFile`);
    if ("$crud" ne "") {
      print Duplicates $_;
      @WordList = (@WordList, $Login);
    }
  }
  close(NewData);
}

# This section removes the offending lines
foreach $word (@WordList) {
  `perl -pi.bak -e 's/${word}\\n//' @data_files[0 .. $#data_files]`;
}

My questions are:
1. Does anyone know of a neater way of achieving the same goal?
2. Why does `perl -pi.bak -e 's/${word}\\n//' @data_files[0 .. $#data_files]`;
   only work with the -pi.bak option? I don't really want the .bak files.
3. Why does the same line process the .bak files? Files test_data1.bak and
   test_data2.bak are exactly the same as test_data1 and test_data2 respectively.
From: stevea@hpwin052.uksr.hp.com (Steve Andrews)
Date: Wed, 2 Sep 1992 09:34:14 GMT
Subject: Perl for MS-DOS, does it exist?
Organization: HP Response Centre, Berkshire, England.
Newsgroups: comp.lang.perl

Please help, does anybody know where I can get a copy of perl for MS-DOS, so
I can have a decent text processing tool in this environment as well as Unix.

Thanks very much for your help
Steve Andrews
stevea@hpwin052.uksr.hp.com
From: markp@vlsi-az_fw.vlsi-az.sps.mot.com (Mark Pease)
Newsgroups: comp.lang.perl
Subject: Re: Perl language formatting conventions?
Date: 14 Sep 92 17:17:50 GMT
Reply-To: markp@vlsi-az.sps.mot.com (Mark Pease)
Distribution: comp
Organization: VLSI Design Center, Tempe AZ

In article <1361@minya.UUCP> jc@minya.UUCP (John Chambers) writes:
>
>> I also use 4-space indent, in case you hadn't noticed.  :-)
>
>It has always seemed to me that a single tab is the best indent.  That
>way,  the  reader  can choose his/her own favorite indent spacing, and
>everyone is happy.  (In vi you type "se ts=4" to  get  4-column  tabs;
>most editors have a similar command.) It's also very fast to type.
>
>One of the silliest frustrations is all the programmers  who  like  to
>use  mixtures  of  tabs  and spaces to get 4-column spacing with 8-col
>tabs. This forces readers to reset the tabs to 8 columns to make sense
>of  the  code; it is slow for the writer to type; it wastes disk space
>and network bandwidth.  It's about as wrong a convention as one  could
>come up with (so of course it's the most common one ;-).
>

This happens automagiclly in vi when you have shiftwidth=4 in you .exrc or
EXINIT, and you use ^T to indent. The programer that does this is not 
(usualy) aware this is even happing! You can get around this by setting sw=8
or tabstop=4, but *I* don't have a problem with it.

>
>
>Actually, my favorite bit of nonsense in C formatting is  the  growing
>practice  of what I call "Chinese" coding.  Recall that traditionally,
>Chinese was written vertically, with one or two character per line. We
>are now seeing a lot of C in a similar style:
>
>    if (!initf)
>    {
>    	win = 
>	    XCreateSimpleWindow(
>    		display,
>    		RootWindow(display,screen),
>    		win_x,win_y,
>    		win_w,win_h,
>    		border_width,
>    		WhitePixel(display,screen),
>    		Pixel(display,screen)
>    	    );
>    	initf = TRUE;
>    }
>    	else
>    {
>    	(void*)
>	fprint(
>	    stderr,
>    	    "%d *** %s can't create new window [%d=%s].\n"
>    	    timestamp(),
>    	    progname,
>    	    errno,
>    	    sys_errlist[errno]
>    	);
>    }
>

    (I) think(that, for_long_lines_that_have_strange, long_names, "Chinese",
	 makes_the_line_more_readable);



Mark Pease                             markp@vlsi-az.sps.mot.com
Motorola CODEX VLSI Design Center
2710 S Roosevelt St.                   Mail Stop: AZ28 BB106
Tempe, AZ 85282         Phone:(602)784-2725    FAX:(602)784-2759
Newsgroups: comp.lang.perl
From: Kevin Burton <noran!iowa!kburton@uunet.uu.net>
Subject: Counting characters that match an arbitrary pattern.
Reply-To: noran!iowa!kburton@uunet.uu.net
Organization: The Internet
Date: Wed, 9 Sep 1992 19:14:38 GMT


I am sure this is a candidate for FAQ but I didn't see it in the "official"
perl FAQ list so here it is.

What is the most efficient subroutine that counts the number of characters 
that match a particular pattern. Currently I have:

       sub countchar
       {
       	       local($pattern,$string) = @_;
       	       local($count);
       	       local($_);
       
       	       $count = ($string =~ s/$pattern//g);
              
       	       return $count;
       }


       printf "Count = %d\n",&countchar('[A-Z]',"abcdEFGH");

Is there a better, more efficient way ?

Thanks.

kburton@noran.com


	


Newsgroups: comp.lang.perl
From: pwh@bradley.bradley.edu (Pete Hartman)
Subject: Re: termcap update via perl oddity
Organization: Bradley University
Distribution: usa
Date: Tue, 8 Sep 92 22:20:53 GMT

In <1992Sep8.211620.13578@bradley.bradley.edu> pwh@bradley.bradley.edu (Pete Hartman) writes:
>After running the script, unknown to me until a user complained about
>a missing termcap, everything from and including the extremely long line
>was truncated.  Is there something stupid in my script that causes
>it to choke on this?  I thought it was pretty simple to just read it
>in as the file existed, replace the top of it, and write it back out
>again, without line length limits.

I suppose, from my only response so far, I was not clear.  The ENTIRE
FILE (not just the long line) was truncated at this point (which would
still be a problem, but a more understandable and work-aroundable one).
-- 
Pete Hartman		       Bradley University	pwh@bradley.bradley.edu
        People say that I'm out of touch with reality.  That I'm insane.
    Sometimes I forget things.  Who I am.  Where I am.  Unimportant things.
                       But I'm not insane.  I am a tick.
Newsgroups: comp.lang.perl
From: peter@merlin.acadiau.ca (Peter Steele)
Subject: Re: What's the difference between `command` and system('command')?
Organization: Acadia University
Date: Fri, 11 Sep 1992 13:09:44 GMT

>:What the difference between saying `some Unix command` and
>:system('some Unix command')?  Are they synonymous?  Are there situations
>:where one is better than the other?

>	`cmd`;
>	$line = `cmd`;
>	@lines = `cmd`;

>returns the output, as it does in the shell.  The first form,
>however, throws it away.  system() works much (although not
>quite exactly) as it does in C.

Where does error output go (i.e., stderr)? I have an application
where I want to capture error output, not stdout.
--
Peter Steele        Unix Services Manager            peter.steele@acadiau.ca 
Acadia Univ., Wolfville, NS, Canada B0P 1X0  902-542-2201  Fax: 902-542-4364
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: dbm problems/questions (msdos-perl).
Originator: tchrist@pixel.convex.com
Date: Tue, 15 Sep 1992 14:17:55 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
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 kebsch@neurotic.sni.de (Waldemar Kebsch):
:I have fetched PERL419X.ZIP from Simtel and it runs fine. Because I have
:no experience with dbm I wrote a simple example using dbmopen(), dbmclose(),
:etc.. It works fine, but the [????????.dir] file is only 0 bytes long???

That's because you don't have enough stuff in it yet.  Add more the
the assoc array, and eventually it will have some size.

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

    echo "ICK, NOTHING WORKED!!!  You may have to diddle the includes.";;
            --Larry Wall in Configure from the perl distribution
From: kc@hpscit.sc.hp.com (Kwok Cheung)
Newsgroups: comp.lang.perl
Subject: Question on Camel Book
Date: 11 Sep 92 20:50:25 GMT
Organization: Hewlett-Packard, Santa Clara, CA


	I am fairly new on perl and have use awk and sed for
a long time. I have a question in regard to the camel book.
On p.259 the nfinger program, can any one explain what is the
meaning of the following line.

exec 'finger', @fingerargs, @finger if @finger;

The last part is the one I have problem in trying to understand

 @finger if @finger

when I run it with the full line, it just return with

Couldn't run finger:

Even I specific the full path to finger '/usr/bin/finger"
But when I delete the last 3 word

exec 'finger', @fingerargs;

The nfinger run, but I cannot pass on the logon to the program.
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: how to find all current package names?
Originator: tchrist@pixel.convex.com
Date: Mon, 14 Sep 1992 00:08:32 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
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 dansmith@Autodesk.COM (Daniel Smith):
:
:	You have a script.  You've included some libraries,
:so you have more than just %_main.  Now, how would you find out
:the names of all of the current packages?

This will get you 99.9% of the way. it would miss some pathological cases
that you probably can't generate without trying really hard, such as
package names that aren't valid identifiers.   But if you're doing that,
you'll probably understand how to modify this code to find them, too.

    foreach $package (keys %_main) {
	next unless $package =~ /^_/;
	$val = $_main{$package};
	next unless $val =~ /^StB/;
	*stab = eval("*$package");
	foreach $ident (keys %stab) {
	    print substr($package, 1)."\n" if $stab{$ident} =~ /^StB/;
	    last;
	}
    }

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

    It is, of course, written in Perl.  Translation to C is left as an
    exercise for the reader.  :-)  --Larry Wall in <7448@jpl-devvax.JPL.NASA.GOV>
From: jc@minya.UUCP (John Chambers)
Newsgroups: comp.lang.perl
Subject: Re: die hook
Date: 11 Sep 92 19:19:20 GMT

In article <1992Aug27.052530.11544@cs.ubc.ca>, phillips@cs.ubc.ca (George Phillips) writes:
> In article <1992Aug15.030457.21382@netlabs.com> lwall@netlabs.com (Larry Wall) writes:
> >The code I'm developing for Perl 5 already has two magical subroutines
> >in it called BEGIN and END.  They're so magical that you don't even have
> >to put "sub" in front of them.  BEGIN is automatically called before
> >the program starts, and END is automatically called just before the
> >program exits, no matter how it exits.
> 
> Do you get a magical BEGIN and END for each package or just one set for
> the entire program?  Seems like it would be a great way for required
> subroutine modules to install cleanup routines without extra bookkeeping
> on the part of the main program.  The BEGIN subroutine may be a problem
> since the earliest it could run would be at require time, but then
> again required files already have BEGIN.

Oh, no! If you do that, you'll shoot down my  most  favorite  pro-goto
argument, and then I'll have to start writing goto-less code!

The argument uses examples of the form:

foo(bar)
{	int r = 0;

	...
	for (...) {
		if (...) {	/* or some other deeply-nested control structure */
			...
			if (...)
				goto done;
			...
		} else {
			...
			if (...)
				goto fail;
			...
		}
	}
	goto done;
fail:
	fprintf(stderr, ... );
	r = -1;
done:
	if (debug > 4)
		fprintf(stderr, ...);
	return r;
}

The idea, of course, is that deep down in a nested pile of code,  some
condition  arises  that  means  you  should just get the hell out in a
hurry, either because you have a disaster on your hands, or  you  have
done  all  that  needs  to  be done (or have found what you're looking
for).  It's a real pain (and typically requires wasting space and time
-  both  cpu  and  debugging)  to  wend  your way out of the code in a
structured manner; you just want to abort the current routine. You can
use  "return",  but  that  doesn't give you any way to clean up, print
failure or debug messages, and so on.

In most programming languages, the only simple, elegant, and  readable
solution to this is a goto, as shown above.  If the proposed BEGIN/END
clauses are added to perl programs and subroutines, then where will  I
find a problem that requires goto for an elegant solution?

-- 
All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc 
--
Pensu tutmonde; agu loke.
From: joel@abigale.UUCP (Joel Rosi-Schwartz)
Newsgroups: comp.lang.perl
Subject: Re: Exegesis
Keywords: theophany meme exegesis VCRPlus+
Date: 13 Sep 92 21:50:23 GMT
Organization: Techne Research, Finchampstead, Berkshire (UK)

In article <BuIzq0.2yL@news.cso.uiuc.edu> ejk@ux2.cso.uiuc.edu (Ed Kubaitis - CCSO) writes:
>In article <1992Sep.102814.14478@abigale.uucp>, 
>joel@abigale.UUCP (Joel Rosi-Schwartz) writes:
>  |...
>  |Larry, your recent comment on cultural/theological diffirences was
>  |interesting.
>  |
>  |[In article <1992Sep11.200227.23995@netlabs.com>,
>  |lwall@netlabs.com (Larry Wall) writes:]
>  |  > [Though now we're getting into cultural differences, not theological
>  |  > differences.  People often confuse the two--probably because most folks
>  |  > can't tell the difference between an ordinary meme and a theophany.]
>  |
>  |I fall into the folk class you refer to, often being unable to clearly
>  |differentiate between the two.  How would you classify the two suggestions
>  |I made?
>
>Joel here frankly admits difficulty with 1992Sep11.200227.23995@netlabs.com.
>

  [much explanation and examples deleted]

>Your humble author hopes this modest offering has contributed to your
>appreciation of these c.l.p passages. If not, tough! I've got a new Stereo 
>HiFi VCR and Wayne's World waiting for me at home! It's even got VCR Plus+ 
>so I might be able to catch most of the MaryThon on Nick at Nite without 
>getting callouses on my remote finger!!

Ed,

That was *very* illuminating, thanks for taking the time from the Telie
to educate us mere mortals. And now I know why I didn't become a Rabbi ;-)

Cheers
Joel


-- 
     ==================================================================
     ||               T E C H N E   R E S E A R C H                  ||
     ||  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  ||
     ||                     Joel Rosi-Schwartz                       ||
     ||   Hildorien House            +   Email: joel@abigale.UUCP    ||
     ||   12 Waverley Way            +    (pyrltd!abigale.UUCP!joel) ||
     ||   Finchampstead, Wokingham   +   Phone: +44 (734) 730.260    ||
     ||   Berkshire RG11 4YD (UK)    +   Fax:   +44 (734) 730.272    ||
     ==================================================================
From: jacobsd@prism.cs.orst.edu (Dana Jacobsen)
Newsgroups: comp.lang.perl
Subject: Re: Help with variable interpolation inside s/// (repost)
Keywords: variable interpolation, substitution
Date: 12 Sep 92 03:36:28 GMT
Organization: Oregon State University, Computer Science Dept

In <1992Sep11.222422.24918@CS.ORST.EDU> hanusj@storm.CS.ORST.EDU (Joe Hanus) writes:
>We have written a short capitalization script that's not working. The
>script assumes all words not found in a standard dictionary are proper
>nouns.  Those found in the dictionary are capitalized by replacing
>with the word from the dictionary. 

>The line giving the problem is commented
>We are using perl 4.035

>Can you pinpoint my problem or suggest a work-around?

  While I can't solve the problem (it looks like your code should work
to me), I can suggest a workaround that not only works, it is much faster
than the method you're using.  Hint: loop over the sentence, not the
dictionary.  I also use the "\u" and "\L" operaters defined on page 70 of
the Camel book to do the capitalization.

#!/usr/local/bin/perl
 
open( CHANGES, "/usr/dict/words" );
while (<CHANGES>) {
  chop;
  $realcap = $_;
  # convert into "Captilized Format"
  s/^(\S)(\S*)/\u$1\L$2/;
  $rwords{$_} = $realcap;
}
close( CHANGES );
 
while ( <> ) {
   s/\b(\S)(\S*)\b/\u$1\L$2/g;
   foreach $word ( split(/\W/) ) {
     s/\b$word\b/$rwords{$word}/g if $rwords{$word};
   }
   print;
}

exit 0;

>------------------------------------------------------------------------------
>Joe Hanus                            | E-MAIL hanusj@bionette.cgrb.orst.edu
>Microbial Germplasm Database         |
>Dept. of Botany and Plant Pathology  | Phone  (503)-737-5300
>Oregon State University              | FAX    (503)-737-3045
>Corvallis, OR 97331-2902             |
>______________________________________________________________________________
--
Dana Jacobsen                       I that wes in heill and gledness
jacobsd@cs.orst.edu                   am trublit now with gret sikness
jacobsd@solar.cor2.epa.gov              and feblit with infirmetie
Computer Sciences Corporation             Timor mortis conturbat me.
From: tmhoff@oogoody.Corp.Sun.COM (Todd Hoff)
Newsgroups: comp.lang.perl
Subject: Removing duplicates from an array
Date: 11 Sep 1992 22:30:25 GMT
Organization: Sun Microsystems, Inc.
Distribution: world
Reply-To: tmhoff@oogoody.Corp.Sun.COM
NNTP-Posting-Host: oogoody.corp.sun.com


Is there a cool way of removing duplicates from an array? I can think
of several methods, it could be an option on sort, but what is the
perl way?

Thanx
Newsgroups: comp.lang.perl
From: Al Gaspar <gaspar@stepsun.army.mil>
Subject: Re: How to convice awk/sed users to use Perl ? 
Reply-To: gaspar@stepsun.army.mil
Organization: The Internet
Date: Thu, 10 Sep 1992 12:09:01 GMT


|As a Perl beginner, I don't know how to answer the following question raised b
|y my
|colleagues:
|   I  use ksh/awk/sed very well, why bother to spend a lot of time to learn Pe
|rl ?
|   What's the real advantages of perl over ksh/awk/sed ?
|
|I will appreciate any help.
|
|---
|
|Chi-Sharn Wu
|swu@probe.att.com
|

    I would suggest that process overhead and speed might be considerations.
In the September 1992 issue of "Unix Review" there was an article including
and discussing an awk/sed/shell script to analyze bourne shell scripts.  Mostly
out of curiosity, I 'translated' that script to perl, without any particular
thought on the best optimizations, and came up with a one pass perl script that
worked at twice the speed as the original script without piping anything to
subprocesses.

    I find that perl is great for quickly producing demonstrations of concepts
that might later be rewritten in C.

    There is source code available.

    When I have a question I pull down one book rather than three.

    There are JAPHs...

    I hope this helps.

Cheers--

Al

-- 
Al Gaspar	<gaspar@st-louis-emh2.army.mil>
USAMC SIMA, ATTN:  AMXSI-TTC, 1222 Spruce St., St. Louis, MO  63103-2834
COMMERCIAL:  (314) 331-4354	AUTOVON:  555-4354
relay1.uu.net!st-louis-emh2.army.mil!gaspar
From: futor@llnl.gov (randy j futor)
Newsgroups: comp.lang.perl
Subject: Re: Why Bother To Learn Perl?
Date: 15 Sep 92 21:37:21 GMT
Followup-To: comp.lang.perl
Organization: CSo @ LLNL


 inc@tc.fluke.COM (Gary Benson) wrote:
A lot of good things & true, but right here is where the hammer found the
nail:
> 
> . . . I tried it in perl. I wrote it just the way it made
> sense, and the son-of-a-gun *worked*! The very first time out! I was amazed.

Amazed.  Slack-jawed.  Dumbfounded.  All of these & more.

If you've written a lot of code over the years, the feeling you get when
you look at a page & a half of perl & try to guesstimate just how many
lines of C it'd take to do the same amount of work is beyond explanantion. 
It's out there 2 or 3 steps past that euphoria sometimes known as the
"coding frenzy".

To mangle the bumpersnicker:
   They'll get my perl
   when they pry it from
   my cold, dead /usr/local/bin
__
\/  -+-  randy  -+-  all generalizations are flawed  -+-  futor@llnl.gov
Newsgroups: comp.lang.perl
From: mike@meiko.com (Mike Stok)
Subject: Re: How to convice awk/sed users to use Perl ?
Organization: Meiko Scientific Corp.
Date: Wed, 9 Sep 1992 16:37:45 GMT

In article <1992Sep9.143629.13571@cbfsb.cb.att.com> swu@att.com writes:
>As a Perl beginner, I don't know how to answer the following question raised
>by my colleagues:
>   I  use ksh/awk/sed very well, why bother to spend a lot of time to learn
>   Perl ?
>   What's the real advantages of perl over ksh/awk/sed ?
>
>I will appreciate any help.

Personally speaking I like to have 1 set of regexp rules to remember
which I can apply to arbitrary data (such as lines > 512 chars, binary
files used by our Cobol (!) runtime) apart from maybe a file from
emacs (or some similar program with Pascaloid notions of new lines as
separators not terminators) with just the character 0 on the last line :-)

Perl at least reads & tokenises the script before executing it and
doesn't just say "bailing out near line 1", so usually you can be
*fairly* happy and confident once it's started to run.  The debugger's
pretty useful sometimes too.

The thing which makes lots of non-programmers like it (and loads of
programmers struggle at first) is the way data type is context
sensitive (e.g. Q "...so, Mike is $x a number or a string?" A "It's a
scalar, and how it's used determines how it's interpreted" type
conversations happen a lot around here).  I like a language which has
"until" and "unless" in it, as this makes it easier to write things
like

  print $x unless $x eq "banana\n";

which reads pretty sensibly to an english speaking person who spends
more time interacting with people than machines ;-)

The formatted output is pretty good for the guys who work at
extracting data from our accounting system and combining it with adat
extracted from a design system, then there's the ease with which I can
fire off processes and do inter-process communication, and when I get
stuck there are stacks of helpful people in comp.lang.perl who usually
help out in the nicest possible way (they know who they are :-)....

Mike
--
The "usual disclaimers" apply.    | ... many were weak and confused, succumbing
Mike Stok                         | to drink or drugs whenever possible ...
mike@meiko.com                    |
Meiko tel: (617) 890 7676         |                          Hunter S. Thompson