[24949] in Perl-Users-Digest
Perl-Users Digest, Issue: 7199 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 1 14:06:59 2004
Date: Fri, 1 Oct 2004 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 1 Oct 2004 Volume: 10 Number: 7199
Today's topics:
Re: $SIG{CHLD} and system (Heinrich Mislik)
Re: $SIG{CHLD} and system <Joe.Smith@inwap.com>
Re: $SIG{CHLD} and system (Heinrich Mislik)
Re: How to check size of harddisk? <ThomasKratz@REMOVEwebCAPS.de>
Re: How to merge .wav files <spamtrap@dot-app.org>
Re: How to merge .wav files <tassilo.von.parseval@rwth-aachen.de>
Re: How to merge .wav files (Anno Siegel)
Re: How to merge .wav files <spamtrap@dot-app.org>
Re: How to merge .wav files <spamtrap@dot-app.org>
Re: How to merge .wav files <jarsonk@nospam.com>
Re: How to merge .wav files <jarsonk@nospam.com>
Re: How to merge .wav files <tassilo.von.parseval@rwth-aachen.de>
Re: How to merge .wav files <tassilo.von.parseval@rwth-aachen.de>
Re: how to put constaints on coefficients obtained from <dwall@fastmail.fm>
Re: how to put constaints on coefficients obtained from <1usa@llenroc.ude.invalid>
How to: Build Dynamic loading Perl (Paula)
Re: How to: Build Dynamic loading Perl <thepoet_nospam@arcor.de>
Re: Odd sort() problem (Tony Skelding)
Problem with HTML::LinkExtor (Helmut Blass)
replace string in file (wana)
Re: replace string in file <mritty@gmail.com>
Re: replace string in file <phaylon@dunkelheit.at>
Re: replace string in file <jurgenex@hotmail.com>
Re: Symbolic algebra <bik.mido@tiscalinet.it>
Re: Syntax appears inconsistent - why is this? (Tony Skelding)
While query <iss025@bangor.ac.uk>
Re: While query <sbryce@scottbryce.com>
Re: While query <iss025@bangor.ac.uk>
Re: While query <1usa@llenroc.ude.invalid>
Re: While query <1usa@llenroc.ude.invalid>
Re: While query <mritty@gmail.com>
Re: While query <mritty@gmail.com>
Re: While query <mritty@gmail.com>
Re: While query <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Who's responsible for this ? <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 01 Oct 2004 10:10:51 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: $SIG{CHLD} and system
Message-Id: <415d2d26$0$31502$3b214f66@usenet.univie.ac.at>
In article <365f784f.0409301300.e738812@posting.google.com>, kspecial@linuxmail.org says...
>
>
>Heinrich.Mislik@univie.ac.at (Heinrich Mislik) wrote in message news:<415bfee0$0$12646$3b214f66@usenet.univie.ac.at>...
>> perl -e '$SIG{CHLD} = "IGNORE";system("date") and die'
>> gives me
>>
>> Thu Sep 30 14:34:22 MSZ 2004
>> Died at -e line 1.
>
>That's exactly what it's supposed to give you...
>
>> I can understand, why this happens.
>
>Why what happens? Perl run's "date", then returns when date exits,
>after which it proceeds to die....perl is reporting that it die()ed.
>I'm not sure what you expected to happen. You can check return values
>etc of the system():
I expected to get the sam result for
perl -e '$SIG{CHLD} = "IGNORE";system("date") and die $?'
which prints
Fri Oct 1 12:08:04 MSZ 2004
-1 at -e line 1.
and
perl -e '$SIG{CHLD} = "DEFAULT";system("date") and die $?'
which prints
Fri Oct 1 12:09:12 MSZ 2004
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Fri, 01 Oct 2004 10:49:46 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: $SIG{CHLD} and system
Message-Id: <eDa7d.148741$MQ5.96256@attbi_s52>
kspecial@linuxmail.org wrote:
> Heinrich.Mislik@univie.ac.at (Heinrich Mislik) wrote in message news:<415bfee0$0$12646$3b214f66@usenet.univie.ac.at>...
>
>>perl -e '$SIG{CHLD} = "IGNORE";system("date") and die'
>>gives me
>>
>>Thu Sep 30 14:34:22 MSZ 2004
>>Died at -e line 1.
>>I can't understand, why this happens.
>
> Why what happens? Perl run's "date", then returns when date exits,
> after which it proceeds to die....perl is reporting that it die()ed.
> I'm not sure what you expected to happen.
He was expecting the value returned by system() to be the same
as what gets stored in $? (zero on success, nonzero on failue).
But that is no longer the case; system() is returning -1 regardless
of the command's exit code.
solaris% perl -le '$SIG{CHLD} = "DEFAULT";print(system("/bin/true"))'
0
solaris% perl -le '$SIG{CHLD} = "DEFAULT";print(system("/bin/false"))'
65280
solaris% perl -le '$SIG{CHLD} = "IGNORE";print(system("/bin/true"))'
-1
solaris% perl -le '$SIG{CHLD} = "IGNORE";print(system("/bin/false"))'
-1
This behavior is not explictly documented; you have to do some digging
to see why the return value if system() has become misleading or useless.
From 'perldoc -f system':
The return value is the exit status of the program as returned
by the "wait" call. To get the actual exit value shift right
by eight (see below). Return value of -1 indicates a failure
to start the program (inspect $! for the reason).
From 'perldoc perlvar':
Using a value of 'IGNORE' usually has the effect of
ignoring the signal, except for the "CHLD" signal.
See perlipc for more about this special case.
From 'perldoc perlipc':
On most Unix platforms, the "CHLD" (sometimes also known as
"CLD") signal has special behavior with respect to a value
of 'IGNORE'. Setting $SIG{CHLD} to 'IGNORE' on such a
platform has the effect of not creating zombie processes
when the parent process fails to "wait()" on its child
processes (i.e. child processes are automatically reaped).
Calling "wait()" with $SIG{CHLD} set to 'IGNORE' usually
returns "-1" on such platforms.
That means that 'perldoc -f system' should have said:
The return value is what is returned by the "wait" call,
which the program's exit status. (Except when $SIG{CHLD}
is set to 'IGNORE', in which case system() returns -1.)
Conclusion: If it is possible that your program will be running with
a non-default value of $SIG{CHLD}, you'll have to change your
program logic to not look at the return value from system().
Change
system($command) and die;
to
system($command); $? and die;
-Joe
------------------------------
Date: 01 Oct 2004 12:04:10 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: $SIG{CHLD} and system
Message-Id: <415d47b4$0$31502$3b214f66@usenet.univie.ac.at>
In article <eDa7d.148741$MQ5.96256@attbi_s52>, Joe.Smith@inwap.com says...
>Conclusion: If it is possible that your program will be running with
>a non-default value of $SIG{CHLD}, you'll have to change your
>program logic to not look at the return value from system().
>Change
> system($command) and die;
>to
> system($command); $? and die;
Won't work either. $SIG{CHLD} = "IGNORE" really means "i'm not interessted
in the return the value from my childs". Since no zombie will be created,
there is no way, get the return value.
OTH, if system temporary changes $SIG{CHLD} and any other child exits
during the system function does waitpid, there would remain an unwanted
zombie.
perdoc -f system should make this clear.
cheers
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Fri, 01 Oct 2004 14:13:38 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: How to check size of harddisk?
Message-Id: <415d49f1$0$7974$bb690d87@news.main-rheiner.de>
Jason Quek wrote:
> Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote:
>>Look at this sub I posted a few weeks ago to get the info from WMI
>>
>>http://www.google.de/groups?hl=de&lr=&ie=UTF-8&selm=4138a093%240%2414528%24bb690d87%40news.main-rheiner.de
>>
>>Thomas
>
> Hi Thomas
>
> When I run this subroutine, I get this error:
>
> Undefined subroutine &main::in called at script.cgi line 19
>
> More specifically, the error occurs on this line:
>
> my @inst = in($wmi->InstancesOf('Win32_ComputerSystem'));
>
> Am I doing something wrongly?
You have to load Win32::OLE with
use Win32::OLE qw/in/;
Please read the docs for Win32::OLE for further informations ( in() is
documented in the section "Overloading")
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
------------------------------
Date: Fri, 01 Oct 2004 06:10:48 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to merge .wav files
Message-Id: <JpudnXZsb8q0sMDcRVn-pQ@adelphia.com>
Anno Siegel wrote:
> I'm no audio buff, but using more than 32 bits to calculate 16 bit
> quantities sounds excessive.
For a single operation involving only two 16-bit tracks, yes. But
high-end apps - stuff like ProTools, Logic, etc. - use 32-bit tracks
internally, and support a ridiculous number of them.
1023 32-bit tracks need 42 bits of range to mix them all without the
risk of truncation - it's far more convenient to round that up and use
64-bit long longs.
I'll freely admit though, that this is getting *very* far afield of the
original question. :-)
> Alternatively to truncation or normalization, calculating a (possibly
> weighted) average looks plausible too.
Nope. Mixing sound means addition. If you average them, that makes the
quiet samples louder and the loud ones quieter. The effect is the most
pronounced where you least want it to be, where one track is very loud
and the other is very quiet; the mixed result has the two sounds much
closer together in volume than they should be.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 1 Oct 2004 12:49:33 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: How to merge .wav files
Message-Id: <2s4r1vF1h5qjeU1@uni-berlin.de>
Also sprach Sherm Pendley:
> Tassilo v. Parseval wrote:
>
>> Some things to watch for: You have to truncate values when they would go
>> beyond the maximum or minimum range
>
> Ouch, just reading this makes my ears hurt! Truncation results is sound
> waves that are squared off at the top and/or bottom. It's commonly known
> as "clipping", and it sounds horrible.
Clipping is the most basic way of doing this, indeed. But very often the
result isn't as bad as it may appear because many recordings have quite a
headroom to the maximum peak (at least always the ones I dealt with in
the past). Files that are well compressed, though, suffer from clipping
more audibly and a less simplistic approach is neede.
> Don't truncate when you're doing the addition. Do the math with 32, 64,
> or even 96-bit ints internally to allow for plenty of headroom, and
> normalize the output to the desired bit width only on output.
Gee, 96 bits? How many streams do you usually mix together? :-)
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 1 Oct 2004 11:12:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to merge .wav files
Message-Id: <cjje2f$2ip$1@mamenchi.zrz.TU-Berlin.DE>
Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
[mixing wav files]
> > Alternatively to truncation or normalization, calculating a (possibly
> > weighted) average looks plausible too.
>
> Nope. Mixing sound means addition. If you average them, that makes the
> quiet samples louder and the loud ones quieter.
We're way off topic, but...
Unbiased averaging *is* addition, after applying a factor of 1/2 to each
summand. Weighted averaging is also addition, after applying individual
factors (whose sum is 1) to each summand. The only difference is that
the sum is immediately scaled so that it never exceeds the maximum of the
inputs. I don't see your point.
> The effect is the most
> pronounced where you least want it to be, where one track is very loud
> and the other is very quiet; the mixed result has the two sounds much
> closer together in volume than they should be.
How so?
Anno
------------------------------
Date: Fri, 01 Oct 2004 07:55:26 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to merge .wav files
Message-Id: <34OdnQd1z8ky2MDcRVn-ig@adelphia.com>
Anno Siegel wrote:
> Unbiased averaging *is* addition, after applying a factor of 1/2 to each
> summand. Weighted averaging is also addition, after applying individual
> factors (whose sum is 1) to each summand. The only difference is that
> the sum is immediately scaled so that it never exceeds the maximum of the
> inputs. I don't see your point.
My point is that you don't know if 0.5 is the best scaling factor. It's
the safest, in that it guarantees a zero chance of clipping. But it can
also reduce the dynamic range needlessly.
For instance, assume that the highest total of two samples is 34k - to
reduce this to the 32k required to fit into 16 bits is a scaling factor
of about 0.94. Reducing all the samples by a factor of 0.5 would then
leave the loudest point at a mere 17k, effectively reducing the total
dynamic range by nearly half.
For the best audio definition, you want to scale the final result so
that the highest peak just barely fits in the range of the output
format. You can't determine what that scaling factor will be, until
you've actually added all of the samples to determine what the value of
that highest peak is.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 01 Oct 2004 08:04:07 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to merge .wav files
Message-Id: <3YOdnSLApv4q2sDcRVn-hg@adelphia.com>
Tassilo v. Parseval wrote:
> Gee, 96 bits? How many streams do you usually mix together? :-)
I've seen pro apps advertising a 96-bit internal data path. Whether it
was actually useful, really that wide, or just marketroid nonsense, is
certainly open for debate.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 1 Oct 2004 08:45:19 -0400
From: "Jarson" <jarsonk@nospam.com>
Subject: Re: How to merge .wav files
Message-Id: <zjc7d.20943$MD5.1221503@news20.bellglobal.com>
Wooooo! Stop! I am very sorry for using the word "merge" when I should have
said "join" or "concatenate".
I don't want to have the two files overlapping each other, I simply want one
joined after the other.
Example:
file1.wav says: "Hello. The blah blah blah system has detected an alert
in your area."
file2.wav says: "The Ohio thing-a-ma-gig is operating at 50% capacity."
fileJoin.wav says: "Hello. The blah blah blah system has detected an
alert in your area. The Ohio thing-a-ma-gig is operating at 50% capacity."
A simple UNIX cat does not work as there appears to be header information in
the first wav file that prevents the joined wav file from working properly.
How should I do a join in perl.
Jarson
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cjj7gq$pcd$1@mamenchi.zrz.TU-Berlin.DE...
> Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
>> Tassilo v. Parseval wrote:
>>
>> > Some things to watch for: You have to truncate values when they would
>> > go
>> > beyond the maximum or minimum range
>>
>> Ouch, just reading this makes my ears hurt! Truncation results is sound
>> waves that are squared off at the top and/or bottom. It's commonly known
>> as "clipping", and it sounds horrible.
>>
>> Don't truncate when you're doing the addition. Do the math with 32, 64,
>> or even 96-bit ints internally to allow for plenty of headroom, and
>> normalize the output to the desired bit width only on output.
>
> I'm no audio buff, but using more than 32 bits to calculate 16 bit
> quantities sounds excessive.
>
> Alternatively to truncation or normalization, calculating a (possibly
> weighted) average looks plausible too.
>
> Anno
------------------------------
Date: Fri, 1 Oct 2004 09:05:58 -0400
From: "Jarson" <jarsonk@nospam.com>
Subject: Re: How to merge .wav files
Message-Id: <WCc7d.20952$MD5.1223139@news20.bellglobal.com>
"kevin" <kevinc@cinesite.co.uk> wrote in message
news:798c3a4c.0410010125.2be74a10@posting.google.com...
> Jarson,
> below is a perl script i wrote to add silence on the front of a wav file,
> together with the notes i have on the wav file header. Unfortunately,
> i can't remember where i got the wav file header docs from :(
>
> the script ran on linux.
> you should be able to merge wavs in a similar way.
>
> HTH,
> kevin
>
[snip]
Ahhh, yes! Your code looks very useful. Since I will be keeping the format
of the wave files the same (channels, sample rate, bytes/sec, etc.) I should
be able to join the data sections and update the length so it corresponds to
the joined length.
Thanks Kevin.
Jarson
------------------------------
Date: Fri, 1 Oct 2004 17:35:17 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: How to merge .wav files
Message-Id: <2s5bpmF1gobg2U1@uni-berlin.de>
Also sprach Sherm Pendley:
> Tassilo v. Parseval wrote:
>
>> Gee, 96 bits? How many streams do you usually mix together? :-)
>
> I've seen pro apps advertising a 96-bit internal data path. Whether it
> was actually useful, really that wide, or just marketroid nonsense, is
> certainly open for debate.
Ah, but that might be something very different. Some digital signal
processing happens with floating point numbers, like when audio data is
sent through a reverb processor or equalizer which requires a prior
fourier-synthesis. And sometimes it can mean a speed-up (especially on
modern processors) if you use floating point values instead of
integers. In the end you always need integer values but in between it
can be benificial to work with very wide floats because you are less
prone to losing quality due to the limited precision.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 1 Oct 2004 17:56:02 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: How to merge .wav files
Message-Id: <2s5d0kF1h213qU1@uni-berlin.de>
[ Please don't top-post ]
Also sprach Jarson:
> Wooooo! Stop! I am very sorry for using the word "merge" when I should have
> said "join" or "concatenate".
> I don't want to have the two files overlapping each other, I simply want one
> joined after the other.
>
> Example:
> file1.wav says: "Hello. The blah blah blah system has detected an alert
> in your area."
> file2.wav says: "The Ohio thing-a-ma-gig is operating at 50% capacity."
>
> fileJoin.wav says: "Hello. The blah blah blah system has detected an
> alert in your area. The Ohio thing-a-ma-gig is operating at 50% capacity."
>
> A simple UNIX cat does not work as there appears to be header information in
> the first wav file that prevents the joined wav file from working properly.
> How should I do a join in perl.
Yes, the first 44 bytes of a wav-file is the header. If you want to
append one wave-file to another, you first have to strip off the first
44 bytes of the stream to be appended. After that, you measure the size
of the stream in bytes (it's filesize minus 44 for obvious reasons).
Then you append the stream to the file. The last thing you have to do is
update two fields in the wave-header of the first stream. Those two
fields denote the size in bytes of the file and the stream:
#!/usr/bin/perl -w
use Fcntl qw/:seek/;
my ($file1, $file2) = @ARGV;
open WAV1, "+<", $file1 or die $!;
open WAV2, $file2 or die $!;
binmode WAV1;
binmode WAV2;
# the length of the second stream without header
my $size = -s WAV2 - 44;
$/ = \4; # four bytes on each <>
seek WAV1, 4, SEEK_SET;
my $filesize = unpack "V", <WAV1>; # it's little-endian AFAIK
seek WAV1, 32, SEEK_CUR;
my $streamsize = unpack "V", <WAV1>;
seek WAV1, 4, SEEK_SET;
print WAV1 pack "V", $filesize + $size;
seek WAV1, 32, SEEK_CUR;
print WAV1 pack "V", $streamsize + $size;
seek WAV1, 0, SEEK_END;
$/ = \4096; # increase block-size a bit
# skip header of second file
seek WAV2, 44, SEEK_SET;
# append
print WAV1 $_ while <WAV2>;
close WAV1;
close WAV2;
The above is totally untested so byte-offsets and such might be a bit
off. If you get hold of a description of a wave-header you should be
able to understand what the above does.
Needless to say, you can only concatenate two wave-files when they have
the same format. Otherwise, you have to convert the one you append
first.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 01 Oct 2004 14:22:43 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: how to put constaints on coefficients obtained from regression.pm
Message-Id: <Xns957569940F513dkwwashere@216.168.3.30>
pj <nsf470@yahoo.com> wrote:
> I use regression package to do a multivariate linear regression
> fit to my data. Regression.pm generates coefficient values
> (thetas), but I want to make them always possitive. How do I put
> constraints (all coefficients are positive) when using regression
> package? any ideas? thanks
Huh? That's really strange. Regression coefficients sometimes just ARE
negative because that's the way the data is. You can transform the data
so that the coefficients are more meaningful, e.g.; taking the log or
something, but when you fit a model to your data you have to accept
what the data says, not what you want it to be. That is, if you're
honest.
Ask in a statistics group; I think they'll tell you the same thing. For
what it's worth, my job title is statistician (although I tend to do
more programming these days) and I've never heard of trying to force
all regression coefficients to be positive. The PhD statistician across
the hall (I only have a Master's in stat) hadn't either. He said it
sounded like something a psychologist would try to do. :-)
------------------------------
Date: 1 Oct 2004 15:24:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: how to put constaints on coefficients obtained from regression.pm
Message-Id: <Xns95757416BFE80asu1cornelledu@132.236.56.8>
"David K. Wall" <dwall@fastmail.fm> wrote in
news:Xns957569940F513dkwwashere@216.168.3.30:
> pj <nsf470@yahoo.com> wrote:
>
>> How do I put constraints (all coefficients are positive) when
>> using regression package? any ideas? thanks
>
> Huh? That's really strange. Regression coefficients sometimes just ARE
> negative because that's the way the data is. You can transform the data
> so that the coefficients are more meaningful, e.g.; taking the log or
> something, but when you fit a model to your data you have to accept
> what the data says, not what you want it to be. That is, if you're
> honest.
>
> Ask in a statistics group; I think they'll tell you the same thing. For
> what it's worth, my job title is statistician (although I tend to do
> more programming these days) and I've never heard of trying to force
> all regression coefficients to be positive. The PhD statistician across
> the hall (I only have a Master's in stat) hadn't either. He said it
> sounded like something a psychologist would try to do. :-)
Well, there are sometimes perfectly valid reasons for calculating
restricted regressions, mostly in the realm of Likelihood Ratio tests.
I know, I know, getting off-topic here.
Sinan.
------------------------------
Date: 1 Oct 2004 07:32:47 -0700
From: pcapacio@amfam.com (Paula)
Subject: How to: Build Dynamic loading Perl
Message-Id: <bd052363.0410010632.24acce29@posting.google.com>
Basic recipe needed for building a dynamic loading Perl on HP/UX V11.
We have perl 5.006001 installed and have since installed other modules
but when attempting to use them we get: You may need to build a new
perl executable which either supports dynamic loading or has the
Date::Calc module statically linked into it.
I don't know anything about installing or configuring Perl on UNIX or
much about UNIX in general. I use ActiveState's Active Perl and PPM
on Windows and that IS dynamic already. Any help to get us started
would be greatly appreciated.
Paula
------------------------------
Date: Fri, 01 Oct 2004 20:04:59 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: How to: Build Dynamic loading Perl
Message-Id: <415d9c24$0$3628$9b4e6d93@newsread2.arcor-online.net>
Paula wrote:
> I don't know anything about installing or configuring Perl on UNIX or
> much about UNIX in general. I use ActiveState's Active Perl and PPM
> on Windows and that IS dynamic already. Any help to get us started
> would be greatly appreciated.
I'm not familiar with HP/UX, but
perldoc perlhpux
should give you some info on that topic.
HTH
-Christian
------------------------------
Date: 1 Oct 2004 04:04:40 -0700
From: tony@skelding.co.uk (Tony Skelding)
Subject: Re: Odd sort() problem
Message-Id: <a78026a1.0410010304.15394677@posting.google.com>
"John W. Krahn" <someone@example.com> wrote in message news:<DJF6d.2511$eq.1514@edtnps84>...
> 187 wrote:
> > I friend of mine recently accessed me for a little one liner to nicely
> > display all the paths in the $PATH vartiable on his NT 5.1 (aka XP Pro)
> > machine: (sorry for word wrap)
> >
> > C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
> > split(/;/, $ENV {'PATH'})), qq{\n};"
> >
> > [snip]
> >
> > I get the same sort of oddness on my Linux machine as well:
> >
> > $ perl -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
> > split(/:/, $ENV{"PATH"})), qq{\n};'
> >
> > [snip]
> >
> > Both Perl's are 5.6.1, though my Linux also has 5.8.2 which does
> > similar, though different order:
> >
> > $ perl5.8.2 -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
> > split(/:/, $ENV{"PATH"})), qq{\n};'
> >
> > [snip]
> >
> > What is going on here? Why is sort doing this? I've used sort(), map(),
> > and grep() in cascaded form like this before without this problem;
> > split() returns an array, which get sucked into sort(), who spits it
> > back out to join(), does it not?
>
> As others have pointed out the problem is with the anonymous hash in "lc{$a}"
> however if you want to make this more portable and remove all those quotes and
> braces and parentheses:
>
> perl -e 'use Env q/@PATH/; print $/, map $_ . $/, sort { lc $a cmp lc $b } @PATH'
>
>
> John
Or even
perl -le 'print for sort { lc $a cmp lc $b } split ":", $ENV{PATH}'
------------------------------
Date: Fri, 01 Oct 2004 17:55:27 GMT
From: helmut.blass@web.de (Helmut Blass)
Subject: Problem with HTML::LinkExtor
Message-Id: <cjk5fi$4mc$04$1@news.t-online.com>
HI,
I've written a perl script which extracts links from websites.
it's working fine but unfortunately only at the first call
after program start. if I call the routine for a second time,
the result list stays empty thou the site to be parsed has been
retrieved. after finishing and restarting the script the routine
works again properly.
all variables are declared locally.
my @url_list = ();
####
sub callback {
my($tag, %attr) = @_;
return if $tag ne 'a';
push(@url_list, values %attr);
}
######
my $p = HTML::LinkExtor->new(\&callback);
# Request document and parse it as it arrives
my $res = $ua->request(HTTP::Request->new(GET => $_),
sub {$p->parse($_[0])});
thanx. Helmut
------------------------------
Date: 1 Oct 2004 08:03:24 -0700
From: ioneabu@yahoo.com (wana)
Subject: replace string in file
Message-Id: <bf0b47ca.0410010703.2d69d7cb@posting.google.com>
I want to replace a key word in a file with a string. Here is a
segment of code cut out of a script I wrote to help me generate
desktop application links.
<code>
open TEMPLATE, './template.desktop' or
die("could not open template.desktop file\n");
my @template = <TEMPLATE>;
foreach (@template)
{
s/EXEC/$ARGV[0]/g;
s/NAME/$ARGV[1]/g;
}
open OUTFILE, ">$ENV{'HOME'}/Desktop/$ARGV[2]" or
die("could not open output file\n");
print OUTFILE @template;
close OUTFILE;
</code>
I was just wondering if there was a better way.
Thank you to all for help on this question and all previous questions
I have submitted to this group for which all responses and
particularly certain special responses have been most helpful.
wana
------------------------------
Date: Fri, 01 Oct 2004 15:17:55 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: replace string in file
Message-Id: <Dye7d.77$MU6.42@trndny08>
"wana" <ioneabu@yahoo.com> wrote in message
news:bf0b47ca.0410010703.2d69d7cb@posting.google.com...
> I want to replace a key word in a file with a string. Here is a
> segment of code cut out of a script I wrote to help me generate
> desktop application links.
>
> <code>
> open TEMPLATE, './template.desktop' or
> die("could not open template.desktop file\n");
> my @template = <TEMPLATE>;
> foreach (@template)
> {
> s/EXEC/$ARGV[0]/g;
> s/NAME/$ARGV[1]/g;
> }
> open OUTFILE, ">$ENV{'HOME'}/Desktop/$ARGV[2]" or
> die("could not open output file\n");
> print OUTFILE @template;
> close OUTFILE;
> </code>
>
> I was just wondering if there was a better way.
>
This is such a common use for perl that there's a couple command line
arguments available to make this a one-liner:
perl -pe"s/EXEC/arg0/; s/NAME/arg1/;" ./template.desktop >
$HOME/Desktop/arg2
Read about -p and -e in
perldoc perlrun
You may also be interested in -i, also in the above perldoc.
Paul Lalli
------------------------------
Date: Fri, 01 Oct 2004 17:15:59 +0200
From: Robert Sedlacek <phaylon@dunkelheit.at>
Subject: Re: replace string in file
Message-Id: <pan.2004.10.01.15.15.54.819631@dunkelheit.at>
wana wrote:
> I was just wondering if there was a better way.
Just an idea: You could use STDIN and STDOUT instead of opening
filehandles. I don't know if this is a good idea, that belongs to
your scenario. You could cut it down to (untested):
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
while(<>) {
s/EXEC/$ARGV[0]/g;
s/NAME/$ARGV[1]/g;
print;
}
If you want to use a default file (eg. ./template.desktop) you could
use this one (again untested):
[...she-bang and use's...]
open TPL, '<./template.desktop'
or die('Unable to open template file.'."\n");
while(<TPL>) {
s/EXEC/$ARGV[0]/g;
s/NAME/$ARGV[1]/g;
print;
}
close TPL;
You can use this one by running
$ $SCRIPT exec_replace name_replace > file
The pro I see here is that you're not doing any buffering of the complete
content of the input file.
hth,
Robert
--
http://www.dunkelheit.at/
»Better to reign in hell than to serve in heaven«
-- John Milton, »Paradise Lost«
------------------------------
Date: Fri, 01 Oct 2004 15:26:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: replace string in file
Message-Id: <vGe7d.415$cd1.206@trnddc03>
wana wrote:
> I want to replace a key word in a file with a string. Here is a
> segment of code cut out of a script I wrote to help me generate
> desktop application links.
>
> <code>
> open TEMPLATE, './template.desktop' or
> die("could not open template.desktop file\n");
> my @template = <TEMPLATE>;
> foreach (@template)
There is on point in reading the whole file into an array when afterwards
you are looping through each line individually anyway. Better process each
line as you read it:
while (<TEMPLATE>) {.....
jue
------------------------------
Date: Fri, 01 Oct 2004 17:12:14 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Symbolic algebra
Message-Id: <s9sql09eno3omlkr08v026tvbe8j071vrr@4ax.com>
On Thu, 30 Sep 2004 14:59:35 -0500, Brian Troutwine
<goofy_headed_punk@msn.com> wrote:
>I'm trying to write a program to output a Lagrange interpolating
>polynomial.
[snip]
>Does anybody have the experience to tell me how to calculate symbolically?
>(Specifically how to implement a symbolic algebra module.)
There may well be some dedicated Perl module, but are you sure that
would be the best choice? There's a highly specialized and optimized
softare package called FORM especially aimed at tasks like yours (and
more complex, of course: it is particularly popular amongst high
energy physics researchers). Since it is compiler, after all, I think
you may efficiently use it from Perl if needed...
Once I did something similar myself, feeding it imput from Perl and
collecting its output with Perl to transform it into LaTeX code.
Unfortunately I don't have anything of that "work" left. It was really
nothing important however.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 1 Oct 2004 03:22:08 -0700
From: tony@skelding.co.uk (Tony Skelding)
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <a78026a1.0410010222.ff95c01@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnclorc6.hv.abigail@alexandra.abigail.nl>...
> Joe Smith (Joe.Smith@inwap.com) wrote on MMMMXLVIII September MCMXCIII in
> <URL:news:TeS6d.146050$D%.55455@attbi_s51>:
> %% Paul Lalli wrote:
> %%
> %% > "David Filmer" <ineverreadanythingsenttome@hotmail.com> wrote in message
> %% >>enclose %food (not parens). I associate curlys with hashes.
> %% >
> %% > Your association is incorrect.
> %% > ( ) are used to create arrays and hashes.
> %% > { } are used to create hash references
> %% > [ ] are used to create array references
> %%
> %% I would phrase it differently.
> %% ( ) are used to build lists, which can populate arrays and hashes.
>
> Eh, wrong. () seldomly build lists. It certainly doesn't in:
>
> my %hash = (key1 => 'val1', key2 => 'val2');
>
> The parens in the above expression play exactly the same role as
> they do in:
>
> my $val = 3 * (4 + 5);
>
> They help the parser to construct a parse-tree.
>
> %% { } are used to create a reference to an anonymous hash.
> %% [ ] are used to create a reference to an anonymous array.
>
>
> Abigail
Or to put it it simpler terms, the parentheses are only necessary
because the = has higer precedence than the ,
------------------------------
Date: Fri, 01 Oct 2004 17:44:39 +0100
From: "P.R.Brady" <iss025@bangor.ac.uk>
Subject: While query
Message-Id: <415D8977.50803@bangor.ac.uk>
Why does 'while' fail to pop a blank string from an array in the following?
use strict;
use warnings;
my @array;
push @array,"";
push @array,"2";
while ($_= pop(@array)) {
print "popped $_ \n";
}
It returns the "2" but not the blank.
Regards
Phil
------------------------------
Date: Fri, 01 Oct 2004 11:00:24 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: While query
Message-Id: <10lr396pg5ddr6c@corp.supernews.com>
P.R.Brady wrote:
> Why does 'while' fail to pop a blank string from an array in the following?
>
> use strict;
> use warnings;
>
> my @array;
> push @array,"";
> push @array,"2";
>
> while ($_= pop(@array)) {
> print "popped $_ \n";
> }
>
> It returns the "2" but not the blank.
It doesn't fail to pop the blank string.
When the blank string is popped, $_= pop(@array) evaluates to false. The
while condition is no longer true, so control passes out of the while
loop without executing the code inside the loop.
------------------------------
Date: Fri, 01 Oct 2004 18:13:53 +0100
From: "P.R.Brady" <iss025@bangor.ac.uk>
Subject: Re: While query
Message-Id: <415D9051.60300@bangor.ac.uk>
Scott Bryce wrote:
> P.R.Brady wrote:
>
>> Why does 'while' fail to pop a blank string from an array in the
>> following?
>>
>> use strict;
>> use warnings;
>>
>> my @array;
>> push @array,"";
>> push @array,"2";
>>
>> while ($_= pop(@array)) {
>> print "popped $_ \n";
>> }
>>
>> It returns the "2" but not the blank.
>
>
> It doesn't fail to pop the blank string.
>
> When the blank string is popped, $_= pop(@array) evaluates to false. The
> while condition is no longer true, so control passes out of the while
> loop without executing the code inside the loop.
>
Scott,
I clearly have a misunderstanding here. You are saying that the
$_=pop(@array) evaluates false because $_ is false?
Panic - where have I made this assumption elsewhere?
So to empty and process my array/stack I need to:
while (scalar(@array)) {
$_=pop(@array);
...
}
Thanks
Phil
------------------------------
Date: 1 Oct 2004 17:20:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: While query
Message-Id: <Xns957587AB5D3Casu1cornelledu@132.236.56.8>
"P.R.Brady" <iss025@bangor.ac.uk> wrote in
news:415D8977.50803@bangor.ac.uk:
> Why does 'while' fail to pop a blank string from an array in the
> following?
>
> use strict;
> use warnings;
>
> my @array;
> push @array,"";
This is an empty string. An empty string is evaluates to false in Perl.
> push @array,"2";
>
> while ($_= pop(@array)) {
The body of the while statement will not be executed if the condition is
false.
> print "popped $_ \n";
> }
>
> It returns the "2" but not the blank.
Are you just trying to pop off array elements while the array is not
empty?
You could instead do
my @array = ('hello', '');
while(@array) {
my $x = pop @array;
print "Popped: [$x]\n";
}
__END__
C:\Scratch> perl t.pl
Popped: []
Popped: [hello]
Sinan
------------------------------
Date: 1 Oct 2004 17:22:44 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: While query
Message-Id: <Xns957588191B864asu1cornelledu@132.236.56.8>
"P.R.Brady" <iss025@bangor.ac.uk> wrote in
news:415D9051.60300@bangor.ac.uk:
> So to empty and process my array/stack I need to:
> while (scalar(@array)) {
> $_=pop(@array);
> ...
> }
You could do
use strict;
use warnings;
my @array = ('hello', '');
while(@array and my ($x) = pop @array) {
print "Popped: [$x]\n";
}
__END__
------------------------------
Date: Fri, 01 Oct 2004 17:39:24 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: While query
Message-Id: <gDg7d.166$ea6.130@trndny06>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns957587AB5D3Casu1cornelledu@132.236.56.8...
> Are you just trying to pop off array elements while the array is not
> empty?
>
> You could instead do
>
> my @array = ('hello', '');
>
> while(@array) {
> my $x = pop @array;
> print "Popped: [$x]\n";
> }
> __END__
Or the canonical way implemented by the magic while(<>){}:
while (defined ($_ = pop @array)){
print "Popped: $_\n";
}
pop returns undef if it is given a blank array as an argument.
Paul Lalli
------------------------------
Date: Fri, 01 Oct 2004 17:41:58 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: While query
Message-Id: <GFg7d.577$MU6.413@trndny08>
"P.R.Brady" <iss025@bangor.ac.uk> wrote in message
news:415D9051.60300@bangor.ac.uk...
> I clearly have a misunderstanding here. You are saying that
the
> $_=pop(@array) evaluates false because $_ is false?
> Panic - where have I made this assumption elsewhere?
In the general case, an assignment expression always returns the value
being assigned:
$x = ($y = foo()); #$x gets the value of foo()
In your specfic case, the while condition was testing the truthfulness
of the entire assignment expression.
Paul Lalli
------------------------------
Date: Fri, 01 Oct 2004 17:43:17 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: While query
Message-Id: <VGg7d.38$6y6.7@trndny02>
I wrote in message news:gDg7d.166$ea6.130@trndny06...
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
> news:Xns957587AB5D3Casu1cornelledu@132.236.56.8...
>
> > my @array = ('hello', '');
> >
> > while(@array) {
> > my $x = pop @array;
> > print "Popped: [$x]\n";
> > }
> > __END__
>
> Or the canonical way implemented by the magic while(<>){}:
>
> while (defined ($_ = pop @array)){
> print "Popped: $_\n";
> }
(I should have mentioned, of course, that this will fail to work if any
of the elements are undefined)
Paul Lalli
------------------------------
Date: Fri, 01 Oct 2004 10:48:48 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: While query
Message-Id: <0th032x7dc.ln2@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-10-01, P.R.Brady <iss025@bangor.ac.uk> wrote:
> Why does 'while' fail to pop a blank string from an array in the following?
>
> use strict;
> use warnings;
>
> my @array;
> push @array,"";
> push @array,"2";
>
> while ($_= pop(@array)) {
> print "popped $_ \n";
> }
>
> It returns the "2" but not the blank.
Others have already posted why; how about another how?
use strict;
use warnings;
my @array=('','2');
foreach (reverse @array)
{
print "''popped'' [$_]\n";
}
Probably less efficient than A. Sinan's suggestion, but I really like
using for/foreach to assign list/array values in turn to $_ (or to a
my'd scalar).
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBXZh+hVcNCxZ5ID8RAgMyAJwMLFu0oqOGy8ri3njlWvz6iSdPKwCfQQ1e
JDulc8T/WZ92MCBFANn4l18=
=Iu0W
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 01 Oct 2004 15:44:37 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Who's responsible for this ?
Message-Id: <7pnql01mshhmkaq0p58bc1il8qe7dohlib@4ax.com>
On 30 Sep 2004 21:13:30 GMT, Csaba <root@localhost> wrote:
> not exp log srand xor s qq qx xor
> s x x length uc ord and print chr
> ord for qw q join use sub tied qx
> xor eval xor print qq q q xor int
> eval lc q m cos and print chr ord
> for qw y abs ne open tied hex exp
> ref y m xor scalar srand print qq
> q q xor int eval lc qq y sqrt cos
> and print chr ord for qw x printf
> each return local x y or print qq
> s s and eval q s undef or oct xor
> time xor ref print chr int ord lc
> foreach qw y hex alarm chdir kill
> exec return y s gt sin sort split
Whoever... cool!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7199
***************************************