[7769] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1394 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 1 02:14:35 1997

Date: Sun, 30 Nov 97 23:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 30 Nov 1997     Volume: 8 Number: 1394

Today's topics:
     Re: Breaking out of an app <schramm@one.net>
     Re: Conditional compilation? (Josh)
     Re: For the pro's ? repost: Leaving HTML tags alone (Sami Sandqvist)
     newcomer Q  - Perl - MS FrontPage - Windows95 <donnapro@earthlink.net>
     OLE <myleslawrence@email.msn.com>
     Re: Perl Plug-In for Netscape? (Nathan V. Patwardhan)
     Re: perlop clarification request <stuartc@ind.tansu.com.au>
     Re: perlop clarification request (Tushar Samant)
     Re: perlop clarification request <rjk@coos.dartmouth.edu>
     Re: Q: alternative to Perl? (Steven W McDougall)
     Re: Q: Learning perl with no progr. experience (Tushar Samant)
     Re: RESOURCE KIT ANOMALY... ONE MORE TIME (Nathan V. Patwardhan)
     Re: Resource Kit Anomaly (Nathan V. Patwardhan)
     Scoring A Group of Arrays (Daniel G. Drumm)
     Re: Scoring A Group of Arrays (Jeremy D. Zawodny)
     Re: Scoring A Group of Arrays <rjk@coos.dartmouth.edu>
     Re: Scoring A Group of Arrays <rjk@coos.dartmouth.edu>
     Re: sort() corrupts data when using an "illogical" func (Tushar Samant)
     Re: sort() corrupts data when using an "illogical" func (Tushar Samant)
     Re: static variables in Perl? (Tushar Samant)
     Re: static variables in Perl? <tchrist@mox.perl.com>
     Re: Text to html perl script (Sweth Chandramouli)
     Trimming space (Ho Chiu Yin)
     Re: Window dies/string error (Tushar Samant)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sun, 30 Nov 1997 22:16:28 -0500
From: "R. Schramm" <schramm@one.net>
Subject: Re: Breaking out of an app
Message-Id: <65ta2k$nnq$1@news.one.net>

The "Expect" scripting language will allow you to control interactive
applications.  From your perl script, call expect and use it to launch your
app and then close it.  It even has an autoscript function that will watch
what you respond to from an application and builds a script based on the I/O
it sees.

Mark Lloyd wrote in message <3481c4b8.4860712@news>...
>I have a perl script which calls another app. This app unfortunately
>does not end with a single call and waits for another entry at the
>command line. What I need to do is break out of this app. Suggestions?
>
>
>Mark Lloyd
>Professional Services
>Bay Networks Canada




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

Date: Mon, 01 Dec 1997 01:15:52 -0500
From: jmf9946@is4.nyu.pam (Josh)
Subject: Re: Conditional compilation?
Message-Id: <jmf9936-ya02408000R0112970115520001@news.nyu.edu>

In article <Pine.GSO.3.96.971127100433.6576C-100000@usertest.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:

> On 26 Nov 1997, Jason Gloudon wrote:
> 
> > Thilo Goetz (goetz@watson.ibm.com) wrote:
> 
> > : So here it goes.  I wrote a lengthy perl script that uses some features
> > : of perl5, so it won't compile under perl4.  If somebody tries to run
> > : this script with an older version of perl, I'd like a controlled death
> 
> > Put it in a BEGIN block :
> > 
> > BEGIN { 
> >       if ($] < 5.0) { die "$0 error: needs perl v. 5 or better, aborting.\n"
> > }
> 
> BEGIN blocks don't work in Perl 4. Nice try! :-)

Is this not why god & Larry gave us numerical requires?

require 5.004;

though I don't have a perl4 handy to test it on, so it's probably wrong.

   - Josh

-- 
   O<     ( (     [ <http://omicron.nyu.edu/~jmf9936/> | ENXJ ]
 _NH >=O   ) )    [ jmf9936@is4.nyu.pam =~ s/pam/edu/ | DNRC O- ]
<_>-<_  + :::::-. [ "Coming Attractions: All dates are subject to ]
 HCl<O>   `:::'-' [ change." IBM http://watson.mbb.sfu.ca/software/ ]


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

Date: 29 Nov 1997 15:59:27 GMT
From: samiss@cc.tut.fi (Sami Sandqvist)
Subject: Re: For the pro's ? repost: Leaving HTML tags alone
Message-Id: <slrn680ev1.143.samiss@ehdo.ton.tut.fi>

On Wed, 26 Nov 1997 22:17:03 GMT, Jim Michael wrote:
>The particular case appears solvable with a simple substitution:
>
>$myString =~ s/([^"]?)http/$1Hyper Text Transfer Protocol/ig;

Maybe, but that is not it. As you can see, it always matches http
because the part in parenthesis is optional. Replacing it with
something like (^|[^"]) might work, but better answers have already
been posted in this thread.

ehdo:[~] % cat test.pl
#!/bin/perl -w
$_="  http  \"http";
s/([^"]?)http/$1Hyper Text Transfer Protocol/ig;
print "$_\n";

ehdo:[~] % ./test.pl
  Hyper Text Transfer Protocol  "Hyper Text Transfer Protocol
ehdo:[~] % 

Sami
-- 
Sami Sandqvist - samiss@cc.tut.fi
Finger for PGP key.


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

Date: 1 Dec 1997 04:48:16 GMT
From: "Donna Provancher" <donnapro@earthlink.net>
Subject: newcomer Q  - Perl - MS FrontPage - Windows95
Message-Id: <01bc874b$63ce6960$f0642299@donnapro>

Hello out there,

Re: build 5.003_7, Microsoft PWS

I'm trying to run Perl scripts through FrontPage. I'm getting internal
server error 500. I'm aware I could be using a canned library, but the
first question I have is, "did I download the right file(s) to begin with?"
and next, "have I installed Perl correctly?"  Finally, "what hasn't
Microsoft told me that I haven't figured out yet?"

Readme files say documentation is seriously out of date. Instructions on
where to put what are not consistent among resources. I could use some help
piecing together the results of two days of trial-and-error processing of
my learning curve.

Thanks in advance,
Donna

-- 
():-) Donna Provancher
donnapro@earthlink.net



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

Date: Sun, 30 Nov 1997 19:08:17 -0800
From: "Myles Lawrence" <myleslawrence@email.msn.com>
Subject: OLE
Message-Id: <OPZ0pWg$8GA.240@upnetnews02.moswest.msn.net>

Tried to use the perl OLE example to open the test.xls spreadsheet and
received a failed to initialize the user32.dll in winnt/system32
Anybody done any ole?
myleslawrence@msn.com




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

Date: 1 Dec 1997 03:26:20 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl Plug-In for Netscape?
Message-Id: <65taos$dol@fridge.shore.net>

Tad McClellan (tadmc@metronet.com) wrote:

: Where did you hear the allegations?

He might have been referring to the prototype written by Stan Melax
(if I'm correct, it used OpenGL).  To my knowledge, there hasn't been
another version of this plug-in, and the original only ran on Solaris
or Irix (I forget which).

--
Nathan V. Patwardhan



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

Date: 01 Dec 1997 14:50:30 +1100
From: Stuart Cooper <stuartc@ind.tansu.com.au>
Subject: Re: perlop clarification request
Message-Id: <yeoen3xiuwp.fsf@kudu.ind.tansu.com.au>

Bill Guindon <billg@networkapparel.com> writes:

> Ok, I'm doing what we are all told to do, R'ingTFM.
> 
> I've made it as far as PERLOP without hitting anything that seemed too
> unfathomable, but everyone has their limits.... here are some of mine:
> ----------------------------------------------------------------------

[snip]

  I'll have a crack at 2 of the questions here: the comma operator and 
the quoting question. Here goes:

> Comma Operator:
> "Binary ``,'' is the comma operator."
> 
> Too funny!  That one's almost biblical.  Left me expecting the next
> sentence to be "and the comma operator is binary ``,''".  Just a
> stupid thought, the questions follow.

  Well, if you're going to have something called a comma operator; it's best
that it's symbol is ','. The word 'binary' here means "accepting two arguments;
one on the left, one on the right". So the sentence means "there is a binary
operator which is called the comma operator, and its symbol is ``,''".

  Try this one on for size; from an Oxford English Dictionary I have seen:
LINCOLN GREEN: Green stuff made in Lincoln.

> "In a scalar context it evaluates its left argument, throws that value
> away, then evaluates its right argument and returns that value."
> 
> What would be the purpose of that?  If it's going to throw it away,
> why burn CPU cycles evaluating it?  If it's going to be thrown away,
> why would you burn keystrokes putting something before the comma?

  The comma operator comes from 'C'; where it has the same semantics.
Two possible uses:

  1) return a value of true for this statement regardless:

  $i_is_set = ($i=0, 1);

  almost certainly the left hand side (LHS) will be doing something useful; 
even though the programmer by using the comma operator disclaims interest in 
the return value. The LHS becomes a side-effect (which Lisp and
other functional programmers are addicted to) of the statement. ie "return
this; but sneak this in on the side". An example in the Blue Perl Book under
the select (output filehandle) function is:

  select((select(STDERR), $| =1)[0])

  2) ',' can be used as a ';' substitute.

  by far the most common use of this is in the for() statement when you need
to do more than one initialise or increment.

  for syntax: for (initialise;test;increment) {
                BODY
              }
  now in for() and probably nowhere else in 'C' or Perl ';'s are 
seperators-in-the-syntax and not statement terminators like usual. So if 
I have to do more than one thing; I use the ',' operator:

  for ($i=1,$j=1;   $i<10;      $i++, $j+=2) {
	$value=($i*$i)+($j*$j);
	print "$i squared + $j squared is $value\n";
  }

> I thought that meant the following code would print 'Second' (it
> didn't).  Could someone give me an example of it in use?
> 
>   $value = 'First', 'Second';
>   print $value;

  Almost. Precedence rules mean your code is ($value = 'First') , 'Second';
You have to bracket to get the behviour you're expecting:
$value = ('First', 'Second'); will give you $value == 'Second';

  Running Perl with the -w switch on this example will give you warnings like 
"Useless use of %s in void context" which perldiag will tell you all
about. In this example I'm using a comma operator without a side-effect
(the LHS of , is a useless scalar 'First') and Perl says "what?!?"

> Quote and Quotelike Operators
> Perl provides customary quote characters for these behaviors, but also
> provides a way for you to choose your quote character for any of them.
> 
> If you don't use the 'customary' quotes, does it follow the same rule
> that it does for pattern matching (see below)?
> 
>   "you can use any pair of non-alphanumeric, 
>   non-whitespace characters as delimiters"

  Yep. There's a very sensible rule Perl uses which I'll state like this:
"if you use an opening quote character that's like an opening bracket,
it will be closed by the equivalent closing bracket"

  Here's some examples:

$hw=q!Hello World!;	# my favourite character is ! usually
$hw=q(Hello World);     # '(' opens it, ')' closes it
$hw=q[Hello World];     #  [             ]
$hw=q{Hello World};     #  {             }
$hw=q]Hello World];     # allowed but ugly
$hw=q[Hello World[;     # syntax error- the matching char for '[' is ']' only

> ----------------------------------------------------------------------
> PLEASE POST ALL REPLIES TO COMP.LANG.PERL.MISC, As I'm sure there are
> others who 'WANT TO KNOW' but are 'AFRAID TO ASK'.

  Of course replies are posted to comp.lang.perl.misc. That's the right way.
It's people who ask 'please send the reply to my own email address because
I really don't check News that much...'  who get pinged. :)

Hope this helps,

Stuart Cooper
stuartc@ind.tansu.com.au


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

Date: 30 Nov 1997 22:41:28 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: perlop clarification request
Message-Id: <65tf5o$fo6@shoga.wwa.com>

billg@networkapparel.com writes:
>----------------------------------------------------------------------
>Multiplicative Operators:
>"@ones = (5) x @ones;        # set all elements to 5"
>
>Why does this work?  Why does it 'seem' that the second reference to
>'@ones' is giving the number of elements in the array?  I thought you
>had to use something along the lines of either '$#days' or
>'scalar(@whatever)' to achieve that.

An "x" to the left means a scalar context. So yes, it's equivalent to
doing scalar(@ones).


>----------------------------------------------------------------------
>C-style Logical (And/Or):
>"Scalar or list context propagates down to the right operand if it is
>evaluated."
>
>It sounds like they are saying a scalar could become a list.  Could
>someone give me an example of what they mean by this?

Doubtful example, but:

@a = ("yo", "whatsup") && 73;

This will set @a to (73). 73 got a list context, because it came in
from the @a=, and propagated through the first list.

The point is -- && is one of the operators which will do this -- as
opposed to say x above which will enforce scalar context on its right.


>----------------------------------------------------------------------
>Comma Operator:
>"Binary ``,'' is the comma operator."
>
>Too funny!  That one's almost biblical.  Left me expecting the next
>sentence to be "and the comma operator is binary ``,''".  Just a
>stupid thought, the questions follow.
>
>"In a scalar context it evaluates its left argument, throws that value
>away, then evaluates its right argument and returns that value."
>
>What would be the purpose of that?  If it's going to throw it away,
>why burn CPU cycles evaluating it?  If it's going to be thrown away,
>why would you burn keystrokes putting something before the comma?

For "side effects". Maybe it's useful in something like this:

$found = 0;
while (<HAYSTACK>) {
    ($found = 1, last) if /needle/;
}

One way of knowing if you finished the loop because you found needle
or for other reasons e.g. exhausting HAYSTACK.  

>I thought that meant the following code would print 'Second' (it
>didn't).  Could someone give me an example of it in use?
>
>  $value = 'First', 'Second';
>  print $value;

Assignment binds tighter than comma. If you did $value=("first","second");
you might get what you expected.


>----------------------------------------------------------------------
>Quote and Quotelike Operators
>Perl provides customary quote characters for these behaviors, but also
>provides a way for you to choose your quote character for any of them.
>
>If you don't use the 'customary' quotes, does it follow the same rule
>that it does for pattern matching (see below)?
>
>  "you can use any pair of non-alphanumeric, 
>  non-whitespace characters as delimiters"

Yes -- with the proviso for "bracketing" characters ({} () <> and []).


>----------------------------------------------------------------------
>Regexp Quotelike Operators /PATTERN/gimosx:  "If the PATTERN evaluates
>to a null string, the last successfully executed regular expression is
>used instead."
>
>Sounds like I can't trust the results.  I thought it would return a
>value of 'false' when the PATTERN is null.  It looks like it always
>returns 'true'?

No. "Logically" a match on a null string should always be true, because
everything matches a null string (or something). But Perl makes it mean
something else -- it remembers the last pattern match and APPLIES it.

This is not the same as remembering the last result of a pattern match.

"Successfully executed", of course, implies nothing about whether the
result was TRUE.

>The sample code below seems to confirm this fear (unless I screwed it
>up).  It even returned 'true' when NO other re had been evaluated yet!
>
>  if ($thisisa =~ //) {print 'This is a '.$thisisa.'\n'}
>  $thisisa = 'test';
>  if ($thisisa =~ /test/) {print 'This is a '.$thisisa.'\n'}
>  if ($thisisa =~ //) {print 'This is a '.$thisisa.'\n'}
>
>The first line produced 'This is a ',

Because the null string $thisisa matched the null pattern.

>                                  and the last two produced 'This
>is a test'.  WHY?  What's the benefit (how can I take advantage) of it
>resorting to 'old' results?

The middle one is obvious. The third one is precisely EQUIVALENT TO

$thisisa =~ /test/;

In other words if you had set $thisisa to say "fail" between the last
two statements, you would have gotten a different result. You could
also try $THATisa=~// etc; the point is the pattern /test/ is being
used again and again.  



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

Date: Mon, 01 Dec 1997 00:59:46 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: perlop clarification request
Message-Id: <34825252.90782A09@coos.dartmouth.edu>

Tushar Samant wrote:
> 
> >----------------------------------------------------------------------
> >Regexp Quotelike Operators /PATTERN/gimosx:  "If the PATTERN evaluates
> >to a null string, the last successfully executed regular expression is
> >used instead."
> >
> >Sounds like I can't trust the results.  I thought it would return a
> >value of 'false' when the PATTERN is null.  It looks like it always
> >returns 'true'?
> 
> No. "Logically" a match on a null string should always be true, because
> everything matches a null string (or something). But Perl makes it mean
> something else -- it remembers the last pattern match and APPLIES it.

Not quite.  See below...

> This is not the same as remembering the last result of a pattern match.
> 
> "Successfully executed", of course, implies nothing about whether the
> result was TRUE.

Actually, that is *exactly* what "sucessfully executed" means.

A null PATTERN is replaced with the last regular expression which
*successfully matched* its target string.


$a = $b = "foo";
$c = "bar";

if ($a =~ /o/) {          # "foo" =~ /o/   match
  print "1: $&\n";
}

if ($b =~ //) {           # "foo" =~ /o/   match
  print "2: $&\n";
}

if ($c =~ //) {           # "bar" =~ /o/   no match
  print "3: $&\n";
}

if ($a =~ /a/) {          # "foo" =~ /a/   no match
  print "4: $&\n";
}

if ($b =~ //) {           # "foo" =~ /o/   match
  print "5: $&\n";
}

if ($c =~ //) {           # "bar" =~ /o/   no match
  print "6: $&\n";
}


Outputs:
1: o
2: o
5: o

After the regexp in step 4 fails to match, the last successfully executed
match is still the one made by /o/ in step 1.  Thus, the null PATTERNs
in steps 5 and 6 and replaced by /o/.

Chipmunk


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

Date: Mon, 1 Dec 1997 03:54:22 GMT
From: swmcd@world.std.com (Steven W McDougall)
Subject: Re: Q: alternative to Perl?
Message-Id: <EKHs6M.K6E@world.std.com>

"Xah" <xah@best.com> writes:

>Are there alternative languages comparable to Perl with respect to text
>manipulation?

>I'm wondering because I'm not too thrilled by Perl's grammar, but need
>Perl's text manipulation power.

Can you be more specific?

Are there aspects of the grammar that you 
- don't understand?
- fear will lead to poor program structure?
- find unaesthetic?


- SWM


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

Date: 30 Nov 1997 23:45:01 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: Q: Learning perl with no progr. experience
Message-Id: <65tist$q36@shoga.wwa.com>

fl_aggie@thepentagon.com writes:
>+ >James - panther, catamount, mountain lion, whatever... :)
>+                   ^^^^^^^^^
>+ Please watch your language.
>
>Sorry. It's a regional name for mountain lion:
>
>cat a mount    (kat'e mount')  n.
>      1. a wild cat, esp. the cougar or the lynx. 
>      2.  CATAMOUNTAIN . 
>      [1655-65; short for CATAMOUNTAIN] 


Dang! I thought ... well never mind.

It would be pretty cool to call it the catamount book,
come to think of it.



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

Date: 1 Dec 1997 03:22:02 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: RESOURCE KIT ANOMALY... ONE MORE TIME
Message-Id: <65tagq$dol@fridge.shore.net>

Phil Houstoun (pjhousto@cse.dnd.ca) wrote:

: I posted a simple inquiry as to whether or not anyone else has
: encountered 'glitches' in the CPAN contained on the PRK CD-ROM. I
: did not entreat discussion on the worth of the PRK, or lack thereof,
[snip]

If these are the same things I encountered when working with the
Betas, I suspect that the problem is related to compressed files on
the CD (that's files with a .Z extension).  

If I recall correctly, the PRK setup tool uses the CPAN module.  The
CPAN module can't handle compressed files, although it can handle
gzipped files (CPAN::Config uses gzip, not compress) -- I believe that
some of the CHECKSUM files on the CD might have been compressed
(again, with a .Z extension), so this might be what you're
experiencing.  You can probably rectify this by cp -r the files you
want from the CD to another directory, uncompressing the CHECKSUM
file, then pointing the CPAN setup tool at the correct file:/ url.

Let me grab a copy of the CD and play with it to see if I can
replicate your problem.  I don't remember your original posting, so
please let me know if I'm offbase here.

--
Nathan V. Patwardhan




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

Date: 1 Dec 1997 03:11:36 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Resource Kit Anomaly
Message-Id: <65t9t8$dol@fridge.shore.net>

Peter J. Schoenster (pschon@baste.magibox.net) wrote:

: All I want to know is what is in the book before I buy it.  "A whole
: bunch of good modules" just doesn't cut it.  I don't need a FIXED
: version of CPAN; I much prefer the live online version.  If this book
: is just a snapshot of CPAN then I have to ask why have the internet?
[snip]

The Tk-based setup tool uses CPAN.pm -- this allows you to do
everything that you would have from the shell-based interface.  

I'm also working on CPAN::Tk.  The (Tk-based) setup tool is still
emerging, tho, so stay tuned.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 1 Dec 1997 03:36:47 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: Scoring A Group of Arrays
Message-Id: <65tbcf$91p$1@tepe.tezcat.com>

I have 26 arrays, @a to @z.
Each array has 26 numbers.
Each number is a random number from 1-100.

I wish to combine all 26 arrays into two data structures:

1. An array of all the numbers in the 26 arrays, discarding duplicates
2. A score of how many arrays a certain number appeared in.

The first one should be a list array, the second probably an associative.

I've played with some code, but my code seems slow. Part I is fine, but Part
II is inside a nested loop, and I get the feeling I'm not doing it as
quickly as I could.

Any pointers?

--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services


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

Date: Mon, 01 Dec 1997 04:14:13 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Scoring A Group of Arrays
Message-Id: <34823945.123364448@woody.wcnet.org>

[original author automagically cc'd via e-mail]

On 1 Dec 1997 03:36:47 GMT, dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
wrote:

>I have 26 arrays, @a to @z.
>Each array has 26 numbers.
>Each number is a random number from 1-100.
>
>I wish to combine all 26 arrays into two data structures:
>
>1. An array of all the numbers in the 26 arrays, discarding duplicates
>2. A score of how many arrays a certain number appeared in.
>
>The first one should be a list array, the second probably an associative.
>
>I've played with some code, but my code seems slow. Part I is fine, but Part
>II is inside a nested loop, and I get the feeling I'm not doing it as
>quickly as I could.

Actually, why can't you do it all with one hash (associative array)?
The "key" can be the number, and the "value" can be the number of
arrays it appears in.

If your code is slow, perhaps you're doing it in a slow way. Care to
post a relevant chunk that we can look at?

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: Mon, 01 Dec 1997 01:37:58 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Scoring A Group of Arrays
Message-Id: <34825B45.D1E2D5D4@coos.dartmouth.edu>

Daniel G. Drumm wrote:
> 
> I have 26 arrays, @a to @z.
> Each array has 26 numbers.
> Each number is a random number from 1-100.
> 
> I wish to combine all 26 arrays into two data structures:
> 
> 1. An array of all the numbers in the 26 arrays, discarding duplicates
> 2. A score of how many arrays a certain number appeared in.
> 
> The first one should be a list array, the second probably an associative.
> 
> I've played with some code, but my code seems slow. Part I is fine, but Part
> II is inside a nested loop, and I get the feeling I'm not doing it as
> quickly as I could.
> 
> Any pointers?

Once you've created the hash in step 2 (%scores, perhaps), the array for step
1 is simply
keys(%scores).  If necessary, sort {$a <=> $b} keys(%hash).

One way to create %scores:

{
  no strict 'refs';                          # allow soft references

  my($arr);                                  # array name counter
  for ($arr = 'a'; $arr le 'z'; $arr++) {    # count from 'a' to 'z'
    foreach (@$arr) {                        # loop over elements in array
      $scores{$_}++;                         # increment count
    }
  }
}

Although that counts each time a number appears, not the number of arrays each
number appears in.

{
  no strict 'refs';                          # allow soft references

  my($arr, %temp);                           # array name counter, temp hash
  for ($arr = 'a'; $arr le 'z'; $arr++) {    # count from 'a' to 'z'
    foreach (@$arr) {                        # loop over elements in array
      $temp{$_}++;                           # increment temp count
    }
    foreach (keys %temp) {                   # loop over unique numbers in
current array
      $scores{$_}++;                         # increment final count
      $temp{$_} = 0;                         # will this be faster than %temp
= () ?  [1]
    }
  }
}

That counts the number of arrays each number appears in.

[1]  Instead of clearing the %temp hash, I set each value to 0 as I go
through.  I'm guessing this could make the block faster overall, because it
won't have to reallocate the elements each time through.  Mind you, I am just
guessing.  :-)

Chipmunk


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

Date: Mon, 01 Dec 1997 01:43:32 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Scoring A Group of Arrays
Message-Id: <34825C92.D90B4F5A@coos.dartmouth.edu>

Woops!  I wasn't thinking clearly in my last post.

When I said:

$temp{$_} = 0;

I forgot that (keys %temp) would then be returning keys that should no longer
be there the next time through the for loop.

So, my second code block should be:

{
  no strict 'refs';

  my($arr);
  for ($arr = 'a'; $arr le 'z'; $arr++) {
    foreach (@$arr) {
      $temp{$_}++;
    }
    foreach (keys %temp) {
      $scores{$_}++;
    }
    %temp = ();
  }
}

Duh.  Sorry about that.

Chipmunk


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

Date: 30 Nov 1997 23:24:54 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: sort() corrupts data when using an "illogical" function to sort.
Message-Id: <65thn6$mp1@shoga.wwa.com>

dformosa@st.nepean.uws.edu.au writes:
>>"illogical". But I was wondering -- if the sort is exactly like
>>we see quicksort described in textbooks, what could possibly go
>>wrong?
>
>It isn't.  What is called when the qsort is called is something that that
>sorts what is given,  often its not a quick sort, it could be a merge sort
>or a heap sort or any other sort the peaple would implement.

A good reason for a canonical qsort, I guess... By the way, it's hard
for me to put this in words, but "pure" versions mergsort and heapsort
wouldn't care about inconsistent compares either, since they do a 
comparison and *move on* so to say...



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

Date: 30 Nov 1997 23:21:11 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: sort() corrupts data when using an "illogical" function to sort.
Message-Id: <65thg7$m69@shoga.wwa.com>

Thanks for the explanation. BTW, yes I checked out your web page since you
seemed so set on it... I am talking about http://home.att.net/~Tom.Horsley 
of course...

tom.horsley@worldnet.att.net writes:
>Depends on which textbook :-). This is actually a well known problem with
>some vendor's implementation of qsort. Some qsorts rely the initial best of
>3 sort in a partition moving array elements to the outer ends of the
>partition which they "know" will stop the scan when it hits them so they
>"know" they don't have to check the partition bounds, when the compare
>routine returns inconsistent results, the scan of the partition goes merrily
>whizzing past the end of the partition (and probably the end of the array as
>well) once that happens, anything can occur.
>
>I've been working on a qsort which I hope will eventually wind up built into
>perl. My qsort does not have this problem (which is a foolish "optimization"
>anyway, since calling the compare routine is vastly more overhead than
>checking an index value against the partition boundary).
>
>The latest and greatest version of my qsort routine can be found on my
>web page (see my signature below for a pointer). But beware, the current
>version isn't an adequate general purpose replacement since it does no
>optimization of array element swaps and moves (it just calls memmove or
>memcpy - a problem which will disappear when it is built into perl since
>perl always sorts the same size elements (pointers) and that can easily
>be optimized).
>--
>>>==>> The *Best* political site <URL:http://www.vote-smart.org/> >>==+
>      email: Tom.Horsley@worldnet.att.net icbm: Delray Beach, FL      |
><URL:http://home.att.net/~Tom.Horsley> Free Software and Politics <<==+




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

Date: 30 Nov 1997 23:10:09 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: static variables in Perl?
Message-Id: <65tgrh$knc@shoga.wwa.com>

jgoerzen+usenet@complete.org writes:
>Hi,
>
>In C, one can declare a variable inside a function to be static.  This
>causes that variable to be within only that function's scope (not
>ordinarily accessible elsewhere) but the variable is not recreated
>each time the function is called -- its contents are preserved.  Can a
>Perl subroutine do the same thing?  If so, how?  If not, why not?  Is
>there a better equivolent in Perl?

It's in the man pages somewhere -- probably perlsub -- but basically:

{
    my $static = 0;
    sub func {
	$static++;
    }
}

If a block like this gets executed func() will get defined with "static"
$static.

The "better equivalent" in Perl is the mechanism of closure -- which
generalizes the above. As a silly example:

{
    my $i = 0;
    sub incr {
	$i++;
	$i = 10 if $i > 10;
	$i;
    }
    sub decr {
	$i--;
	$i = -10 if $i < -10;
	$i;
    }
}

Now incr and decr share a value not seen by anyone outside. In a sense,
they are implementing an object.



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

Date: 1 Dec 1997 06:43:48 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: static variables in Perl?
Message-Id: <65tmb4$42q$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    scribble@shoga.wwa.com (Tushar Samant) writes:
:Now incr and decr share a value not seen by anyone outside. In a sense,
:they are implementing an object.

Because a closure is a binding of code and data, it can be used to
implement what might be thought of as an object.

Here's an example that creates and returns a hash of anonymous functions.
The mkcounter() function takes an argument of a seed counter, and returns
a hash ref that you can use to manipulate the counter indirectly.

    $c1 = mkcounter(20);
    $c2 = mkcounter(77);

    printf "next c1: %d\n", $c1->{"next"}->();  # 21
    printf "next c2: %d\n", $c2->{"next"}->();  # 78
    printf "next c1: %d\n", $c1->{"next"}->();  # 22
    printf "last c1: %d\n", $c1->{"last"}->();  # 21
    printf "old  c2: %d\n", $c2->{"reset"}->(); # 77

The code values in the hash references in $c1 and $c2 maintain
their own separate state.  Here's how to set that up:

    sub mkcounter {
	my $count  = shift;
	my $start  = $count;
	my $bundle = {
	    "next"   => sub { return ++$count  },
	    "last"   => sub { return --$count  },
	    "get"    => sub { return $count    },
	    "set"    => sub { $count = shift   },
	    "bump"   => sub { $count += shift  },
	    "reset"  => sub { $count = $start  },
	};
	$bundle->{"prev"} = $bundle->{"last"};
	return $bundle;
    }

Because the lexical variables are used by the closures in the $bundle
hash ref returned out of the function, they are not deallocated.  The next
time mkcounter() is called, the closures get a different set of variable
bindings for the same code.  Because no one outside of those closures
can access these two variables, this makes true privacy.

The assignment right before the return makes both the "prev" and "last"
values point to the same closure.  You can think of these as being two
different messages, both implemented using the same method.

One has to admit that the bundle we return is not an object in the sense
that it has inheritance and polymorphism, but it certainly does have
state, behaviour, and identify, plus of course encapsulation.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


At MIT the server is the unit of invention.  --Rob Pike


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

Date: 30 Nov 1997 23:41:24 -0500
From: sweth@gwis2.circ.gwu.edu (Sweth Chandramouli)
Subject: Re: Text to html perl script
Message-Id: <65tf5k$lc0@gwis2.circ.gwu.edu>

In article <652io6$98l@shoga.wwa.com>,
Tushar Samant <scribble@shoga.wwa.com> wrote:
>jeremy@lightningweb.com writes:
>>I need a script that can help me convert an entire directory of text files
>>to htmls with preconfigured headers and footers.
>
>Firstly, txt2html, as has been suggested, is not a complete solution.
>I see from its web page that it converts a single file. (Yes, I know
>you specifically said you wanted something more...)
>
>Are you on a Unix system? What do you mean when you say the .docs
>"format out as text"? How much HTML do you want in the final product?
>Just a <pre> - </pre> slapped on, or much more?

	i have a similar question, but with much more specific needs --
i'm trying to find a way to format all of our local man pages in html.
i've got a shell script that builds a list of all of the man pages in a
certain set of directories, and then creates an index of links to those
pages, each pointing to a cgi script that runs the man page through
deroff, and (as you put it) slaps <pre> and </pre> on it.
	what i'd _like_, however, is something that would build such an
index, but also correlate man pages in different sections together so
that instead of a listing like:

Section 1:
myscript
anotherscript

Section 2:
myscript


i would instead get

myscript (1) (2)
anotherscript (1)

with the links on the numbers, pointing appropriately.  also, it would be
nice if the man pages were formatted a bit more nicely than just being
preformatted text (e.g. having synopsis, etc. be headers).  the big
feature i would like is for references to other man pages to be links
pointing, again, to the same cgi page that would generate them on the fly.

	i think i could do most of these things on my own, given the time,
but i know that it wouldn't be fast or pretty; before i start (re)learning
perl, is there something out there already that can do this?

	tia,
	sweth.
-- 
 .


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

Date: 1 Dec 1997 06:39:44 GMT
From: 97Eyin@uxmail.ust.hk (Ho Chiu Yin)
Subject: Trimming space
Message-Id: <65tm3g$sg7@ustsu10.ust.hk>

I want to ask how to trimming left and right space of a string.
For example : $str = "   this is a test.      " to "this is a test."

Thanks
Stephen



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

Date: 1 Dec 1997 00:03:09 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: Window dies/string error
Message-Id: <65tjut$sgs@shoga.wwa.com>

mhol003@stat.auckland.ac.nz writes:
>When I submit a form for processing, 9 times out of 10 it works fine,
>but every now and then either the netscape window either vanishes or I
>get the error:
>
>A network error occurred while Netscape was sending data.
                                             ^^^^^^^
>(Network Error: XP_GetBuiltinString 7014 not found).
>
>Try connecting again.
>
>This only seems to be the case using Netscape 3, the program appears to
>run fine 100% of the time using Netscape 4.  
[etc]

Be at peace. It's almost certainly Netscape.



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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 1394
**************************************

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