[26084] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8285 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 28 09:05:30 2005

Date: Thu, 28 Jul 2005 06:05:05 -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           Thu, 28 Jul 2005     Volume: 10 Number: 8285

Today's topics:
    Re: Earthquake Forecasting Program  July 11, 2005 <horedson@earthlink.net>
    Re: How does a scalar know what it is? <notvalid@email.com>
        integer fail ... <gis86508@cissol1.cis.nctu.edu.tw>
    Re: integer fail ... <jurgenex@hotmail.com>
    Re: integer fail ... <sisyphus1@nomail.afraid.org>
    Re: integer fail ... <tadmc@augustmail.com>
    Re: Perl performance issue <thepoet_nospam@arcor.de>
    Re: tied hash (Anno Siegel)
        true false ? : expression thingy <someone@somewhere.com>
    Re: true false ? : expression thingy (Anno Siegel)
    Re: true false ? : expression thingy <someone@somewhere.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Jul 2005 04:35:51 GMT
From: "Hank Oredson" <horedson@earthlink.net>
Subject: Re: Earthquake Forecasting Program  July 11, 2005
Message-Id: <HgZFe.5345$0C.4915@newsread3.news.pas.earthlink.net>

"Lemming" <thiswillbounce@bumblbee.demon.co.uk> wrote in message 
news:7qage1h9vve4ba0ub0ka3fuo4nph7j3qv0@4ax.com...
> On Wed, 13 Jul 2005 23:39:46 GMT, "Hank Oredson"
> <horedson@earthlink.net> wrote:
>
>>In particular I am interested in the EM dataset.
>
> Hank, with respect ...
>
> Posted to nine newsgroups; fluffy responses when you ask specific
> questions; evasion when you repeatedly ask for real data ... I regret
> to say, YHBT.
>
> Lemming
> -- 
> Curiosity *may* have killed Schrodinger's cat.

Why yes, your post was much more informative and interesting.
Do you have the EM dataset?

-- 

  ... Hank

http://home.earthlink.net/~horedson
http://home.earthlink.net/~w0rli




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

Date: Thu, 28 Jul 2005 03:24:04 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: How does a scalar know what it is?
Message-Id: <odYFe.1262$iM7.1056@newssvr21.news.prodigy.com>

Tom wrote:
> again at the machine level, how does perl know
> what it has?

I'm curious to know why you ask this question. If you want a language 
that is closer to the hardware, then you know where to find C, or even 
assembly. The whole point of a higher level language like Perl is to 
unburden (is that a real word?) the user from such information. As a 
Perl user, you don't need to keep track of whether a scalar is an 
integer, string, reference or whatever. You can rest assured that:

	print $x;

will do the Right Thing (tm) irrespective of what $x contains. This 
comes at the expense of more memory usage. If your goal is to optimize 
memory/performance, then you should be looking at a lower level language 
like C.

--Ala



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

Date: Thu, 28 Jul 2005 03:35:38 +0000 (UTC)
From: stratus <gis86508@cissol1.cis.nctu.edu.tw>
Subject: integer fail ...
Message-Id: <dc9jqa$2prt$1@news.cis.nctu.edu.tw>

$input_startx=223.0000;
$input_starty=221.0000;
 
$input_endx=2392.2000;
$input_endy=2484.2000;
 
$input_step=0.8;
 
$total=$input_endy-$input_starty;
$track =$total/$input_step;
print "...$track....\n";     ====================> 2829
$track=int $track;
print "...$track....\n";     ====================> 2828

Why ??????   2829 changed to 2828 ???




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

Date: Thu, 28 Jul 2005 04:00:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: integer fail ...
Message-Id: <JLYFe.7949$mU3.7423@trnddc02>

stratus wrote:
[...]
> $input_step=0.8;
[...]
> Why ??????   2829 changed to 2828 ???

You ignored the first law of computer numerics: "Thou shalt not use floating 
point for precision computations."
See "perldoc -q 9999"

jue 




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

Date: Thu, 28 Jul 2005 15:58:45 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: integer fail ...
Message-Id: <42e87444$0$1097$afc38c87@news.optusnet.com.au>


"stratus" <gis86508@cissol1.cis.nctu.edu.tw> wrote in message
news:dc9jqa$2prt$1@news.cis.nctu.edu.tw...
> $input_startx=223.0000;
> $input_starty=221.0000;
>
> $input_endx=2392.2000;
> $input_endy=2484.2000;
>
> $input_step=0.8;
>
> $total=$input_endy-$input_starty;
> $track =$total/$input_step;
> print "...$track....\n";     ====================> 2829
> $track=int $track;
> print "...$track....\n";     ====================> 2828
>
> Why ??????   2829 changed to 2828 ???
>
>

To (partly) see why:

use warnings;
use Devel::Peek;

$input_starty=221.0000;

$input_endy=2484.2000;

$input_step=0.8;

$total=$input_endy-$input_starty;
$track =$total/$input_step;

print "############\n";
Dump($track);
print "############\n";

print "...$track....\n";
$track=int $track;

print "############\n";
Dump($track);
print "############\n";

print "...$track....\n";

__END__

Which produces for me:

############
SV = NV(0x8b09bc) at 0x8c07c8
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  NV = 2829
############
 ...2829....
############
SV = PVNV(0x3f8704) at 0x8c07c8
  REFCNT = 1
  FLAGS = (IOK,pIOK)
  IV = 2828
  NV = 2829
  PV = 0x89304c "2829"\0
  CUR = 4
  LEN = 35
############
 ...2828....

The first time $track was printed, the NOK flag was set - so it printed the
value contained in the NV slot.
The second time $track was printed, the IOK flag was set (because the int
function had been called) - so it printed the value contained in the IV
slot.

Of course the above doesn't demonstrate how the IV slot came to contain
2828. Does someone know of a way of providing such a demonstration ?

(We can surmise that the reason the IV slot contains 2828 is that the int()
function received a value something like 2828.99999.... .
But it would be so much more conclusive if there were a way to actually
*demonstrate* that that's what happened.)

Cheers,
Rob




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

Date: Thu, 28 Jul 2005 07:46:20 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: integer fail ...
Message-Id: <slrndehkss.9rq.tadmc@magna.augustmail.com>

stratus <gis86508@cissol1.cis.nctu.edu.tw> wrote:
> $input_startx=223.0000;
> $input_starty=221.0000;
>  
> $input_endx=2392.2000;
> $input_endy=2484.2000;
>  
> $input_step=0.8;
>  
> $total=$input_endy-$input_starty;
> $track =$total/$input_step;
> print "...$track....\n";     ====================> 2829
> $track=int $track;
> print "...$track....\n";     ====================> 2828


change your print() statements to:

   printf "...%30.20f....\n", $track;

 ...

> Why ??????   2829 changed to 2828 ???

 ... and you will see why.   :-)



Then see the answer to your Frequently Asked Question:

    Why am I getting long decimals (eg, 19.9499999999999) instead of the
    numbers I should be getting (eg, 19.95)?


And you might also benefit from this FAQ:

       Does Perl have a round() function?  ...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 28 Jul 2005 07:23:17 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Perl performance issue
Message-Id: <42e86bac$0$11753$9b4e6d93@newsread4.arcor-online.net>

Cameron McCormack schrieb:
> Hi everyone.
> 
> I am migrating my web/mail/svn/etc. servers from a computer connected to
> my ADSL at home, an old Athlon 800, to a hosted Celeron 2.4GHz machine.
> I found though that Perl runs much more slowly on the new machine and I
> really don't know why.  The problem seems to show itself mostly when
> loading modules (though this could just be because there is lots of
> code in the modules).

Did you check other programs than perl too? It could very
well be an issue of the system configuration (like missing
kernel optimisations). You should perhaps also check with
"top" if there are processor time consuming tasks running
in the background.

If it's indeed only perl that runs slowly, you could run
"strace -fFv -o SOMEFILE.txt perl -e1" and compare the
output (SOMEFILE.txt) on both machines whether there are
some obvious problems on the new machine that don't appear
on the old one.

There are quite a number of possible causes, even hardware
errors. Most of them should show their signs in the event
log or when doing an strace.

HTH
-Chris


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

Date: 28 Jul 2005 10:46:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: tied hash
Message-Id: <dcad2h$a84$1@mamenchi.zrz.TU-Berlin.DE>

Konrad Eisele  <konrad@gaisler.com> wrote in comp.lang.perl.misc:
> I have a tied hash, say %a. On a tied 'STORE' I want to get the return 
> values of the STORE function. is that possible? a naive aproach would be
> @a = ($a{'key'} = 'value'); however this returns still the tied FETCH
> of $a{'key'}. How do i have to reorder the expression??
> 
> -- Konrad
> 
> 
> 
> 
> %a = ();
> tie %a,'Ta';
> @a = ($a{'key'} = 'value');

When this happens, @Ta::ISA is not yet set.

> package Ta;
> use Tie::Hash;
> @ISA = qw(Tie::StdHash);

This happens too late.  Wrap "BEGIN {}" around it.

> sub STORE {
> 	return [1,2,3];
> }

Your example program doesn't use your STORE method.

But even if it did, what is returned by an assignment is always the
variable on the left hand side (with the new value already in it).
If that happens to be tied, or, in your example, happens to be a value
in a tied hash, that doesn't change that fact.  The value you see will
be the value stored (as read back by READ), no matter what STORE returns.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 28 Jul 2005 11:40:24 +0100
From: "Bigus" <someone@somewhere.com>
Subject: true false ? : expression thingy
Message-Id: <dcacmr$bg3$1@blackmamba.itd.rl.ac.uk>

I'm not sure what this method is called, which is perhaps why I've had no 
luck when searching around the web for info on it, but when you want a 
1-line alternative to an if...else.. construct, you can use the following 
syntax:

$ctr > 3 ? $text = "yes" : $text = "no";

that works fine, however, when I try this:

my $incsubs;
$line =~ /\ts/i ? $incsubs = 0 : $incsubs = 1;

it doesn't work.. well, $incsubs equals 1 regardless whereas it works in the 
standard if...else.. construct.

I guess this is because the regular expression doesn't return true/false, or 
sth like that.. is there a "trick" you can use to make this type of method 
work with regexps?

Bigus 




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

Date: 28 Jul 2005 11:15:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: true false ? : expression thingy
Message-Id: <dcaenn$d40$1@mamenchi.zrz.TU-Berlin.DE>

Bigus <someone@somewhere.com> wrote in comp.lang.perl.misc:
> I'm not sure what this method is called, which is perhaps why I've had no 
> luck when searching around the web for info on it, but when you want a 
> 1-line alternative to an if...else.. construct, you can use the following 
> syntax:
> 
> $ctr > 3 ? $text = "yes" : $text = "no";
> 
> that works fine, however, when I try this:
> 
> my $incsubs;
> $line =~ /\ts/i ? $incsubs = 0 : $incsubs = 1;
> 
> it doesn't work.. well, $incsubs equals 1 regardless whereas it works in the 
> standard if...else.. construct.
> 
> I guess this is because the regular expression doesn't return true/false, or 
> sth like that.. is there a "trick" you can use to make this type of method 
> work with regexps?

Wrong diagnosis.  A regex returns a boolean value in scalar context,
that part of your expression is quite all right.

Your problem is one of precedence.  Perl parses your expression like
this:

    ( ( $line =~ /\ts/i) ? ( $incsubs = 0) : $incsubs) = 1;

So if you have a match, $incsubs is set to 0 and $incsubs is returned.
If you don't have a match, $incsubs is not set to 0, but returned as is.
In either case what is returned is $incsubs, and 1 is assigned to it
unconditionally.  Hence the result you see.

Generally, the "?:" construct (sometimes called "ternary conditional",
btw) should not be used for operations that have a side effect, like
the assignments you are doing.  Use a normal if/else for that, even if
it's a bit longer.

Using "?:", your conditional assignment can be written:

    my $incsubs = $line =~ /\ts/i ? 0 : 1;

Now the assignment is outside the "?:".  But now it becomes apparent
that this is (almost) equivalent to

    my $incsubs = $line !~ /\ts/i;

which is what I would use.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 28 Jul 2005 12:36:25 +0100
From: "Bigus" <someone@somewhere.com>
Subject: Re: true false ? : expression thingy
Message-Id: <dcafvq$cuh$1@blackmamba.itd.rl.ac.uk>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message 
news:dcaenn$d40$1@mamenchi.zrz.TU-Berlin.DE...
> Bigus <someone@somewhere.com> wrote in comp.lang.perl.misc:
[..]>> my $incsubs;
>> $line =~ /\ts/i ? $incsubs = 0 : $incsubs = 1;
>>
[..]
> Your problem is one of precedence.  Perl parses your expression like
> this:
>
>    ( ( $line =~ /\ts/i) ? ( $incsubs = 0) : $incsubs) = 1;
>
> So if you have a match, $incsubs is set to 0 and $incsubs is returned.
> If you don't have a match, $incsubs is not set to 0, but returned as is.
> In either case what is returned is $incsubs, and 1 is assigned to it
> unconditionally.  Hence the result you see.

Ahhh, so this would work:

my $incsubs;
$line =~ /\ts/i ? ($incsubs = 0) : ($incsubs = 1);

> Generally, the "?:" construct (sometimes called "ternary conditional",
> btw) should not be used for operations that have a side effect, like
> the assignments you are doing.  Use a normal if/else for that, even if
> it's a bit longer.
>
> Using "?:", your conditional assignment can be written:
>
>    my $incsubs = $line =~ /\ts/i ? 0 : 1;
>
> Now the assignment is outside the "?:".  But now it becomes apparent
> that this is (almost) equivalent to
>
>    my $incsubs = $line !~ /\ts/i;

OK, that sounds good. I 'll use that in this case. The previous syntax would 
be useful in situations where I want to make a non boolean assigment 
resulting from a regexp match.

Thanks

Bigus




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

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 8285
***************************************


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