[18124] in Perl-Users-Digest
Perl-Users Digest, Issue: 284 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 13 18:11:30 2001
Date: Tue, 13 Feb 2001 15:10:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <982105817-v10-i284@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest           Tue, 13 Feb 2001     Volume: 10 Number: 284
Today's topics:
        perl output to pop-up window <hbarwood@bluemarble.net>
    Re: perl output to pop-up window <kstep@pepsdesign.com>
        Q: printing IEEE float or double as hex <chuck.meyers@lmco.com>
    Re: Replacing single-letter words doesn't work <uri@sysarch.com>
        Simple GUI question  (TK) <shino_korah@yahoo.com>
    Re: Strings and pointers in Perl? (Gwyn Judd)
    Re: Strings and pointers in Perl? <mischief@velma.motion.net>
        Syntax quickie: How do I get the index of an arrayref? <pobbard@hotresponse.com>
    Re: Syntax quickie: How do I get the index of an arrayr <jdf@pobox.com>
    Re: Syntax quickie: How do I get the index of an arrayr (Clinton A. Pierce)
    Re: the best solution? <joe+usenet@sunstarsys.com>
    Re: the best solution? <mischief@velma.motion.net>
    Re: Using split to chop up a flat database file (Damian James)
        Wait for background processes jeacocks@uk.ibm.com
    Re: Wait for background processes jeacocks@uk.ibm.com
    Re: Wait for background processes (Abigail)
    Re: What  v65  refer to ? (Gary E. Ansok)
    Re: What  v65  refer to ? nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Feb 2001 15:57:34 -0500
From: Barwood <hbarwood@bluemarble.net>
Subject: perl output to pop-up window
Message-Id: <3A899FBE.40702@bluemarble.net>
I am trying to have html output from a perl script open in a pop-up 
window. I would like to know how I can modify my script or my form to do 
so. I am very new to perl and I could use a bit of help. I have an 
example of what I'm trying to do at 
http://www.mineralcollecting.org/showcase/new.html
The script I am using is as follows:
#!/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
$specurl = param('specurl');
$spectext = param('spectext');
$specheading = param('specheading');
print <<"JADAM";
<HTML>
<HEAD>
<TITLE>$specheading</TITLE>
</HEAD>
<BODY>
<H2>$specheading<br>$spectext<br><img src="$specurl"></H2>
</BODY>
</HTML>
JADAM
;
 
'spectext' is the specimen description, 'specurl' is the image url, and 
'specheading' is the heading for the page.
The page that I would like to use the pop-up's on is at 
http://www.mineralcollecting.org/showcase/  I want to use hidden fields 
to submit the text message and image url to the new window. As is, I am 
just using an onClick-open.window script that I found on a freebee site.
I don't even know if what I just said makes sense, but any help would be 
GREATLY appreciated.
~Adam
hbarwood@bluemarble.net
http://www.mineralcollecting.com/
http://www.mineralcollecting.org/
------------------------------
Date: Tue, 13 Feb 2001 18:04:36 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: perl output to pop-up window
Message-Id: <96cede$vn$1@slb6.atl.mindspring.net>
"Barwood" <hbarwood@bluemarble.net> wrote in message
news:3A899FBE.40702@bluemarble.net...
> I am trying to have html output from a perl script open in a pop-up
> window. I would like to know how I can modify my script or my form to do
> so. I am very new to perl and I could use a bit of help. I have an
> example of what I'm trying to do at
> http://www.mineralcollecting.org/showcase/new.html
Popup windows are a browser feature, controlled by the scripting language
running on the browser.  A Perl CGI script on the server can only pass
content to the browser.  Of course, theres no reason why that content can't
be javascript.
In your case, the current CGI script is fine for passing the content to the
popup window.  Try calling the script from the onClick handler in the client
script.
A more elegant solution would be to store the sample name, text, image
height, width and URL in either a database or a delimited text file.  Your
main sample page would be dynamically generated using a template for the
static parts such as the header and sidebar, and a lookup function that
would generate the links for each sample.  See the many *::Template modules
available on CPAN.  You will probably want to write a generic javascript
onClick handler to open the new window and set a default height and screen
position.  The URL opened by the window would call a second script on the
server.
(main page)
<script language="javascript">
<!--
function showSpecimen(specimen) {
    var queryURL = 'cgi-bin/show_specimen.pl?specimen=' + specimen;
    window.open(queryURL, [window options] );
}
-->
</script>
 ...
<body>
 ...
    <a href="#" onClick="showSpecimen('feldspar');">Feldspar</a>
Ths script show_specimen.pl is your original script, modified to perform the
lookup and resize the window.
#! /usr/bin/perl -wT
use strict;
use CGI;
use CGI::Carp;
my $q = new CGI;
print $q->header;
# Look up the information
my $spec = $q->param('specimen');
my ($heading, $text, $url, $height, $width) = lookup($spec);
print <<"JADAM";
<html>
<head>
<title>$heading</title>
</head>
<body onLoad='resizeTo($width, $height);'>
<h2>$specheading<br>$spectext<br><img src="$specurl"></h2>
</body>
</html>
JADAM
sub lookup {
    my $spec = shift;
    my ($heading, $text, $url, $height, $width);
    # get the data
    return ($heading, $text, $url, $height, $width);
}
HTH
Kurt Stephens
I don't know much about geology, but I'm not an igneous schist!
------------------------------
Date: Tue, 13 Feb 2001 14:36:13 -0800
From: Chuck Meyers <chuck.meyers@lmco.com>
Subject: Q: printing IEEE float or double as hex
Message-Id: <3A89B6DD.597BC8F9@lmco.com>
Is there a way within perl to print a float or double as a 32 or 64 bit
integer?
Are calling a C routine or picking the double apart bit by bit the only
options?
------------------------------
Date: Tue, 13 Feb 2001 19:18:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Replacing single-letter words doesn't work
Message-Id: <x7wvaumlxb.fsf@home.sysarch.com>
>>>>> "HM" == Holger Marzen <holger.marzen@sik-gmbh.de> writes:
  HM> On Mon, 12 Feb 2001 20:42:10 GMT, Uri Guttman wrote:
  >> perl -pe 's/\b\w\b/ /g'
  HM> Finally I found out that I cannot use \b if there are umlaut
  HM> characters contained in the strings. Perl accidentally sees the
  HM> "b" in "börse" as a single character delimited by a
  HM> non-word-character "ö". Setting the locale does not help. So I
  HM> found out how to build zero-width expressions that are neccessary
  HM> that all single-letter-words (and not every 2nd) are deleted in a
  HM> string:
hmm, that could be a bug in the definition of \b for your locale. double
check this with someone who knows the char set you are trying to use.
  HM> $suchtext =~ s/(^| )[A-Za-z0-9ÄÖÜäöüß]{1}(?=
  HM> [ ]|$)//g;
  HM> First it looks for the beginning-of-line or a SPACE.  Then for
  HM> exactly one of the characters
  HM> A-Za-z0-9ÄÖÜäöüß.  Then for end-of-line or a
  HM> SPACE, but that SPACE will be seen after the deletion.
some minor improvements. do you realize you will delete that leading
space if it exists? maybe put $1 in the replacement string to correct
that.
theres is no need for the {1} as 1 char is all a char class will ever
match by itself.
there is no need for [ ] to in the lookahead. in fact what if the space
you find is really a tab or newline? you might be better off matching a
\s there (and also in the beginning).
adding the /i modifier will allow you to use only A-Z and possibly match
more locale chars in the class. look into perl 5.6's support of posix
char classes which might solve the problem better. this is possible:
	s/(?<=[^[:alpha:]])[[:alpha:]](?=[^[:alpha:]])//g
assuming :alpha: works with your locale. there is an active german perl
community which would be of help to you here. i think they even have
their own newsgroup and probably some perl monger groups too. 
uri
-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com
------------------------------
Date: Tue, 13 Feb 2001 15:01:43 -0800
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Simple GUI question  (TK)
Message-Id: <96cecn$nc@news.or.intel.com>
I'm using windows NT and my perl scrip gives 2 errors..can anyone help me
out
My code::
use Tk;
$top = MainWindow->new();
$top->title("FIRST GUI");
$s=$top->Label(text =>'Wassup shino?',anchor =>'n',relief =>'groove',width
=>100,height =>30);
$button = $top->Button(text =>'Start',command =>\&change_label);
$s->pack();
$button->pack();
$bev="coffee";
$coffee = $top->Radiobutton(variable=>\$bev,text =>'Coffee',value
=>'coffee');
$tea = $top->Radiobutton(variable=>\$bev,text=>'Tea',value =>'tea');
$coffee->pack(side=>'left');
$tea->pack(side=>'left');
$t=$top->Text(width=>80,height=>10)->pack();
######################################################
#Error here
$t->insert("Sample","end");
########################################################
MainLoop();
sub change_label()
{
$button->cget('text') eq "Start" ?
$button->configure(text=>'Stop') : $button->configure(text=>'Start');
}
when I compile it says--> bad text index "Sample".
Please help:)
------------------------------
Date: Tue, 13 Feb 2001 21:44:45 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Strings and pointers in Perl?
Message-Id: <slrn98jamc.adq.tjla@thislove.dyndns.org>
I was shocked! How could Frank van Wensveen <fw@lanvision.nl>
say such a terrible thing:
>I'm originally a C programmer, and now I'm trying port a piece of C
>code to Perl. Nasty business. :-) Typical C practices won't work. 
Yeah, better to write your Perl program in Perl rather than attempting
too close a translation. Things that work well in C don't tend to
translate well.
>I have a string s which I'm scanning with a pointer p from begin to
>(\0-terminated) end, in C:
>
>char *p, *s;
>
>p = s;
>while (*p) {
>  /* do something to *p */
> p++;
>}
There is a few ways but you don't really say what it is you are doing to
the string so that influences things. The closest translation of the
above would probably involve using the substr() function:
for my $i (0..length $s)
{
    my $p = substr $s, $i, 1;
    # do something to $p
    substr($s, $i, 1) = $p;
}
but this is probably incredibly inefficient for what you want to do. A
more idiomatic solution would possibly be to use a regular expression
(which are pervasively used in Perl) and can allow you to work with the
whole string at once.
$s =~ s/hi/bye/ig; # substitute all instances of the word 'hi' with the
                    # word 'bye, case insensitive
As you can see they are very powerful. See the documentation:
perldoc perlre
perldoc perlop
perldoc -f substr
-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
If in any problem you find yourself doing an immense amount of work, the
answer can be obtained by simple inspection.
------------------------------
Date: Tue, 13 Feb 2001 22:21:44 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Strings and pointers in Perl?
Message-Id: <t8jcro1kgu7fe8@corp.supernews.com>
Frank van Wensveen <fw@lanvision.nl> wrote:
> I'm originally a C programmer, and now I'm trying port a piece of C
> code to Perl. Nasty business. :-) Typical C practices won't work. 
> I have a string s which I'm scanning with a pointer p from begin to
> (\0-terminated) end, in C:
Others have already given you excellent advice. I just thought I'd
mention substr(), which can be used to get one character at a time
from a string (among other things) without using an array _or_ regular
expressions. There's More Than One Way To Do It. As a matter of fact,
TMTOWTDI is a sort of Perl slogan.
Learn to use perldoc while you're learning to use Perl (or use man
for the Perl docs if you're on a Unix-like system). The following
can get you the information about how to use substr:
        perldoc -f substr
        perldoc perlfunc
        man perlfunc
You can also look at http://www.perldoc.com for docs or look at
HTML docs for Perl on you hard drive if you have ActiveState Perl
for Windows isntalled.
Chris
-- 
Christopher E. Stith
------------------------------
Date: Tue, 13 Feb 2001 17:31:09 -0500
From: "Philip Obbard" <pobbard@hotresponse.com>
Subject: Syntax quickie: How do I get the index of an arrayref?
Message-Id: <96cc92$1sb$1@taliesin.netcom.net.uk>
Hi all,
I know this must be something simple, but I've been combing my O'Reilly
books and can't seem to get the syntax right.
Question: I know I can get the index of @items by using $#items. But if
$items is actually an arrayref, which variable to I use?
Thanks,
Philip
------------------------------
Date: 13 Feb 2001 17:45:05 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Syntax quickie: How do I get the index of an arrayref?
Message-Id: <66ieb3ta.fsf@pobox.com>
"Philip Obbard" <pobbard@hotresponse.com> writes:
> Question: I know I can get the index of @items by using $#items. But
> if $items is actually an arrayref, which variable to I use?
You don't get the "index" of anything from @items in a scalar context;
you get the number of elements in @items.  To get the number of
elements in $aref, you use @$aref in a scalar context.
-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Tue, 13 Feb 2001 22:51:09 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Syntax quickie: How do I get the index of an arrayref?
Message-Id: <xTii6.308601$hD4.73387923@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <96cc92$1sb$1@taliesin.netcom.net.uk>,
	"Philip Obbard" <pobbard@hotresponse.com> writes:
> I know this must be something simple, but I've been combing my O'Reilly
> books and can't seem to get the syntax right.
Sure!
> Question: I know I can get the index of @items by using $#items. But if
> $items is actually an arrayref, which variable to I use?
The "index"?  No $#items would give you the index of the last element.
Watch this:
It it were @foo, then you could say $#foo.  It's not, but remember 
this arrangement anyways.
But $items is an array ref.  It's a stand-in for an array.  The whole 
array (using $items as a ref) is:
	@{$items}
Now, just treat {$items} as though it were the array name and continue
onward doing what you were doing before:
	$#{$items}
And that gives the index of the last element.  It's ugly, but there 
ya go.  Please tell me you're not going to say:
	$items->[$#{$items}];  # or worse...
	${$items}[$#{$items}];
Because I will have to hurt you then.  :)
PS: If you're just after the last element itself, then use $i->[-1]
instead.  It looks nicer.  If you're trying to find out how many things
are in the array referenced by $i then use @$i in a scalar context like:
$count=@$i+0 or $count=scalar $@i.
-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: 13 Feb 2001 14:26:29 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: the best solution?
Message-Id: <m3u25yidui.fsf@mumonkan.sunstarsys.com>
Chris Stith <mischief@velma.motion.net> writes:
> I have little time to do comprehensive testing for other people. I
> showed my results and the OP is free to test it himself. I showed in
> my post how he could do that. So, what's your problem with that?
Not much at all.  What I objected to was you attempts to guess
at a reason why your results turned out the way they did. And
quite frankly, it appeared to me that you hand-picked the conditions
of you test for dramatic effect.  Based on the results below,
I hope you'll understand why I felt that way.
> I only offered benchmarks in the first place because the OP
> wanted to know. I warned that Perl is probably not the right
> langauge if memory usage and speed are a concern. Get the
> hell off your high horse and join the rest of us in responding
> to what the OP has asked. You say "big deal" to exactly what
> the OP asked for. I don't consider that very helpful. If you're
> going to critique my posts, at least take the time to read the
> thread first.
Here's the original post:
==================================================
Hi all,
I know this seems like a simple problem but I can't figure out 
the best way of doing this so I thought i would seek advice!
I am searching strings for the occurances of a term, as I see it 
the are (obvious) options:
1. Short loop with index of function loop while index != -1 
incrementing a counter
2. Create a temp copy of string and use the replace function to 
return the number of occurances
Memory/performance is a major issue for the application, so I 
reckon the temp string method is the best
I was wondering if is there a less costly method !
Any Advice would be greatly appreciated, any insults/abuse will 
be accepted with a good natured smile and a promise not to ask 
such simplistic questions!
==================================================
Seems to me you totally ignored suggestion number 1; in my
original followup I posted a sub that implements this for him 
to test it out. Yet you choose to ignore that suggestion as 
well, which is exactly what OP wanted to compare against.
Since you apparently do not have the time to be bothered to 
test it, I'll do it for you: (OP's first solution is labeled GZ)
linux 2.2, perl 5.6
multiplier:    x1           x10        x 100
        CS: 54175.80/s   10440.43/s   1217.68/s
        GZ: 63679.60/s   13039.60/s   1454.10/s
        OP: 48816.88/s   10448.85/s   1208.23/s
 OP_option: 64397.70/s   11012.56/s   1209.23/s
linux 2.2, perl 5.005_03
        CS: 57416.70/s   12962.74/s   1516.52/s
        GZ: 53227.17/s   10553.90/s   1179.82/s 
        OP: 46717.86/s   12561.24/s   1507.92/s
 OP_option: 78177.13/s   14048.68/s   1528.20/s
#!/usr/bin/perl -w
use strict;
use Benchmark;
                                        # MULTIPLIER 
my $string = 'substring of string' x 1; # x1 , x10, x100
my $count = 0;
timethese -10, {
    'CS' => \&CS,
    'GZ' => \&GZ,
    'OP' => \&OP,
    'OP_option' => \&OP_option,
};
sub CS {
    $count = $string =~ s/string/string/g;
}
sub OP {
    my $temp_string = $string;
    $count = $temp_string =~ s/string//g;
}
sub OP_option {
    $count = 0;
    $count++ while( $string =~ /string/g );
}
sub GZ {
    my $i = $count = 0;
    ++$count while ( ($i = 1+index($string,"string", $i)) > 0);
}
__END__
> >   sub LAiSC {
> >         $count = () = $string =~ /string/g;  
> >   }
> 
> I thought about offering that one myself. However, the OP stated
> explicitly that he needed speed and memory efficiency. He also
> mentionbed two possible solutions he wanted to compare, neither
> of which is the above.
And only one of those you did bother to actually test.
Not as helpful as you might have imagined if he's using 
5.6 with linux. And oh, did you consider the possibility 
that maybe he needed that efficiency because his strings 
were quite large?  I guess it didn't matter much to you  
since you didn't ask.
-- 
Joe Schaefer   "There is nothing so annoying as to have two people talking when
                                  you're busy interrupting."
                                               --Mark Twain
------------------------------
Date: Tue, 13 Feb 2001 21:44:06 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: the best solution?
Message-Id: <t8jal6tohf9535@corp.supernews.com>
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> Chris Stith <mischief@velma.motion.net> writes:
>> I have little time to do comprehensive testing for other people. I
>> showed my results and the OP is free to test it himself. I showed in
>> my post how he could do that. So, what's your problem with that?
> Not much at all.  What I objected to was you attempts to guess
> at a reason why your results turned out the way they did. And
> quite frankly, it appeared to me that you hand-picked the conditions
> of you test for dramatic effect.  Based on the results below,
> I hope you'll understand why I felt that way.
No, unfortunately I don't. I tried to present what I felt were
the most relevant results. I think it's good to show the results
and the version info, then let the OP decide. I do think it's
good for the OP that you and I get differing results with
different versions of perl and both post. That gives perspective.
What I would understand is if you thought I was becoming hostile
in my last post, which I didn't mean to do. I'm having a bad day
and I'm sorry to be short with you, Joe. Please accept my
apologies with the thought that this post should be (somewhat)
better. Maybe tomorrow I can get to the doctor and get some
painkillers for my dislocated hip ;)
Perhaps in the future I'll try to mention just how many times
I've run each benchmark and with exactly which data sets.
Maybe I'll even write a complete testing framework for every
post to which I respond. The results below still show the
fastest option, given the version of perl I reported I was
using, is the one I said seemed to be the fastest. In your
own results using version 5.005_03, it is the fastest in every
case you cover.
> Here's the original post:
[snip original post in thread]
How well did you read my post? Where did I say, "I've only
tried these things exactly as shown and they are not indicative
of any other testing"?
> Seems to me you totally ignored suggestion number 1; in my
> original followup I posted a sub that implements this for him 
> to test it out. Yet you choose to ignore that suggestion as 
> well, which is exactly what OP wanted to compare against.
> Since you apparently do not have the time to be bothered to 
> test it, I'll do it for you: (OP's first solution is labeled GZ)
The original post mentions a short loop and a counter. I wrote
something with a short loop and a counter. I misread a bit and
didn't use index. My mistake. *eats hat*
On the version of perl I'm using, the OP_option method is 25%
faster than the GZ method at the high end of your own testing.
It's 50% at the low end. Perl 5.6 does change this quite a bit.
The OP doesn't state what version of perl he's using. I did
mention my perl version in case their was anything version
dependent (since there usually is).
Perl is a great language, and perl is pretty consistent in
semantics from version to version. However, it's expected
that interpreter upgrades optimize certain situations
differently from prior versions.
> linux 2.2, perl 5.6
> multiplier:    x1           x10        x 100
>         CS: 54175.80/s   10440.43/s   1217.68/s
>         GZ: 63679.60/s   13039.60/s   1454.10/s
>         OP: 48816.88/s   10448.85/s   1208.23/s
>  OP_option: 64397.70/s   11012.56/s   1209.23/s
So OP_option is still the fastest on short strings, second
fastest on fairly long and comparable to the method that's
second fastest on very long strings?
> linux 2.2, perl 5.005_03
>         CS: 57416.70/s   12962.74/s   1516.52/s
>         GZ: 53227.17/s   10553.90/s   1179.82/s 
>         OP: 46717.86/s   12561.24/s   1507.92/s
>  OP_option: 78177.13/s   14048.68/s   1528.20/s
So, given the same version I mentioned I was using for
benchmarking, OP_option does 147% the work of the method
using index on hort strings? It does 133% the work on
fairly long strings? It does 130% the work on long
strings?
Given the same version and the same results, provided by
you, the index option is the slowest by a good margin in
the fairly long and long string tests?
So, given all of this, and given the OP asked for the
best possible solution, could I reasonably tell him that
index would be the best solution for the version of Perl
I'm using? Did I have much way of knowing whether or not
he's using the same version I'm using? Many people do
use 5.005_03. I use it on all of my production systems.
I'm still considering when to make the jump to 5.6.0 on
those systems. Sure, I have one machine running 5.6 for
structured troubleshooting on code I write for open Source
projects, but I hardly ever access that machine, let alone
that version of the interpreter on it (it runs 5.005_03
as /usr/bin/perl and additionally runs other versions of
the interpreter just for testing including 4.0). I don't
post news from that box, and I don't usually open yet
another login to test code bound for newsgroups.
> #!/usr/bin/perl -w
> use strict;
> use Benchmark;
>                                         # MULTIPLIER 
> my $string = 'substring of string' x 1; # x1 , x10, x100
> my $count = 0;
> timethese -10, {
>     'CS' => \&CS,
>     'GZ' => \&GZ,
>     'OP' => \&OP,
>     'OP_option' => \&OP_option,
> };
> sub CS {
>     $count = $string =~ s/string/string/g;
> }
> sub OP {
>     my $temp_string = $string;
>     $count = $temp_string =~ s/string//g;
> }
> sub OP_option {
>     $count = 0;
>     $count++ while( $string =~ /string/g );
> }
> sub GZ {
>     my $i = $count = 0;
>     ++$count while ( ($i = 1+index($string,"string", $i)) > 0);
> }
> __END__
>> >   sub LAiSC {
>> >         $count = () = $string =~ /string/g;  
>> >   }
>> 
>> I thought about offering that one myself. However, the OP stated
>> explicitly that he needed speed and memory efficiency. He also
>> mentionbed two possible solutions he wanted to compare, neither
>> of which is the above.
> And only one of those you did bother to actually test.
> Not as helpful as you might have imagined if he's using 
> 5.6 with linux. And oh, did you consider the possibility 
> that maybe he needed that efficiency because his strings 
> were quite large?  I guess it didn't matter much to you  
> since you didn't ask.
Maybe he needs the efficiency because he has several instances
of the program running at once. Maybe he needs efficiency because
it's running on a server already bogged down with other software
running. He didn't mention in the first place.
There's not a good way to profile or benchmark Perl for memory
usage. I'm not a regular at hacking the core, so I don't always
have good estimates. What I can do is test a few things for speed
and specification and give feedback.
I would have included more detailed test results, but I'm already
on the top 10 list for highest volume most of the time, even when
I'm not on it for number of posts. I thought maybe someone would
appreciate an attempt at a less voluminous post. This time it's 
probably clear I didn't try for brevity. I'm not always as clear
when I try to be concise. I need to take lessons from Abigail or
Randal.
Come to think of it, if I could afford to, I'd love to take Perl
lessons from Randal. As things are, the free advice in the
newsgroups will suffice. Too bad StuporNews doesn't carry alt.perl,
which I understand is getting more attention from (some of) the
gurus these days. I'd hate to have to wade through Dejoogle,
especialy since you can't even post from there for now.
All in all, I do understand you're trying to be helpful to the OP,
Joe. What I don't understand is why you'd think I have an agenda
to promote certain Perl built-in functions over others or why you'd
assume that any results not shown are either benchmarks not performed
or are withheld with malice aforethought.
I also understand that your benchmarks are more helpful to someone on
5.6.0 than mine, but I did mention my Perl version. Yours also help
point out some nice additional optimizations in 5.6.0 compared to the
5.005_03 version. I don't understand why you would assume the OP isn't
using 5.005_03, since many people do.
I understand (as I mentioned in my prior posts) that Perl is not the
best language to use if the OP's number one and number two priorities
are memory and speed (or vice versa). If using Perl is an even higher
priority than speed or memory but those are still considerations, then
benchmarks _can_ help.
In fact, I feel often that memory and speed are sometimes _more_ of an
issue with Perl than with C. There are several applications for which I
use Perl for its many benefits which might be just too slow or use just
too much memory written a certain way in Perl but just fast enough or
use just little enough memory written a different way in Perl. In these
cases, even a poor C implementation would usually suffice (which it
probably would be, since I only touch C when I feel I must). There is a
lot of gray area in which Perl _might_ be fast enough or _might_ use
little enough memory. I think this is often only part of the decision
process between choosing Perl for a project and choosing C, since Perl
can be so much easier to port and distribute. We like to say to choose
Perl when programmer time matters and to choose C when running time
matters, but when they are are both important, which is to be chosen?
Perhaps Inline.pm should be in every Perler's toolbox.
Chris
-- 
Christopher E. Stith
Disclaimer: Actual product may not resemble picture in ad in any way.
------------------------------
Date: 13 Feb 2001 22:55:05 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Using split to chop up a flat database file
Message-Id: <slrn98jepp.iub.damian@puma.qimr.edu.au>
Thus spake Michael on Tue, 13 Feb 2001 02:11:15 GMT:
>...
>
>open(FILE,"testfile");
>$/="LAST";  #split recs 
>@recs = <FILE>;
>close(FILE);
>
You're not using split at all (you liar :-). You're changing the input record
separator to match something in your data, with predictable results. Go
have a look at perlvar, think about what happens when the IRS is a newline,
and you should see why you are getting the results you see.
To snarfle the data you provided in to a Perl data structure, you might
rather do something like:
#!/path/to/perl -w
use strict;
open(FILE, "testfile");
#leave the IRS the way it was!
my @records = ();
my $index = -1;
while (<FILE>) {
    ++$index if /^LAST/;
    chomp;
    my ($key, $value) = split ": ";
    $records[$index]->{$key} = $value;
};
close FILE;
for my $record (@records) {
    print "--------------------------\n";
    for (keys %{$record}) {
        print "$_ = $records[$index]->{$_}\n";
    };
};
__END__
See:
	perldoc -f split
	perldoc perldsc
for details.
HTH
Cheers,
Damian
-- 
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,;ord($&)-$:-$;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval;               #requires 5.6.0 ## my first attempt at one of these...
------------------------------
Date: Tue, 13 Feb 2001 19:09:46 +0000
From: jeacocks@uk.ibm.com
Subject: Wait for background processes
Message-Id: <96c0rn$vsg$1@sp4en10.hursley.ibm.com>
I want to launch a group of commands in the background using system, then 
I want the perl script to wait until all of the background processes have 
finished before exiting. At the moment I am doing something like,
system("sleep 10 &");
system("sleep 10 &");
------------------------------
Date: Tue, 13 Feb 2001 19:49:23 +0000
From: jeacocks@uk.ibm.com
Subject: Re: Wait for background processes
Message-Id: <96c35u$p20$1@sp4en10.hursley.ibm.com>
Sorry, my news reader cut the message short....
I want to launch a group of commands in the background using system, then 
I want the perl script to wait until all of the background processes have 
finished before exiting. At the moment I am doing something like,
system("sleep 10 &");
system("sleep 10 &");
while(1) {
        if ( wait() == -1 ) {
                last;
        }
}
But this just exits straight away, any ideas?
Thanks in advance
Stewart Jeacocke
jeacocks@uk.ibm.com
------------------------------
Date: 13 Feb 2001 20:35:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Wait for background processes
Message-Id: <slrn98j6jo.u8.abigail@tsathoggua.rlyeh.net>
jeacocks@uk.ibm.com (jeacocks@uk.ibm.com) wrote on MMDCCXXIII September
MCMXCIII in <URL:news:96c35u$p20$1@sp4en10.hursley.ibm.com>:
== Sorry, my news reader cut the message short....
== 
== I want to launch a group of commands in the background using system, then 
== I want the perl script to wait until all of the background processes have 
== finished before exiting. At the moment I am doing something like,
== 
== system("sleep 10 &");
== system("sleep 10 &");
== while(1) {
==         if ( wait() == -1 ) {
==                 last;
==         }
== }
== 
== But this just exits straight away, any ideas?
system() forks a child and if the argument contains a character special
to the shell (like &), it invokes the shell and have the shell execute
the command. Which the shell does, putting sleep in the background, then
it returns (it's done).
sleep is not the child of your program - the shell is.
Here's something that might work for you (depending on your OS, there
are subtle differences. Study man perlipc. Study your system API, as
Perl depends on it).
    #!/opt/perl/bin/perl -w
    for (1, 2) {
        my $pid = fork;
        die "Can't fork: $!\n" unless defined $pid;
        unless ($pid) {
            exec sleep => 10;
            die "Failed to exec: $!";
        }
    }
    use POSIX ":sys_wait_h";
    my  $kid;
    do {$kid = waitpid -1 => WNOHANG} until $kid == -1;
    __END__
Abigail
-- 
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
          for (s;s;s;s;s;s;s;s;s;s;s;s)
              {s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'
------------------------------
Date: 13 Feb 2001 20:07:10 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: What  v65  refer to ?
Message-Id: <96c45e$osm@gap.cco.caltech.edu>
In article <n1bqbiik.fsf@pobox.com>, Jonathan Feinberg  <jdf@pobox.com> wrote:
>"Daniel Piché" <dpiche@speedware.com> writes:
>>    ie:    $href = {  v65 => 'some value', .... }
>> As a test, I try:    print v65  and I got   A  (humm!!)
>
>> So, my question is the following, what does v[0..9]* represent in
>> Perl and why it does'nt work the way I have use it?
>
>The v[0-9]+ notation for character strings is documented in the
>perldata manual.
It seems to me to be a bug that $href = { v65 => 1 }; print $href->{v65};
doesn't work.  
I think I'd rather have both refer to $href->{'v65'}, but I could live 
with both referring to $href->{'A'}.
Perl should be more consistent on when v65 is to be an ordinary word and 
when it is to be a version string.  Aren't both of these contexts
documented to treat the bareword as a double-quoted string if it's
a "word"?
-- Gary Ansok
------------------------------
Date: 13 Feb 2001 20:35:47 +0000
From: nobull@mail.com
Subject: Re: What  v65  refer to ?
Message-Id: <u9lmragw2k.fsf@wcl-l.bham.ac.uk>
"Daniel Piché" <dpiche@speedware.com> writes:
> While creating an unnamed hash table, I entered  v followed by digits as the
> key
>    ie:    $href = {  v65 => 'some value', .... }
> I was not abel to retrieve that key later on (remember, left-end side are
> treated as string).
This is, IMNSHO, a bug.
 
> As a test, I try:    print v65  and I got   A  (humm!!)
> 
> So, my question is the following,  what does  v[0..9]* represent in
> Perl 
They "version tuples" documented as in perldata:
    A literal of the form v1.20.300.4000 is parsed as a string composed of
    characters with the specified ordinals. This provides an alternative,
    more readable way to construct strings, rather than use the somewhat
    less readable interpolation form "\x{1}\x{14}\x{12c}\x{fa0}". This is
    useful for representing Unicode strings, and for comparing version
    ``numbers'' using the string comparison operators, cmp, gt, lt etc. If
    there are two or more dots in the literal, the leading v may be
    omitted.
	print v9786;              # prints UTF-8 encoded SMILEY,
	"\x{263a}"
	print v102.111.111;       # prints "foo"
	print 102.111.111;        # same
> and why it does'nt work the way I have use it?
It is a bug in 5.6.0.  I have been unable to find it on bugs.perl.org
but it's probably related to the second bug reported in 20000511.002.
I am able to reproduce the bug in 5.7.0.
The problem is that the quoting action of => is implemented as an ugly
hack in toke.c.  When the special case for 'v' was added this hack was
not reproduced:
--- perl-5.7.0/toke.c	Fri Sep  1 14:59:20 2000
+++ perl-5.7.0-bam/toke.c	Tue Feb 13 20:05:30 2001
@@ -3594,6 +3594,22 @@
 	    else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF)) {
 		char c = *start;
 		GV *gv;
+	        char *d = start;
+
+	        while (d < PL_bufend && isSPACE(*d))
+		    d++;
+
+  	        /* Is this a word before a => operator? */
+	        if (*d == '=' && d[1] == '>') {
+		    CLINE;
+		    *start = '\0';
+		    yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
+		    *start = c;
+		    yylval.opval->op_private = OPpCONST_BARE;
+		    s = start;
+		    TERM(WORD);
+	        }
+
 		*start = '\0';
 		gv = gv_fetchpv(s, FALSE, SVt_PVCV);
 		*start = c;
I've not submitted this to perlbug (ID 20010213.008).
I've not yet written the corresponding test cases.
> PS:  It's my first week using Perl.
And you've found an interpreter bug already!  This is unusual.
-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V10 Issue 284
**************************************