HDTenEightyP/NetNews huggingface dataset:
From: namra@magnus.acs.ohio-state.edu (Nasir K Amra)
Subject: speeding up access and processing of 650,000 record database
Organization: The Ohio State University
Date: Mon, 31 Aug 1992 14:06:32 GMT


	I currently have a program which takes a game file (consisting
of 60 moves) and then searches a 650,000 record database file (46
megabyte) to count game configurations that are consistent with the
moves at each move. Currently the program takes 3 hours on a single
game file which is much too long.  I've tried to load the whole
database file in an array on a 64 megabyte Sparc II , but Perl gives
me an "Out of Memory!" error message which I find hard to believe. Do
I have to reconfigure Perl in order to exploit the memory available on
the workstation? If so , how? 
	I believe a significant amount of processing time is spent in
comparing each record in the database file with each move in the game
file. Currently I use the pattern matching operator =~ /pattern/ to
test equality between the accumulated move pattern and the record
pattern. Is there a faster way to do this? I've appended the
subroutine which processes the game file below (any help would be much
appreciated): 

# the database is structured so that a record consists of an 8
# numeric string that is the configuration and a 64 numeric string
# that is the pattern.
$template="A8 A64";
sub process_datafile {
    local($recnum);
    $recnum = 1;
    open(BB,"<$bb_database") || die "Couldn't open $bb-database";
       while ( (read(BB,$record,$recordsize))) {
           #process record.
	   ( $config , $pattern ) = unpack ($template, $record);
	   #process moves of datafile
	   for ($j = 1; $j <= $game ; $j++ ) {
	       #variables for each game
	       for ($k = 1; $k <= 32 ; $k++) {
		   $gamepattern[$k] = "\\d\\d"; }
	       for ($i = 1; $i <= $moves[$j]; $i++  ) {
		   #variables for each move
		   if ($event{$j,$i} =~ /Shoot Ray/){
		       if ($to{$j,$i} < 10) {
			   $gamepattern[$from{$j,$i}] = "0" . $to{$j,$i}; }
		       else {
			   $gamepattern[$from{$j,$i}] = $to{$j,$i} ; }
		       $testpattern = join("", @gamepattern) . "\n"; 
		       if ($pattern =~ /$testpattern/ ) {
			   #yes $testpattern matches $pattern 
			   $yes{$j,$i} = $yes{$j,$i} + 1; # of patterns in database
                                                      # consistent with game pattern
		       }
		       else { # no need to continue to cycle through moves since $pattern is not consistent
			   last ; # exits loop through moves for statement.
		       }
		   }
	       }
	   }
            $recnum++;
       }

}

-- 
---------------------------------------------------------------------
Nasir K. Amra				     amra@med.ohio-state.edu
Laboratory for Knowledge Based Medical Systems
571 Health Science Library,376 W. 10th , Columbus, Ohio, 43210
Xref: sparky comp.lang.perl:5736 sci.classics:683
From: dsg@blackbird.mitre.org (David S. Goldberg)
Subject: Re: P-COPS
Organization: The Mitre Corp., Bedford, MA.
	<1992Aug27.210806.7694@porthos.cc.bellcore.com>
Date: Fri, 28 Aug 1992 13:30:01 GMT


>>>>> In article <1992Aug27.210806.7694@porthos.cc.bellcore.com>,
>>>>> slade@accolade.base.bellcore.com (25873-slade) writes:

slade> Where can I ftp a copy of P-COPS?

slade> Thanks,

It's available from cert.org in /pub/tools.  I've gotten a couple of
responses, but so far it's still hanging and I'm still getting those
messages.  I can run the perl checks individually without any problem,
so I'm probably just going to look into taking those checks that I
want and running them from the shell version.

Unfortunately, not much of a perl hacker (yet)

--
Dave Goldberg                      UNIX Systems Programmer/Administrator
Post: The Mitre Corporation MS B020 202 Burlington Rd. Bedford, MA 01730
Phone: 617-271-2460
Domain: dsg@mbunix.mitre.org  UUCP: {your neighborhood}!linus!mbunix!dsg 

Newsgroups: comp.lang.perl
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: Re: Simultaneous processes
Organization: Motorola Codex, Canton, Massachusetts
Date: Wed, 26 Aug 1992 18:48:23 GMT

peter@merlin.acadiau.ca (Peter Steele) writes:

>How does one set up simultaneous processes in perl? For example,
>how would I translate the following into perl:

>    #!/bin/sh

>    ls -la > d1 &
>    ls -la > d2 &
>    ls -la > d3 &
>    wait
>    cat d1 d2 d3 > d4

...

>            wait for all processes to complete and combine output;

It would probably be enough to wait for them in the order they were started.
For example, here's the logic from a script I use run parallel rsh's:

foreach $host (@host)
{
    open($host, "rsh $host $command |") || die "popen";
}
foreach $host (@host)
{
    while (<$host>)
    {
        &do_something_with($_);
    }
    close($host);
}

Michael.
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: How do I make traps in perl?
Originator: tchrist@pixel.convex.com
Date: Wed, 2 Sep 1992 14:13: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 ian@unipalm.co.uk (Ian Phillipps):
:lwall@netlabs.com (Larry Wall) writes:
:
:>    sub CATCHINT {
:>	print "OUCH! Don't DO that!!!\n";
:>    }
:
:I've wanted the equivalent of a longjmp to allow a sig handler to yank
:me out of nest of routines etc, and plonk me down somewhere standard
:(e.g. a main STDIN-reading loop). The "goto" spec is so discouraging
:that I've not even tried it, and nothing else seems to fit.

Have you not tried eval?

27) How can I do an atexit() or setjmp()/longjmp() in Perl?

    Perl's exception-handling mechanism is its eval operator.  You 
    can use eval as setjmp, and die as longjmp.  Here's an example
    of Larry's for timed-out input, which in C is often implemented
    using setjmp and longjmp:

          $SIG{'ALRM'} = 'TIMEOUT';
          sub TIMEOUT { die "restart input\n"; }

          do {
              eval '&realcode';
          } while $@ =~ /^restart input/;

          sub realcode {
              alarm 15;
              $ans = <STDIN>;
          }


--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist
    > This made me wonder, suddenly: can telnet be written in perl?
    Of course it can be written in Perl.  Now if you'd said nroff, 
    that would be more challenging...   --Larry Wall
From: steiner@bakerst.rutgers.edu (Dave Steiner)
Newsgroups: comp.lang.perl
Subject: Re: split !!
Keywords: split, GRRR
Date: 2 Sep 92 01:49:50 GMT
Organization: Rutgers Univ., New Brunswick, N.J.
Cc: steiner

If you can change the database file, you might want to use the $; char
as the field separator (generally bound to \034 or some such).  I've
change my database program (which uses dbm files so I don't care what
they look like) to use this instead of the ':' as originally intended
for this very reason.

ds
-- 

Dave Steiner
arpa: Steiner@BakerSt.Rutgers.Edu or Steiner@Rutgers.Edu
uucp: ...{backbone site}!rutgers!bakerst.rutgers.edu!steiner
From: steiner@jupiter.cse.utoledo.edu (jason "Think!" steiner)
Newsgroups: comp.lang.perl
Subject: Re: Ordering indices based on their values
Date: 27 Aug 92 01:30:32 GMT
Distribution: comp.lang.perl

glenn@clsi.COM (Glenn Boysko) writes:
> 
> Hello Perl Hackers,
> 
> I was wondering if anyone knew of an efficient, simple way to 
> produce an ordered array of indices whose order was based on their 
> values.  Consider the following array:
> 
> 	Index | Value
> 	------+------
> 	  0   |  7
> 	  1   |  2
> 	  2   |  4
> 	  3   | -1
> 	  4   |  5
> 
> I would like a new array whose values are indices of the input 
> array.  The values of the new array are ordered such that their 
> values in the original array are ordered in descending order.  The 
> resulting array for our example is:
> 
> 	Index | Value
> 	------+------
> 	  0   |  0
> 	  1   |  4
> 	  2   |  2
> 	  3   |  1
> 	  4   |  3
> 
> Note that an appropriate solution would be to use an associative 
> array to store (value, index) entries and then sort the keys.  
> However, this will not work if the values of the original array are 
> not distinct.
> 
> Once this array has been generated, I can process each entry in the 
> orignal array according to the descending order of the values.
> 
> Any Ideas?
> Glenn

here's how i would do it...

#!/usr/local/extras/bin/perl

@array=(7,2,4,-1,5);
@index=(0,1,2,3,4);

@index = sort {$array[$b]<=>$array[$a];} @index;
for (@index) { print "$_\t$array[$_]\n"; }

and it works if elements are not distinct.

jason "am i a Perl hacker now?" steiner

--
`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`
`,` Do you happen to be of the mechanical persuasion? `,`
`,`      Don't be taken in / by weak imitations.      `,`
`,`    A robot and a man got the same limitations.    `,`
`,`                -- Rise Robots Rise                `,`
`,`,`,`,`,`,` steiner@jupiter.cse.utoledo.edu `,`,`,`,`,`
From: tchrist@convex.COM (Tom Christiansen)
Newsgroups: comp.lang.perl
Subject: Re: easy question?: substrings
Date: 26 Aug 92 22:28:21 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Distribution: usa
Organization: Convex Computer Corporation, Colorado Springs, CO
Originator: tchrist@pixel.convex.com
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 budnick@cbnewse.cb.att.com (Mary Jo Budnick):
:Hi!  I just started to use Perl and can't find the info in the
:Wall/Schwartz book very easily to solve my problem.  Help me out?
:
: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 

Try:

    $n = "ffffff00";
    print join(".", unpack(C4, pack(L, hex($n)))), "\n";

Add quotes around the format strings for old versions of perl.

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

    Hey, I had to let awk be better at *something*...  :-)
            --Larry Wall in <1991Nov7.200504.25280@netlabs.com>1
From: watson@carssdf.UUCP (- Self Empl. Sys.Integrator)
Newsgroups: comp.lang.perl
Subject: how to 'write' cr-nl
Date: 31 Aug 92 16:35:41 GMT
Organization: John Watson (Self Employed System Integrator)

Is there an easy way to write CR-NL at the end of the lines
instead of just "\n".  Sort of like  $\ = "\r\n", except make
it apply to the write statement?

Alternatly is there an EASY way to set the onlcr flag on 
STDOUT in some portable way when you don't know for sure
what device it is pointing to (so I can't do system('stty...)..

This must be simple, I've got to be overlooking the easy
solution.

John Watson     watson@carssdf.UUCP
Newsgroups: comp.lang.perl
From: asherman@laser.fmrco.com (Aaron Sherman)
Subject: Re: fast way to get number of elements in an assoc array?
Reply-To: asherman@fmrco.COM
Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
Date: Thu, 27 Aug 1992 16:17:10 GMT

>>>>> jacobsd@prism.cs.orst.edu (Dana Jacobsen) said:
Dana> Article-I.D.: CS.1992Aug27.032106.20515
Dana> Nntp-Posting-Host: prism.cs.orst.edu


Dana>   Is there a function akin to $#array that works on associative
Dana> arrays? I have an associative array with over 30,000 keys, and
Dana> this is what I'm currently doing:

Dana>	@dummykey = keys(%records);
Dana>	print $#dummykey+1, " records loaded.\n";
Dana>	undef (@dummykey);

Try:

		print "# of entries: ", scalar(keys %foo), "\n";

Remember, arrays in a scalar context USUALLY return the number of
items that they contain. 


			-AJS
--
--------
Disclaimer: I am solely responsible for the content of this message.
The views expressed here may not be the views of I-Kinetics, Fidelity,
any of the Fidelity-owned corporations or my mother.
Newsgroups: comp.lang.perl
From: ejk@ux2.cso.uiuc.edu (Ed Kubaitis - CCSO)
Subject: Re: coding style (was Re: Perl language formatting conventions?)
Organization: University of Illinois - Urbana
Date: Fri, 28 Aug 1992 14:10:05 GMT

lwall@netlabs.com (Larry Wall) writes:
  |...
  |I required curlies in Perl because people wrongly
  |perceive this sort of thing:
  |
  | 	while ( ( c = getc(fpIn) ) != EOF )
  | 		putc(c, fpOut);
  |		count++;
  |	printf("%d\n", count);
  |

Alas, indentation is for people, not compilers. K&R (1st edition p 52): 
"The indentation shows unequivocally what you want, but the compiler 
does not get the message."  

When I was too new to the culture to know better, this quote inspired me
to write a 2000+ line C application in a dialect of C that required no 
braces (and no semi-colons.) These "tools of ignorance" for the compiler 
were added by a 60-line shell/old-awk script during make. The script relied 
on indentation, and a few restrictions on otherwise permissable C syntax. 

For me, it was a pleasant way to code, sort of like fishing in Alaska
without mosquitoes. Indendation reflected control structure and the damn 
braces were neither hiding at the end of the line nor stealing valuable 
real estate on my miserly 24-line ascii terminal.

  |This is also why I prefer outdenting the trailing curly.  If you say,
  |as some do for reasons that they have recently admitted are related
  |to cultural continuity,
  |
  | 	while ( ( c = getc(fpIn) ) != EOF ) {
  | 		putc(c, fpOut);
  |		count++;
  |		}
  |	printf("%d\n", count);
  |
  |then you're actually trying to ignore the existence of the trailing curly,
  |and relying on the indentation for grouping.  Why else would you line
  |it up except to make it more or less invisible?  

Exactly! Block delimiters are for compilers, not people. My experiment in 
indent-structured C suggested (to me at least) that braces in a rigorously 
indented program carry little information. So I do want to make braces more 
or less invisible so as not to visually distract from the important 
information provided by the indentation. (Hiding the trailing brace on the 
end of the last line of the block makes adding new lines and visually 
syntax-checking nested structures more difficult, so I don't go that far.)

----------------------------------
Ed Kubaitis (ejk@ux2.cso.uiuc.edu)
Computing & Communications Services Office - University of Illinois, Urbana
Newsgroups: comp.lang.perl
From: lwall@netlabs.com (Larry Wall)
Newsgroups: comp.lang.perl
Subject: Re: Processing multi-line entities with perl
Date: 25 Aug 92 22:45:48 GMT
Organization: NetLabs, Inc.

In article <1992Aug24.125350.3407@cas.org> lvirden@cas.org (Larry W. Virden) writes:
: WARNING! NOVICE QUESTION APPROACHES!
: 
: 
: Okay.  I have occasion to deal with files containing one or more entities of
: the format:
: 
: 
: [number1,number2]
: text0
: 
:   text1
:   text2
:         text3
: 
:   text4
:   possible lines text5 to textn
: 
: 
: What I want to do is sort such entities by info in various places in the entry.
: For instance, sometimes it may be by [number1,number2], other times 
: by substrings within text0, etc.
: 
: Does anyone have some tips on where to begin processing such a file?  I
: have seen shell, awk, etc. code which would redefine record separators to
: be a newline.  But in my case, there is no unique line separating the
: entities.  Each entity DOES begin with [some number, some other number],
: but that value must remain as part of the entity.
: 
: Any tips that you might have would be appreciated.

There are several approaches you might take.  I usually just keep $_ as a
lookahead line:

    while (<>) {
	&do_something if /^\[\d+,\d+]/;
	$text .= $_;
    }
    &do_something;

    sub do_something {
	if ($text ne '') {
	    # do something
	    $text = '';
	}
    }

You could also play around with a record separator of "\n[", but
that's a little messier.  (But it may also be a lot more efficient!)

    $/ = "\n[";

    while (!eof()) {
	$_ .= <>;
	chop; chop;
	# do something
    }
    continue {
	$_ = "[";
    }

That assumes you don't have any text lines that start with "[".  If
you do, then you have to do a lookahead of some sort, unless...

If the file's not too large, you can just slurp it in and split it
on /^\[\d+,\d+]\n/:  

    {
	local($/) = undef;
	@stuff = split(/^\[\d+,\d+]\n/, <>);
    }
    while (($brackets,$text) = splice(@stuff, 0, 2)) {
	# do something
    }

And sometimes it's better to change the thing that spits out the files
in the first place.  Then you could set $/ to a delimiter you know will
not be in the text.

Larry
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: easy question?: substrings
Originator: tchrist@pixel.convex.com
Date: Fri, 28 Aug 1992 18:32:56 GMT
Distribution: usa
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 john@sekrit.WPI.EDU (John Stoffel):
:Don't you mean you want a 'N' instead of the 'L' in the pack?
:At least this is what is needed with perl 4.035 on a DECstation 3100.

Yup, and did so in a followup.  Dang crazyendians.

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

    The use of COBOL cripples the mind; its teaching should, therefore, be
    regarded as a criminal offense.  -- E. W. Dijkstra
Newsgroups: comp.lang.perl
From: jhd@irfu.se (Jan D.)
Subject: Re: fast way to get number of elements in an assoc array?
Date: Thu, 27 Aug 1992 15:36:19 GMT
Organization: Swedish Institute of Space Physics, Uppsala, Sweden

In article <MEISSNER.92Aug27103724@tiktok.osf.org> meissner@osf.org (Michael Meissner) writes:
>In article <1992Aug27.032106.20515@CS.ORST.EDU> jacobsd@prism.cs.orst.edu (Dana Jacobsen) writes:
>
>| 
>|   Is there a function akin to $#array that works on associative arrays?
>
>	int (scalar (%array))

That can't be right, at least not on all machines. Consider this:

% perl -e 'print int(scalar (%ENV)), "\n"'
24
% perl -e 'print int(scalar (keys %ENV)), "\n"'
39
% env | wc -l
     39


BTW, int(scalar (keys %ENV)) isn't a good way to count elements for large
assoc arrays.

This is a FAQ (but where's the FAQ? :-). Number 37 to be exact:

37) How can I know how many entries are in an associative array?

    While the number of elements in a @foobar array is simply @foobar when
    used in a scalar, you can't figure out how many elements are in an
    associative array in an analogous fashion.  That's because %foobar in
    a scalar context returns the ratio (as a string) of number of buckets
    filled versus the number allocated.  For example, scalar(%ENV) might
    return "20/32".  While perl could in theory keep a count, this would
    break down on associative arrays that have been bound to dbm files.

    However, while you can't get a count this way, one thing you *can* use
    it for is to determine whether there are any elements whatsoever in
    the array, since "if (%table)" is guaranteed to be false if nothing
    has ever been stored in it.  

    So you either have to keep your own count around and increments
    it every time you store a new key in the array, or else do it
    on the fly when you really care, perhaps like this:

	$count++ while each %ENV;

    This preceding method will be faster than extracting the
    keys into a temporary array to count them.



	Jan D.

Newsgroups: comp.lang.perl
From: pem@yarra-glen.aaii.oz.au (Paul E. Maisano)
Subject: Re: LVALUE =~ EXPR ?
Organization: Australian Artificial Intelligence Institute
Date: Fri, 4 Sep 1992 05:06:28 GMT

Paul E. Maisano (that's me) writes:

>I was rather expecting (hoping for?) this to work:
>
>($x = 'ab') =~ (s/a/A/, s/b/B/);
>print "$x\n";

Thanks to those who replied to my message (by mail).
Especially Raymond Chen, who gave me a detailed explanation of
how the expression above was actually being interpreted (which
I'll summarize below).

Firstly, my motivation for wanting the above to work was that I wanted to
avoid repetitions such as:
    $some_meaningfully_named_variable =~ tr/abc/xyz/;
    $some_meaningfully_named_variable =~ s/foo/bar/;
    $some_meaningfully_named_variable =~ s/BAR/puppy/;

I wanted to be able to say something like:
$some_meaningfully_named_variable =~ (tr/abc/xyz/, s/foo/bar/, s/BAR/puppy/);
Much nicer, I think.

As Raymond pointed out to me, this evaluates just as described in the
manual (once you understand what the manual is trying to say).

>                                     (If the right argument is an
>             expression other than a  search  pattern,  substitu-
>             tion,  or translation, it is interpreted as a search
>             pattern at run time.

What this means is that (and it is obvious to me now), the RHS is evaluated
just as it normally is and whatever it returns is treated as a search-pattern;
as if it was enclosed in `/ ... /'. So the above is evaluated like this:
	$tmp = (tr/abc/xyz/, s/foo/bar/, s/BAR/puppy/);
	$some_meaningfully_named_variable =~ /$tmp/;

Of course, $tmp contains the return value of the s/BAR/puppy/.
This is not the effect I wanted. I suppose I was hoping for a bit
of perl magic where it does what you expect it to do rather than
what the rules say it should do :-)

Ok, I know that this is not an earth-shattering problem but I hate
repeating the variable name all over the place. So what are my options?

	$_ = $some_meaningfully_named_variable;
	(tr/abc/xyz/, s/foo/bar/, s/BAR/puppy/);

But I might have been using $_ for something else.

Probably this is best:

	{ local($_) = ($some_meaningfully_named_variable);
	  tr/abc/xyz/;
	  s/foo/bar/;
	  s/BAR/puppy/;
	}

The syntax I would really like (and it looks like perl to me :-) is:

	$some_meaningfully_named_variable =~ {
		tr/abc/xyz/;
		s/foo/bar/;
		s/BAR/puppy/;
	};

I think this fits in with the way braces are used for grouping things
in perl and it seems just to be a generalization of the =~ operator.

Well, I've bored you all enough by now.


-paul, (can't wait for 5.0)

---
Paul Maisano                  pem@aaii.oz.au
Australian Artificial Intelligence Institute