[8507] in Perl-Users-Digest
Perl-Users Digest, Issue: 2124 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 18 07:07:21 1998
Date: Wed, 18 Mar 98 04:00:30 -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 Wed, 18 Mar 1998 Volume: 8 Number: 2124
Today's topics:
Re: argh!! how do I overwrite part of a preexisting fil <tchrist@mox.perl.com>
Re: Bitwise? (Jim Michael)
building for perl 5.004_04 on NT Frank@but_dont_use_this.address
Re: building for perl 5.004_04 on NT <uwe.honekamp@etas.de>
Re: building for perl 5.004_04 on NT Frank@but_dont_use_this.address
Re: contexts: is there such a thing as array? <tchrist@mox.perl.com>
Re: Date function - yyyymmdd format parkesb@yahoo.com
Re: Date function - yyyymmdd format <zenin@archive.rhps.org>
Re: Date function - yyyymmdd format <Tony.Curtis+usenet@vcpc.univie.ac.at>
executing cgi script problems heitkamp@hotmail.com
Re: executing cgi script problems sloop@mailcity.com
Re: grep on hashes <tchrist@mox.perl.com>
Re: MS PWS won't run CGI pfranken@c2.telstra-mm.net.au
Re: Multiple substitues <sottek@quiknet.com>
Re: Multiple substitues (Bart Lateur)
Re: need perl script to read utmp files [Not Perl] <maxin@iscs.nus.edu.sg>
Re: need perl script to read utmp files <qdtcall@esb.ericsson.se>
Re: parsing perl (Mike Heins)
Re: Perl system() calls on NT w/IIS <tom@imagic.be>
Re: Problem of auto-increment in s///; (David Oswald)
Re: Problem of auto-increment in s///; parkesb@yahoo.com
Re: Problem of auto-increment in s///; (Michael Fuhr)
Re: Q: Threads (in 5.004_62) and signals (Malcolm Beattie)
Re: Variable question <tchrist@mox.perl.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Mar 1998 15:11:56 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: argh!! how do I overwrite part of a preexisting file?
Message-Id: <6em3rs$5hv$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
"Andy Lindeman" <andy.lindeman@digital.com> writes:
:Hi-
:
:I need to overwrite the first few characters in a preexisting file, but
:can't figure out what mode I should open the file in.
open(FILE, "+<$filename");
Or just use
use Fcntl;
sysopen(FILE, $filename, O_RDWR);
# but then use sysseek
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I am a little more weird today than normal. --Andrew Hume
------------------------------
Date: Wed, 18 Mar 1998 10:57:53 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: Bitwise?
Message-Id: <genepoolEq0H4H.I3t@netcom.com>
rfonline@nbn.com wrote:
: Greetings,
: I have a set of "items," which are represented by a series of 0s and
: 1s. For example, an item might look like this:
: 10011
: I am comparing the items to see how "alike" they are, that is, how
: many characteristics they have in common. For example:
: 10011
: 00000
: The above two items have two characteristics in common (the second and
: third).
Assuming you have mapped your bits into numbers in $A and $B,
the check for high bit matches would be $A & $B, and the check
for low bit matches would be ~$A & ~$B, so the check for all
matches would be ($A & $B) | (~$A & ~$B).
$A: 1001
$B: 0011
$A & $B: 0001
~$A: 0110
~$B: 1100
~$A & ~$B: 0100
($A & $B) | (~$A & ~B) = 0001 | 0100 = 0101
HTH.
Cheers,
Jim
------------------------------
Date: 18 Mar 1998 08:43:07 +0100
From: Frank@but_dont_use_this.address
Subject: building for perl 5.004_04 on NT
Message-Id: <yo9lnu8la0k.fsf@nym.sc.philips.com>
Hello all,
I'm trying to build perl 5.004_04 on NT 4.0 SP3. I'm using the source
code which can be compiled on unix systems too.
The C-compiler is the one from Mr. Gates, called Visual Studio
97. Perl compiled with a lot of warnings, but seems to run fine.
however, I would like describe some problems
1) "nmake test" failed with fatale error, which seems to be related to
the not existing network support on my system. Is network support
needed to get a working perl? Or is it only needed for "nmake test" to
succeed?
2) I could not read the documentation coming with perl.
- "perldoc.bat perldoc" pops up an empty notepad.exe window. It seems
that a textfile should have been created (and later displayed) in the
temp directory. My temp directory is on a FAT partition(supporting
long filenames only via some strange mechanism), could this be a
reason?
- All links in the HTML version of the doc were "broken". I suspect
that the reason for this is the HTML Browser (IE 3.0) installed on my
system, not perl, but I'm not sure. The links in the HTML all look
like: //F|/dir1/dir2/.../file.html. This is a syntax not familar to me
and appearently neither to my browser. I could fix this by modifying
the makefile (removing the first two slashes) somewhere in the
install_doc target. Is the problem coming from my browser or is there
a error in the makefile?
regards
Frank
------------------------------
Date: 18 Mar 1998 09:57:56 GMT
From: "Uwe Honekamp" <uwe.honekamp@etas.de>
Subject: Re: building for perl 5.004_04 on NT
Message-Id: <01bd5254$4a98f2b0$931a0180@fe13803>
> I'm trying to build perl 5.004_04 on NT 4.0 SP3. I'm using the source
> code which can be compiled on unix systems too.
Did you call nmake from the Win32 subdirectory?
> 2) I could not read the documentation coming with perl. =20
My installation does not show this problem.
> - All links in the HTML version of the doc were "broken". I suspect
dito. The browser well-understands /F|/dir1/dir2/.../file.html.
Although the installation went perfectly well I get into trouble
when calling C functions from within perl scripts :-(
Regards=20
Uwe
--
Uwe Honekamp * ETAS GmbH * Borsigstr. 10 * D-70469 Stuttgart =20
uwe.honekamp@etas.de * voice: ++49/(0)711/89661-143 * fax: -107
------------------------------
Date: 18 Mar 1998 11:48:59 +0100
From: Frank@but_dont_use_this.address
Subject: Re: building for perl 5.004_04 on NT
Message-Id: <yo9k99sl1es.fsf@nym.sc.philips.com>
"Uwe Honekamp" <uwe.honekamp@etas.de> writes:
> Did you call nmake from the Win32 subdirectory?
Yes!
>
> > 2) I could not read the documentation coming with perl.
>
> My installation does not show this problem.
Do you have the same installation?
Mine is the one you can download from
http://language.perl.com/CPAN/src/latest.tar.gz
>
> > - All links in the HTML version of the doc were "broken". I suspect
>
> dito. The browser well-understands /F|/dir1/dir2/.../file.html.
Which Browser do you use? In your header is X-Newsreader: Microsoft
Internet News 4.70.1157. So you are using an later version (4.x) of
the Microsoft browser?
And please note I had a path //F|/dir1/dir2/.../file.html.
(Two slashes at the beginning)
>
> Although the installation went perfectly well I get into trouble
> when calling C functions from within perl scripts :-(
I wish I would come so far!
regards (& thank you)
Frank
------------------------------
Date: 17 Mar 1998 12:57:25 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: contexts: is there such a thing as array?
Message-Id: <6elrvl$sdk$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Andy Tompkins <aet@aryth.webplanets.com> writes:
:To me
:$next_index = @array + 1;
:uses a list in a scalar context.
That's an array in scalar context.
$something = (10,20,30)+1;
*That's* perhaps what you would think of as a list in a scalar
context, but in reality, those commas knowing they weren't in list
context never bothered to make a list in the first place, instead
resorting to the old comma-operator behaviour.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Emacs is a fine programming language, but I still prefer perl. -me
------------------------------
Date: Wed, 18 Mar 1998 00:52:09 -0600
From: parkesb@yahoo.com
Subject: Re: Date function - yyyymmdd format
Message-Id: <6enqrb$k92$1@nnrp1.dejanews.com>
One way to do it is:
chomp($portfoliodate = `date +%Y%m%d`);
which uses the unix date command to produce the right format.
Brian
In article <6en89p$s73$1@nnrp1.dejanews.com>,
jmohr@grizzly.ccsd.k12.wy.us wrote:
>
> I've been searching for a couple hours. Is there a perl function that
returns
> a date in yyyymmdd format? I can write my own but why re-invent the wheel?
> It's the principal of the thing, you know.
>
> --
> John Mohr
> Communications Specialist/Analyst
> Campbell County School District
> Gillette, Wyoming
> jmohr@grizzly.ccsd.k12.wy.us
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/ Now offering spam-free web-based newsreading
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 18 Mar 1998 07:47:22 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: Date function - yyyymmdd format
Message-Id: <890207629.918490@thrush.omix.com>
parkesb@yahoo.com wrote:
: One way to do it is:
: chomp($portfoliodate = `date +%Y%m%d`);
: which uses the unix date command to produce the right format.
Don't ever do this...it's just the type of bad design that
blows portability and reliability to hell for absolutely no good
reason... Not to mention with the extra fork() needed to do this
it can seriously slow some code down, as well as open up security
holes and many other problems...
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 18 Mar 1998 10:19:31 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Date function - yyyymmdd format
Message-Id: <7xn2eo2w64.fsf@beavis.vcpc.univie.ac.at>
Re: Date function - yyyymmdd format, jmohr
<jmohr@grizzly.ccsd.k12.wy.us> said:
jmohr> I've been searching for a couple hours. Is there a
jmohr> perl function that returns a date in yyyymmdd format?
jmohr> I can write my own but why re-invent the wheel? It's
jmohr> the principal of the thing, you know.
POSIX::strftime
and the Date::* modules from CPAN.
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/
"Everything I am, I learned on the back of cereal boxes" ~ RJ, "Over the Hedge"
------------------------------
Date: Wed, 18 Mar 1998 01:13:09 -0600
From: heitkamp@hotmail.com
Subject: executing cgi script problems
Message-Id: <6ens2b$lj7$1@nnrp1.dejanews.com>
i am new to cgi scripts and found a good collection of scripts at
www.worldwidemart.com
i tried to customize two of them, one is a formmail and the other a more
complex bulletin board
my server www.t3west.com supports cgi
still i get internal server errors or file not found (the requested url
under.html (?) could not be found) errors
i got my formmail to confirm submission but it seems like it never actually
send it, especially as i never receive anything.
i been trying for days and are frustrated big time.
could there be a problem with the permission (im using fetch and cant enter
chmoded xxx but work with checkboxes)
my servers techsupport suggests that there might be bugs in the scripts but i
dont think so as i didnt write them myself...
anybody has similar problems or better: solutions?
please email back, as i am not sure, which additional information you will
need.
thanks a million
alexander
heitkamp@hotmail.com
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 18 Mar 1998 08:26:21 GMT
From: sloop@mailcity.com
Subject: Re: executing cgi script problems
Message-Id: <350f8361.10113424@news.xmission.com>
On Wed, 18 Mar 1998 01:13:09 -0600, heitkamp@hotmail.com wrote:
>i am new to cgi scripts and found a good collection of scripts at
>www.worldwidemart.com
>i tried to customize two of them, one is a formmail and the other a more
>complex bulletin board
>
>my server www.t3west.com supports cgi
>still i get internal server errors or file not found (the requested url
>under.html (?) could not be found) errors
>i got my formmail to confirm submission but it seems like it never actually
>send it, especially as i never receive anything.
>
>i been trying for days and are frustrated big time.
>
>could there be a problem with the permission (im using fetch and cant enter
>chmoded xxx but work with checkboxes)
>
>my servers techsupport suggests that there might be bugs in the scripts but i
>dont think so as i didnt write them myself...
>
>anybody has similar problems or better: solutions?
>please email back, as i am not sure, which additional information you will
>need.
>
I'm afraid you're really in over your head. First you ought to learn
some essential programming concepts. Next, learn about such concepts
as Unix paths, permissions and executable bits, etc. Next learn about
how CGI works. Next, learn how all this applies to your server in
particular. Next learn how to modify the script so that it will work
within the confines of your server's configuration. Then you'll have
a prayer of getting the scripts going. Until then, you're simply
never going to succeed with it except perhaps by a massive stroke of
luck. This isn't like installing ICQ on a Win95 machine. If it were,
it wouldn't be fun.
Really, save yourself the time. I'm not saying this is the wrong
hobby for you, I'm just saying that you're underestimating the level
of knowledge you'll need before it becomes a viable hobby.
By the way; your question has little to do with Perl and thus is
inappropriate in this newsgroup.
------------------------------
Date: 18 Mar 1998 03:35:01 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: grep on hashes
Message-Id: <6enfd5$ikr$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Christopher Lambrou" <hold@cglis.com> writes:
:I want to count the number of keys in a hash array
:that are equal to a value, say 'foo'.
The answer is either false (there exists no key 'foo' in the hash) or
true (there does exist a key 'foo' in the hash). Pretend I just said
0 or 1 there. There cannot be more than that. Hashes have unique keys!
$has_foo = exists $hash{'foo'};
:So I said, assuming %a to be the hash in question:
:
:@count = grep {$_ eq 'foo'} %a;
Whoa, Nellie! What *are* you doing there? I thought you were looking
for keys! Now you tell me you want to grep across all the keys and
all the values intertwingled. Is that so? Why are you doing that?
Do you mean to grep just the keys? Why didn't you call keys()? (Not that you
will get more than 1 matching key to an eq string *EVER*!) Or do you
mean just the values? Then why didn't you call the values function?
I am surely confused. Or you are. Compare all these:
foreach $thingie ( %hash ) {
print "Got $thingie\n";
}
foreach $thingie ( keys %hash ) {
print "Got $thingie\n";
}
foreach $thingie ( values %hash ) {
print "Got $thingie\n";
}
:$count = $#count + 1;
Afraid of scalar @count, or scalar grep?
:This works(?) but is this the best way to do this?
I don't think it "works". Consider:
%hash = (
foo => 'bar',
bar => 'foo',
glarch => 'foo',
);
How many keys eq 'foo'? 1.
How many values eq 'foo'? 2.
How many values or values eq 'foo'? 3.
:The Camel book does not mention anything
:about using hashes with 'grep'.
That's because it's not sensible.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
double value; /* or your money back! */
short changed; /* so triple your money back! */
--Larry Wall in cons.c from the 4.0 perl source code
------------------------------
Date: Wed, 18 Mar 98 18:09:15
From: pfranken@c2.telstra-mm.net.au
Subject: Re: MS PWS won't run CGI
Message-Id: <NEWTNews.890209257.12009.pfranken@woo>
I'm having a similar problem.
I have installed PWS (I do have an internet connection running), I have
Perl-Win32 installed and running, but cannot execute .pl scripts on my machine
through my web browser.
I found a source on the internet (which refers to WinNT) which states that an
addition to the registry must be made as follows... (the following came from a
page in the Microsoft Support Site):
-- After you install PERL for WIN32, you will have to edit the registry to add
-- the script map entries under the following key:
--
--
-- Hkey_local_machine\system\currentcontrolset\services\W3Svc\
-- parameters\Script Map
--
-- The value is .pl: REG_SZ: C:\perl\bin\perl.exe %s
This registry addition doesn't make sense to me in a Win95 context. If anyone
could describe to me how to modify the Win95 registry so that PWS knows how to
run a .pl script I would be most appreciative.
I have tried adding a value as follows in the above key:
Value Name: .pl
Value Data: c:\perl\bin\perl.exe %s
My browser produces a "405-Method-Not-Allowed" error whenever I try a POST
command to execute a .pl script in the cgi-bin directory of the web site.
My cgi-bin directory has been checked to "Allow scripts to be run".
Hmmm.
No idea.
------------------------------
Date: Tue, 17 Mar 1998 22:08:14 -0800
From: sottek <sottek@quiknet.com>
To: dfrench@aig.vialink.com
Subject: Re: Multiple substitues
Message-Id: <350F64CE.63A2C496@quiknet.com>
I know you said that your examples were not exactly
what you were trying to do, but what are you trying
to do? It seems from your examples that you want to
do a translation, not a switch. Perl has the
y///; to do that!
Here is a one liner..
perl -e '$_ = "PERL";y/LER/ler/;print'
It prints "Perl"! All the letters matching "LER" are
translated into the corresponding letter in "ler"
Any number of translations can be done in one line this
way.... if that was what you were trying to do!
-SOTTEK
------------------------------
Date: Wed, 18 Mar 1998 08:15:25 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Multiple substitues
Message-Id: <3512778c.2010749@news.tornado.be>
John Y. wrote:
>This is the most efficient code I have used to do this if there is
>something more efficient I would like to know.
I've posted it already in this thread, but you seem to have missed it.
$sub{'this'} = 'that';
$sub{'and'} = 'the';
$sub{'other'} = 'thing';
s/(this|that|other)/$sub{$1}/g;
You could create the left side pattern by code, for example, like this:
$pattern = join ("|", map { "\\Q$_\\E" } keys %sub );
(which will generate \Qthis\E|\Qthat\E|\Qother\E or something similar)
and then
s/($pattern)/$sub{$1}/go;
Of course, you have the typical problem with //o if you want to do a
different substitution with the same statement: you can't force it to
recompile the pattern. Drop the "o" and you'll get a much slower
substitution.
HTH,
Bart.
------------------------------
Date: 18 Mar 1998 07:56:48 GMT
From: Ma Xin <maxin@iscs.nus.edu.sg>
Subject: Re: need perl script to read utmp files [Not Perl]
Message-Id: <6enuo0$a8410@id4.nus.edu.sg>
John Porter <jdporter@min.net> wrote:
> User::utent -- Interface to utmp/utmpx/wtmp/wtmpx database
Thanks for your help but I can't fint it. It's not one of the standard modules. I can only find grent and pwent inside the User module. where should search for User::utent?
TIA
_____
Best Regards,
Ma Xin
------------------------------
Date: 18 Mar 1998 10:19:18 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: need perl script to read utmp files
Message-Id: <iszpio5pbd.fsf@godzilla.kiere.ericsson.se>
Ma Xin <maxin@iscs.nus.edu.sg> writes:
> I'm looking for a perl script to read the utmp files(including
> /etc/utmp, /etc/wtmp, etc) in unix. I think it can be read using
> pack, unpack function in perl but I'm not sure what format the utmp
> files use. anyone?
Try typing "man utmp" at a shell prompt near you.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: 18 Mar 98 08:08:23 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: parsing perl
Message-Id: <350f80f7.0@news.one.net>
Zenin <zenin@archive.rhps.org> wrote:
> Rob Collins <rob@NOSPAMintr.net> wrote:
> : By what you say below, do you mean there are no rules which, when applied to a
> : block of text, can determine if the syntax is correct?
> Of course there is:
> if ( system ("perl -ce '$perlcode' > /dev/null 2>&1") == 0) {
> print "Perl code syntax is ok\n";
> } else {
> print "Perl code has syntax errors\n";
> }
Perl has so much better facilities for testing small code snippets with
some safety. I suggest you use the Safe module, which is great for this:
use Safe;
my $safe = new Safe;
my $code = <<'EOF';
sub routine {
return "this is valid.\n";
}
sub not_so_routine {
return "this is wrong.\n';
}
EOF
$safe->reval($code);
if($@) {
die "There was a boo-boo.\n";
}
my $file_with_code = "/home/you/lib/whatever.pl";
$safe->rdo($file_with_code);
if($@) {
die "There was a boo-boo in $file_with_code.\n";
}
This has the advantage of preventing problems with possibly
malicious code. Obviously the code will be executed, but it won't
affect anything in your namespace. You will have to allow certain
operations if needed, as the Safe module doesn't allow some things
like sort() and file tests by default.
Safe comes standard with Perl 5.004.
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
Just because something is 131 Willow Lane, Floor 2 | || _ \
obviously happening doesn't Oxford, OH 45056 | || |_) |
mean something obvious is <mikeh@minivend.com> |___| _ <
happening. --Larry Wall 513.523.7621 FAX 7501 |_| \_\
htat
------------------------------
Date: Wed, 18 Mar 1998 10:59:44 +0100
From: "Tom Adriaenssen" <tom@imagic.be>
Subject: Re: Perl system() calls on NT w/IIS
Message-Id: <6eo5um$re6$1@xenon.inbe.net>
>I/O redirection might be your problem, as it's broke in IIS (all versions).
>With IIS4, find adsutil.vbs (somewhere in inetsrv\adminsamples) and execute
>
>adsutil set w3svc/CreateCGIWithNewProcess True
Almost ;) After browsing dejanews, I found:
adsutil set w3svc/CreateCGIWithNewConsole True
Works fine now.
Are there any more of these undocumented 'features' in IIS? (du-uh!)
Tom.
------------------------------
Date: Wed, 18 Mar 1998 08:02:10 GMT
From: doswald@xmission.com (David Oswald)
Subject: Re: Problem of auto-increment in s///;
Message-Id: <350f7e1f.8767454@news.xmission.com>
On 18 Mar 1998 03:44:01 GMT, wtang@cs.ualberta.ca (Wei Tang) wrote:
>Hi,
>
>I want to auto-increment a variable in s///. I got the following running
>fine under Perl4. But I got an error when using Perl5:
>...
>Can't modify constant item in postincrement at count.pl line 6, near "cnt++"
>
>#!/usr/local/bin/perl -w
>
>$cnt = 0;
>$str = "one two three four five";
>print "$str \n";
>$str =~ s/(\w+)/$1_${cnt++}/g;
>print "$str \n";
>
>The output should be:
>one two three four five
>one_0 two_1 three_2 four_3 five_4
>
>Could somebody help?
>
The problem is with ${cnt++}. It won't work that way. You could use
$cnt++ or ${cnt}++, whichever seems to work within your regexp
substitution. If you want to do a little experiment, remove all of
the complexity and try just that increment part. You'll see what I'm
getting at by using the following little piece of code:
$cnt = 0;
$test = ${cnt++};
print "$test, $cnt\n";
The code won't compile that way.
Now try the following:
$cnt = 0;
$test = ${cnt}++;
print "$test, $cnt\n";
The output will be: 0, 1
Finally, try the same without the curly brackets. The output will be
the same. You can't increment cnt, but you can increment $cnt.
Dave
------------------------------
Date: Wed, 18 Mar 1998 03:19:05 -0600
From: parkesb@yahoo.com
Subject: Re: Problem of auto-increment in s///;
Message-Id: <6eo3ef$uf6$1@nnrp1.dejanews.com>
You ought to replace the s/// line with
$str =~ s/(\w+)/$1 . "_" .$cnt++/ge;
The /ge treats the replacement as a Perl expression.
Brian
email: parkesb@yahoo.com
In article <6enfu1$m7o$1@scapa.cs.ualberta.ca>,
wtang@cs.ualberta.ca (Wei Tang) wrote:
>
> Hi,
>
> I want to auto-increment a variable in s///. I got the following running
[snip]
> $str =~ s/(\w+)/$1_${cnt++}/g;
[snip]
>
> Could somebody help?
>
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 18 Mar 1998 03:52:38 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Problem of auto-increment in s///;
Message-Id: <6eo91m$3a5@flatland.dimensional.com>
wtang@cs.ualberta.ca (Wei Tang) writes:
> I want to auto-increment a variable in s///. I got the following running
> fine under Perl4. But I got an error when using Perl5:
> ...
> Can't modify constant item in postincrement at count.pl line 6, near "cnt++"
>
> #!/usr/local/bin/perl -w
>
> $cnt = 0;
> $str = "one two three four five";
> print "$str \n";
> $str =~ s/(\w+)/$1_${cnt++}/g;
> print "$str \n";
>
> The output should be:
> one two three four five
> one_0 two_1 three_2 four_3 five_4
Here's one way:
$str =~ s/(\w+)/"$1_" . $cnt++/ge;
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: 18 Mar 1998 11:17:35 GMT
From: mbeattie@sable.ox.ac.uk (Malcolm Beattie)
Subject: Re: Q: Threads (in 5.004_62) and signals
Message-Id: <6eoagf$5mg$1@news.ox.ac.uk>
In article <6ebipd$6o7$1@news.ox.ac.uk>,
Malcolm Beattie <mbeattie@sable.ox.ac.uk> wrote:
>In article <35083395.1B82@fc.hp.com>, Derek Sherlock <dereks@fc.hp.com> wrote:
>>My question: Nowhere in the perl builtins, CPAN modules, or Threads
>>entensions can I find a way of doing something like sigwait(3).
[...]
>use Thread::Signal;
As has been pointed out to me in email, Thread::Signal itself never
made the journey from brain to keyboard (and the Thread.xs support
was buggy too). Here's a patch against perl5.004_63 which adds it.
You may need to "touch ext/Thread/Thread/Signal.pm" before applying it
if your version of patch can't create files diffed against /dev/null.
------------------------------ cut here ------------------------------
Change 835 by mbeattie@localhost on 1998/03/18 11:03:11
Add Thread::Signal to run signal handlers reliably in a new thread
Affected files ...
... //depot/perl/MANIFEST#45 edit
... //depot/perl/ext/Thread/Thread.xs#18 edit
... //depot/perl/ext/Thread/Thread/Signal.pm#1 add
Differences ...
Index: perl/MANIFEST
==== //depot/perl/MANIFEST#45 (text) ====
@@ -267,6 +267,7 @@
ext/Thread/Thread.xs Thread extension external subroutines
ext/Thread/Thread/Queue.pm Thread synchronised queue objects
ext/Thread/Thread/Semaphore.pm Thread semaphore objects
+ext/Thread/Thread/Signal.pm Start a thread to run signal handlers
ext/Thread/Thread/Specific.pm Thread specific data access
ext/Thread/create.t Test thread creation
ext/Thread/die.t Test thread die()
Index: perl/ext/Thread/Thread.xs
==== //depot/perl/ext/Thread/Thread.xs#18 (text) ====
@@ -280,8 +280,15 @@
static Signal_t
handle_thread_signal(int sig)
{
- char c = (char) sig;
- write(sig_pipe[0], &c, 1);
+ unsigned char c = (unsigned char) sig;
+ /*
+ * We're not really allowed to call fprintf in a signal handler
+ * so don't be surprised if this isn't robust while debugging
+ * with -DL.
+ */
+ DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ "handle_thread_signal: got signal %d\n", sig););
+ write(sig_pipe[1], &c, 1);
}
MODULE = Thread PACKAGE = Thread
@@ -555,7 +562,7 @@
void
kill_sighandler_thread()
PPCODE:
- write(sig_pipe[0], "\0", 1);
+ write(sig_pipe[1], "\0", 1);
PUSHs(&sv_yes);
void
@@ -566,22 +573,22 @@
XSRETURN_UNDEF;
PUSHs(&sv_yes);
-SV *
+void
await_signal()
PREINIT:
- char c;
+ unsigned char c;
SSize_t ret;
CODE:
do {
- ret = read(sig_pipe[1], &c, 1);
+ ret = read(sig_pipe[0], &c, 1);
} while (ret == -1 && errno == EINTR);
if (ret == -1)
croak("panic: await_signal");
- if (ret == 0)
- XSRETURN_UNDEF;
- RETVAL = c ? psig_ptr[c] : &sv_no;
- OUTPUT:
- RETVAL
+ ST(0) = sv_newmortal();
+ if (ret)
+ sv_setsv(ST(0), c ? psig_ptr[c] : &sv_no);
+ DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ "await_signal returning %s\n", SvPEEK(ST(0))););
MODULE = Thread PACKAGE = Thread::Specific
--- /dev/null Tue Jan 1 04:00:00 1980
+++ ext/Thread/Thread/Signal.pm Wed Mar 18 11:00:37 1998
@@ -0,0 +1,50 @@
+package Thread::Signal;
+use Thread qw(async);
+
+=head1 NAME
+
+Thread::Signal - Start a thread which runs signal handlers reliably
+
+=head1 SYNOPSIS
+
+ use Thread::Signal;
+
+ $SIG{HUP} = \&some_handler;
+
+=head1 DESCRIPTION
+
+The C<Thread::Signal> module starts up a special signal handler thread.
+All signals to the process are delivered to it and it runs the
+associated C<$SIG{FOO}> handlers for them. Without this module,
+signals arriving at inopportune moments (such as when perl's internals
+are in the middle of updating critical structures) cause the perl
+code of the handler to be run unsafely which can cause memory corruption
+or worse.
+
+=head1 BUGS
+
+This module changes the semantics of signal handling slightly in that
+the signal handler is run separately from the main thread (and in
+parallel with it). This means that tricks such as calling C<die> from
+a signal handler behave differently (and, in particular, can't be
+used to exit directly from a system call).
+
+=cut
+
+if (!init_thread_signals()) {
+ require Carp;
+ Carp::croak("init_thread_signals failed: $!");
+}
+
+async {
+ my $sig;
+ while ($sig = await_signal()) {
+ &$sig();
+ }
+};
+
+END {
+ kill_sighandler_thread();
+}
+
+1;
------------------------------ cut here ------------------------------
--
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Oxford University Computing Services
"I permitted that as a demonstration of futility" --Grey Roger
------------------------------
Date: 17 Mar 1998 23:57:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Variable question
Message-Id: <6en2lo$62u$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Shawn M. Kelly" <kellysm@ix.netcom.com> writes:
:I have a data file that looks like this:
:door1 5.0
:door2 2.0
:door3 7.0
:
:I'd like to read the data file in and then dynamically assign a variable
:with the first field having the value of the second. So after reading
:in this particular file I would have three variable like so:
:
:door1 equals 5.0
:door2 equals 2.0
:door3 equals 7.0
You're thinking about this all wrong -- you *do not* want three separate
variables. You want a data structure here whose contents are those
door names. Perhaps you are more used to using some icky thing like
Fortran, Cobol, or BASIC. Until you start thinking in terms of hashes
and in terms of regular expressions, you aren't thinking in Perl.
while (<>) {
($door, $number) = split;
$valuables{$door} = $number;
}
foreach $door (sort keys %valuables) {
$contents = $valuables{$door};
print "$door equals $contents\n";
}
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Randal said it would be tough to do in sed. He didn't say he didn't
understand sed. Randal understands sed quite well. Which is why he
uses Perl. :-) -- Larry Wall in <7874@jpl-devvax.JPL.NASA.GOV>
------------------------------
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 2124
**************************************