[19396] in Perl-Users-Digest
Perl-Users Digest, Issue: 1591 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 22 21:05:31 2001
Date: Wed, 22 Aug 2001 18:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998528713-v10-i1591@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 22 Aug 2001 Volume: 10 Number: 1591
Today's topics:
Accessing $a and $b in conjunction with goto &NAME <gamma@mintaka.iern.disa.mil>
Re: Accessing anonymous hash inside array?? (Tad McClellan)
Re: Accessing anonymous hash inside array?? (Tad McClellan)
Re: array question... sort of <goldbb2@earthlink.net>
Re: days since 1/1/1970 (Abigail)
DB_File on Tru64.. In-memory DBTree still uses /tmp ?? (Patrick Saunders)
Re: Directory listing order <cberry@cinenet.net>
Re: Directory listing order <stevea@wrq.com>
Re: Directory listing order <goldbb2@earthlink.net>
Re: Directory listing order (Randal L. Schwartz)
Help with Calculating fields <james.salt@virgin.net>
Re: i need to count words in perl <cberry@cinenet.net>
Re: i need to count words in perl (Abigail)
Job Control in Perl <christopher.knowlton@usa.xerox.com>
Re: Loading up a program asociated with a file (Eric Bohlman)
Re: Need help trapping 'not a number' errors <godzilla@stomp.stomp.tokyo>
Re: Need help trapping 'not a number' errors <samneric@tigerriverOMIT-THIS.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Aug 2001 19:04:17 -0400
From: "W. James Showalter, Jr." <gamma@mintaka.iern.disa.mil>
Subject: Accessing $a and $b in conjunction with goto &NAME
Message-Id: <Pine.GSO.4.32.0108221846330.6948-100000@mintaka.iern.disa.mil>
Hello,
I am using perl 5.6.0 on Solaris 8.
Here is a fragment of a subroutine I use for sorting dotted values
(e.g. OIDs and IP addresses). It resides in a library package.
sub ipsort {
my $pkg = (caller)[0];
my @a = split(/\./, ${"$pkg\::a"});
my @b = split(/\./, ${"$pkg\::b"});
# remainder of code
}
Rather than come up with a more generic name I wanted it to be
able to be called by the name 'oidsort'. So I put the following in
the same package as ipsort.
sub oidsort {
goto &ipsort;
}
However, this did not work even though the calling package name
was correctly determined in the actual sub 'ipsort'. The errors
indicated that $a and $b were not initialized.
My ultimate solution was to use
*oidsort = \&ipsort;
which is probably more efficient anyway. But I would appreciate an
explanation as to why my first "solution" did not work.
Thanks,
Jim
------------------------------
Date: Wed, 22 Aug 2001 17:54:23 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Accessing anonymous hash inside array??
Message-Id: <slrn9o8agf.4du.tadmc@tadmc26.august.net>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>
>I am still working my way through creating and
>using references
And you are doing that by referring to perlreftut.pod, I trust?
There are only 4 important things in there. Get those 4 down,
and Bob's your uncle:
2 ways to get a reference
2 ways to dereference
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Aug 2001 18:02:12 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Accessing anonymous hash inside array??
Message-Id: <slrn9o8av4.4du.tadmc@tadmc26.august.net>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>Carlos C. Gonzalez wrote:
>> sub print_all
>> {
>> my ($hashref) = @_;
>> foreach my $key (keys %$hashref) {
>> #<---- NON-REPITITION OF $hashref->{$key}??
>> printf "%15s => %-30s\n", $key, $hashref->{$key} ? $hashref->{$key} :
>> "undefined";
^^^^^^^^^
^^^^^^^^^ that should say "false"
>This here is ok, quite short and idiomatic.
but misleading, as it is possible that it will say "undefined"
when it _is_ defined (but false).
Carlos is not testing for definedness above, he's testing for truth.
printf "%15s => %-30s\n", $key,
defined($hashref->{$key}) ? $hashref->{$key} : "undefined";
Or maybe he wanted exists() instead.
Truth, existence and definedness are 3 different things, you
should test for the one that you mean to be testing for.
(I often either run through the hash, or make sure when loading
the hash, that undef hash values are forced to empty strings, then
I don't need shenanigans as above.
)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Aug 2001 20:03:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: array question... sort of
Message-Id: <3B844846.8C664C1E@earthlink.net>
Leary wrote:
>
> I'm using the below script to create an array of arrays that is the
> output of a dos command. What I need to do next is create an array for
> each $acct so I can seperate all the transactions by account in order
> to generate totals. My question then is this; how can I use an element
> of one array as the name of another array?
As others have said, you can, but shouldn't. What you really want is an an element of one array as the key of a hash of arrays.
> (I'm thinking a seperate array for each account.)
Ok, as long as each "seperate array" is actually an anonymous array, not a named one, and are values of a hash.
> Am I on the wrong track entirely? Is there another method that seems
> better suited to this task?
>
> I would appreciate being pointed in the write direction.
>
> TIA
>
> <<begin script>>
> #!perl
#! perl -w
use strict;
> #8/12/2001 11:22PM
> open (TESTDATA, 'VHOUSE3 %IBERDIR%\\DATA\\HOUSE50|') or die "Can't run
> vhouse3.exe";
> while (<TESTDATA>) {
Because dos/win only emulate pipes [they actually run the command until completion, putting it's data into a textfile, then open that file to read a line at a time, there is little advantage in using the above syntax, except in terms of memory usage [having the whole output in memory, or dealing with a line at a time]. Since a slurp is likely faster, you might prefer:
foreach( qx'VHOUSE3 %IBERDIR%\\DATA\\HOUSE50' ) {
> #This line is only for the purpose of rejecting the header info from
> #the output of the dos command.
> #Valid data has a time field as the first field. (Gotta be a better
> #way to reject the header lines)
> my ($ttime, $AmPm, $tday, $tmonth, $tdate, $tyear, $acct, $type, $amt,
> $tip, $prt, $purge) = split;
> push @array, [ split ] if "$ttime" =~ /\d\d:\d\d:\d\d/;
my @fields = split;
push @array, \@fields if $fields[0] =~ /^\d\d:\d\d:\d\d\z/
> }
> $tot = 0;
> for $i ( 0 .. $#array ) { # $#array is the total number of rows in the array
> $tot += "$array[$i][8]";
> }
$tot += $_->[8] foreach( @array );
> printf "%10d %68.2f\n", $#array, $tot;
printf "%10d %68.2f\n", scalar(@array), $tot;
> >>end script<<
>
> <<begin sample data>>
>
> VHOUSE2 v5.011 Copyright (C) 1994 by Yoho, Inc.
> Time ACCT TYPE AMT TIP PRINT PURGE
> ---------------------------- ----- -------- ------ ------ ----- -----
> 02:00:00 PM Thu Apr 12, 2001 03422 CHARGE 6.25 0.00 FALSE FALSE
> 02:00:00 PM Thu Apr 12, 2001 09562 CHARGE 8.50 0.00 FALSE FALSE
> 02:00:00 PM Thu Apr 12, 2001 02129 CHARGE 30.68 0.00 FALSE FALSE
#! perl -w
use strict;
my $template = "a28 x2 a5 x2 a8 x2 a6 x2 a6 x a5 x a5";
open( my $vhouse, "-|", 'VHOUSE3 %IBERDIR%\\DATA\\HOUSE50' )
or die "Couldn't fork: $!";
my @headers = unpack $template, scalar <$vhouse>
until $headers[-1] or eof $vhouse;
for( @headers ) {
s/^\s*//;
1 while s/\s\z//;
}
scalar <$vhouse>; # discard one line.
my %transactions;
my ($count, $total); # $total defaults to 0
while( <$vhouse> ) {
my %transaction;
for( @transaction{@headers} = unpack $template, $_ ) {
s/^\s*//;
1 while s/\s\z//;
}
$total += $transaction{AMT}; ++$count;
my $account = delete $transaction{ACCT};
# delete() removes it and returns old value.
push @{$transactions{$account}}, \%transaction;
# After all, having it in here would be redundant.
}
unless( close $vhouse ) {
my ($ret, $sig) = ($?/256, $?&255);
die "vhouse.exe died from signal $sig\n" if $sig;
die "vhouse.exe exited with code $ret\n" if $ret;
die "Error running vhouse.exe: $!";
}
while( my ($acct, $trns) = each %transactions ) {
my $sum; $sum += $_->{AMT} foreach( @$trns );
printf "%05d: %10d %68.2f\n", $acct, scalar(@$trns), $sum;
}
printf "total: %10d %68.2f\n", $count, $total;
--
I'm not a programmer but I play one on TV...
------------------------------
Date: 22 Aug 2001 23:09:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: days since 1/1/1970
Message-Id: <slrn9o8ess.6m2.abigail@alexandra.xs4all.nl>
Jürgen Exner (jurgenex@hotmail.com) wrote on MMCMXIII September MCMXCIII
in <URL:news:3b8418a8$1@news.microsoft.com>:
)) "Abigail" <abigail@foad.org> wrote in message
)) news:slrn9o82d0.6m2.abigail@alexandra.xs4all.nl...
)) > Valentin 30IR976 (radiotito@yahoo.com) wrote on MMCMXIII September
)) > MCMXCIII in <URL:news:3B83E612.5E0A9EA@yahoo.com>:
)) > :} I would need to get exactly days since 1/1/1970. I need to put this
)) >
)) > time() gives you seconds since 1/1/1970. Since 1970, days have had the
)) > same amount of seconds.
))
)) This is not totally accurate. There have been a few years where additional
)) seconds have been inserted to adjust our artifical time to the actual sun
)) time.
And those seconds have been happily ignored by Unix time.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 22 Aug 2001 17:08:09 -0700
From: psaunder@comcen.com.au (Patrick Saunders)
Subject: DB_File on Tru64.. In-memory DBTree still uses /tmp ??
Message-Id: <7bfe00fe.0108221608.52c1229e@posting.google.com>
I've hunted the net like a madman
for an answer to this.
My program simply reads lines from STDIN
and puts them into BTree. I want to use
memory (we have 12Gb of RAM) but it still uses
/tmp, even when I use 'undef' as file name
as per documentation.
(prog has been trimmed for brevity)
Any ideas as to why it does this?
I suspect it's something to do with the
Tru64 libraries.
ta,
patrick.
========= my prog ================================
#!/usr/bin/perl
use Digest::MD5 qw(md5 md5_hex md5_base64);
use DB_File;
use Fcntl;
# Create BTree in memory
$db = tie(%h, 'DB_File',undef , O_RDWR|O_CREAT, 0, $DB_BTREE) or
die("cant tied DB_FILE: $!");
my $k;
print STDERR "Reading standard input...\n";
open(STDIN);
while(<STDIN>){
$h{$_} = 'X';
}
print STDERR "Done reading input...\n";
close(STDIN);
untie %h;
=====================================
------------------------------
Date: Wed, 22 Aug 2001 22:33:01 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: Directory listing order
Message-Id: <Xns91059E300CF7Ecberrycinenetnet1@207.126.101.92>
Guillaume Filion <gfk@spamcop.net> wrote in news:gfk-07749D.16180322082001
@news.videotron.net:
> I'd like to read the content of a directory in this order: files first,
> then directories. The order of the files or directory is not important
> as long as all the files are first.
>
> Here's how I implemented this:
> -----
> opendir CACHEDIR, $dirpath or die "serious dainbramage: $!";
> my @allfiles = readdir CACHEDIR;
my @allfiles = sort { -f $a && -d $b ? -1 :
-d $a && -f $b ? +1 : 0 } readdir CACHEDIR
At that point, @allfiles contains the list of files then directories.
Note that you can replace that final "0" with "$a cmp $b" to get lexical
ordering within each category.
Add a "grep !/^..?$/" between the sort and the readdir to eliminate the .
and .. dirs, as your original loop did.
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: Wed, 22 Aug 2001 22:39:12 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Directory listing order
Message-Id: <u1ym3u39k.fsf@wrq.com>
Guillaume Filion <gfk@spamcop.net> writes:
>Hi all,
>
>I'd like to read the content of a directory in this order: files first,
>then directories. The order of the files or directory is not important
>as long as all the files are first.
>
>Here's how I implemented this:
>-----
>opendir CACHEDIR, $dirpath or die "serious dainbramage: $!";
>my @allfiles = readdir CACHEDIR;
>closedir CACHEDIR;
>
>my @directories;
>my @files;
>foreach my $thing (@allfiles) {
> next if ($thing =~ /^\.\.?$/ or not $thing);
> push(@directories, $thing) if (-d "$dirpath/$thing");
> push(@files, $thing) if (-f "$dirpath/$thing");
>}
>push(@files, @directories);
>-----
>
>It seems to me like a lot of code just to do this... Does any one of you
>knows a better/simplier way to do this?
Maybe using unshift will tidy things up a bit:
my @ls;
for (readdir CACHEDIR) {
next if /^\.\.?$/;
push @ls, $_ if -d "$dirpath/$_";
unshift @ls, $_ if -f "$dirpath/$_";
}
closedir CACHEDIR;
Not a big difference, but it seems cleaner to me.
--
-- Steve __
------------------------------
Date: Wed, 22 Aug 2001 19:11:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Directory listing order
Message-Id: <3B843C07.92CB6955@earthlink.net>
Guillaume Filion wrote:
>
> Hi all,
>
> I'd like to read the content of a directory in this order: files
> first, then directories. The order of the files or directory is not
> important as long as all the files are first.
>
> Here's how I implemented this:
> -----
> opendir CACHEDIR, $dirpath or die "serious dainbramage: $!";
> my @allfiles = readdir CACHEDIR;
> closedir CACHEDIR;
>
> my @directories;
> my @files;
> foreach my $thing (@allfiles) {
> next if ($thing =~ /^\.\.?$/ or not $thing);
> push(@directories, $thing) if (-d "$dirpath/$thing");
> push(@files, $thing) if (-f "$dirpath/$thing");
How about:
push @{ -d "$dirpath/$thing" ? \@directories : \@files },
$thing;
> }
> push(@files, @directories);
Or, eliminating that final push():
my @files;
foreach (@allfiles) {
next if /^\.?\.?\z/;
-d "$dirpath/$_" ? push(@files,$_) : unshift(@files, $_);
}
If you don't like ?: you can put in a simple if/else.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: 22 Aug 2001 16:34:14 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Directory listing order
Message-Id: <m1d75nd5zd.fsf@halfdome.holdit.com>
>>>>> "Craig" == Craig Berry <cberry@cinenet.net> writes:
Craig> my @allfiles = sort { -f $a && -d $b ? -1 :
Craig> -d $a && -f $b ? +1 : 0 } readdir CACHEDIR
That's a helluva lot of stats for any non-trivial directory. I'd GRT
that...
my @allfiles =
map substr($_, 1),
sort
map { (-d $_ ? 1 : 0).$_ } readdir CACHEDIR;
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 22 Aug 2001 22:32:41 GMT
From: James Salt <james.salt@virgin.net>
Subject: Help with Calculating fields
Message-Id: <3B8431A6.94310E1F@virgin.net>
I must say before I ask my question I am new to CGI scripts. However I
do know some C++ and I have made various alterations to the formmail
script that I am using.
What I want to do in the cgi script is to multiply a form field
(Quantitiy) by a number that I want to hard code into the script
(amount).
I can multiply two numbers together in the script but when I try to
multiply a variable name by a number this does not work. I think where I
am going wrong is the script might think the form field that I am trying
to multiply is text, how do I specify that the text field I am wanting
to use is a number field and not a text field?
This is a little piece of the script I am using, any help to put me on
the right track would be gratefully appreciated:
$amount=20*Quantity;
print MAIL "This is the $amount you need to pay to\n\n ";
Regards,
James
------------------------------
Date: Wed, 22 Aug 2001 22:20:16 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: i need to count words in perl
Message-Id: <Xns91059C06628AFcberrycinenetnet1@207.126.101.92>
dime0000@yahoo.com (Larry S) wrote in news:8fd7acb0.0108220737.57aac387
@posting.google.com:
> ok, i have a variable, $text, which contains a certain amount of words.
> i want to display the first 30 words of $text, nothing more.
A lot depends on a more detailed analysis of your requirements. What
constitutes a "word"? Anything matching /\w+/, or maybe /\S+/, or something
else? When you say you want the first 30 words, do you mean just those
words (presumably delimited somehow), or the fragment of $text containing
the first 30 words, with all surrounding spaces and punctuation intact?
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: 22 Aug 2001 23:16:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: i need to count words in perl
Message-Id: <slrn9o8fan.6m2.abigail@alexandra.xs4all.nl>
Ren Maddox (ren@tivoli.com) wrote on MMCMXIII September MCMXCIII in
<URL:news:m34rr09bku.fsf@dhcp9-161.support.tivoli.com>:
:} On Wed, 22 Aug 2001, Rainer.Klier@erl.sbs.de wrote:
:}
:} > Larry S wrote:
:} >>
:} >> ok, i have a variable, $text, which contains a certain amount of
:} >> words. i want to display the first 30 words of $text, nothing
:} >> more. any simple solutions?
:} >
:} > print join " ",((split " ",$text)[0..29]);
:}
:} For variety:
:}
:} print $text =~ /^((?:\S+\s+){0,30})/g;
That would fail if text contained thirty words exactly, with no whitespace
following the last word.
But what about:
There might be a problem if there are dashes -- like this -- in
the text.
That would count the dashes as words, for 16 words in the sentence above.
However, another common way of writing the above sentence is:
There might be a problem if there are dashes--like this--in
the text.
Now we suddenly have 12 words. For the same sentence!
Perhaps finding words from a text isn't as trivial as most people think
it is.
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
------------------------------
Date: Wed, 22 Aug 2001 11:44:29 -0400
From: "Chris Knowlton" <christopher.knowlton@usa.xerox.com>
Subject: Job Control in Perl
Message-Id: <9m0k6d$i7a$1@news.wrc.xerox.com>
I have an application where I am spawning children which then spawn multiple
children in turn. I am trying to implement the "cancel" button for a poller
that sits and watches several 'sets' of this type of job under Solaris 2.6.
I have tried using the following kill statement and it only kills off the
parent and the next process in line is orphaned and continues to execute.
kill 9, <pid>;
waitpid $pid, 0;
Then I read a snippet in "Programming Perl" about negating the pid and then
killing it. (supposedly this kills the entire job) This does not work but
with different behavior...
$pid = $pid * -1;
kill 9, $pid;
waitpid $pid, 0;
This code does not kill anything and the parent hangs waiting for waitpid to
unblock.
Now, I have mis-interpreted stuff in the book before and I am not ruling
that out, but I suspect that others have done this before and may be able to
point me to a reference or a code frag that can help me out.
Each job is opened using the following...
foreach (@command_list) {
$pid = (open($handle, "$_ |"));
}
Each command immediately spawns several more shells and an xterm. The
command and all it's sub-processes need to die for succesful cancel. I have
no control over the processes below the XTERM process, they are spawned by
code I don't own or can't change.
The process map looks like
PERL_SCRIPT -----V <---- this
is the poller
csh -c -----V
xterm-----V
sh -c-----V
csh-----V
COMPILER
Any help would be much appreciated, especially if you have a reference to a
book.
Chris Knowlton
christopher.knowlton@usa.xerox.com
------------------------------
Date: 22 Aug 2001 23:44:08 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Loading up a program asociated with a file
Message-Id: <9m1g48$3em$3@bob.news.rcn.net>
Peter Mann <Pcmann1@btinternet.com> wrote:
> I am trying to load an HTML file using whatever default browser in
> installed on the computer. In Visual Basic, I can use a command to load a
> file, and the program associated with the file extension will be loaded.
> I am trying to achieve the same in Perl!
> To my understanding, there is a 'system' command which could be used to
> start up a browser with a HTML page. However, I would need the path to the
> browser - I suppose this could be stored in a file for use by the program.
> However, I was hoping to load a browser which may reside any different
> location!, and different computers may have different default browsers. Is
> there a command therefore which will load a file into a program and select
> the program with respect to the type of file it is?
If, as I suspect from your reference to VB, you're talking about Win32
systems exclusively, then you can use the command processor's "start"
command to do the work of finding and starting the browser:
my $url='http://www.perl.com';
system('start',$url);
start is just a wrapper around the Win32 API's ShellExecute function,
which is undoubtedly what VB is using.
On non-Win32 systems, this won't work; at some point you're going to have
to find out from the user what they're preferred browser is and how to
invoke it.
------------------------------
Date: Wed, 22 Aug 2001 15:18:06 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Need help trapping 'not a number' errors
Message-Id: <3B842F9E.3486F064@stomp.stomp.tokyo>
C.J. Mackie wrote:
(snipped)
Godzilla suggested, "Think Scientific Notation."
> ...Nor is it scientific notation, since the file to be processed is
> binary floats packed and unpacked with "f".
http://www2.hursley.ibm.com/decimal/dxexcep.html
Read and learn. You will be a better troll in turn.
Who knows, if you smarten up enough, you might even
slip one of your troll articles by me. Nonetheless,
you will never come close to matching my Perl skills.
Godzilla! Queen Of Decimalatia.
------------------------------
Date: Wed, 22 Aug 2001 19:31:11 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Need help trapping 'not a number' errors
Message-Id: <MPG.15ee0aa6174bfe17989690@news.onemain.com>
C.J. Mackie wrote:
> Hi, Malcolm. The problem isn't negatives, unfortunately (I tried sqrt'ing
> negatives, and zero, and it's not the same error text). In fact, it
> shouldn't be possible for the number to be negative, since the expression is
> sqrt( $val1 * $val2), where $val[12] are both sums of squares. Nor is it
> scientific notation, since the file to be processed is binary floats packed
> and unpacked with "f".
>
> There's no doubt you're right--eval is the way to go. I was just stuck on
> trying to figure out the bad value rather than trapping all errors (thought
> it might be less expensive). I've reconfigured the program with an eval
> block, and it's past the first trouble spot with no worries--noticeably
> slower, but still fast enough.
I did a google search on "1.#QNAN" and the results were interesting.
Evidently, the IEEE spec allows C library functions which return a double to
return a 'quiet NaN' as an error-flag instead of raising an exception. The qNaN
is supposed to be allowed to propagate through other math functions without
causing further errors.
(When converted from float to string it displays as "1.#QNAN" ???)
Evidently some compiled module that you are using (or your version of perl core
itself??) is invoking such a function, seeing no error flag and then not
trapping with isnan() for the 'quiet NaN' as a return value before passing it
to sqrt() - which chokes on it.
Any chance you could share the code and values that eval() trapped? I'd like to
know where it occurred.
------------------------------
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.
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 1591
***************************************