[29034] in Perl-Users-Digest
Perl-Users Digest, Issue: 278 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 28 21:10:07 2007
Date: Wed, 28 Mar 2007 18:09:09 -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 Wed, 28 Mar 2007 Volume: 11 Number: 278
Today's topics:
Re: Beginning OO help (Jamie)
Re: Beginning OO help <nomail@sorry.com>
Re: Beginning OO help <abigail@abigail.be>
Re: DBI MS SQL connection error <nospam@somewhere.com>
Heroes of the FAQ (was: Re: FAQ 8.4...) <please@nospam.net>
Re: Heroes of the FAQ <uri@stemsystems.com>
Re: Heroes of the FAQ <DJStunks@gmail.com>
Re: LWP hangs (Jamie)
Re: perl + script files from only one directory magne.nilsen@gmail.com
perl 5.8.8 with Template::Cache error <danparker276@yahoo.com>
Re: Perl package install dll problems <thepoet_nospam@arcor.de>
Re: Problem in the Perl script stu42j@gmail.com
Re: Problem in the Perl script <bik.mido@tiscalinet.it>
Re: Problem in the Perl script <thepoet_nospam@arcor.de>
Re: Problem in the Perl script <jurgenex@hotmail.com>
Re: Replacing characters in file <klaus03@gmail.com>
Re: Sweetest Accessor? <please@nospam.net>
Re: Sweetest Accessor? anno4000@radom.zrz.tu-berlin.de
What could potentially be wrong in this script? <foureightyeast@yahoo.com>
Re: What could potentially be wrong in this script? <klaus03@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Mar 2007 20:18:43 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: Beginning OO help
Message-Id: <Lc1175092406219240x89ae270@pong.podro.com>
In <eueamb$5vq$1@agate.berkeley.edu>,
Arvin Portlock <nomail@sorry.com> mentions:
>Unlearning is definitely necessary to learn this stuff. OO
>really is just grafted onto perl. It's plain old references
>used in clever ways with the help of bless.
Yep. :-)
I actually really like it this way, it's shed a little light
on other languages (C++, Java, PHP) From what I've seen, all
of them do this same trick in one way or another.
Usually they do the equiv. of my $self = shift() for you and
then re-arrange "$name" to "$self->name" thus making it appear
as if something special is happening, with "this" having special
meaning.
It's all just pointers to pools of data with a whole lot of
techno-speak designed to trick you into thinking something earth
shattering has happened.
Perl just makes it plain, which I've come to appreciate.
(Who'd have thunk perl would be *more readable* LOL)
Jamie
--
http://www.geniegate.com Custom web programming
Perl * Java * UNIX User Management Solutions
------------------------------
Date: Wed, 28 Mar 2007 15:42:08 -0800
From: Arvin Portlock <nomail@sorry.com>
Subject: Re: Beginning OO help
Message-Id: <euer04$hcs$1@agate.berkeley.edu>
Jamie wrote:
> In ,
> Arvin Portlock mentions:
>
> >Unlearning is definitely necessary to learn this stuff. OO
> >really is just grafted onto perl. It's plain old references
> >used in clever ways with the help of bless.
>
>
> Yep. :-)
I need help again! $obj = Package->new (args) works but I can't
get $obj = new Package (args) to work. The actual program is too
long to post here and I *tried* to reproduce it in a smaller simpler
program and failed.
Interestingly, if I simply declare the package name anywhere before
the current package then change it back, then the indirect method
works. In pseudo code, this does not work:
package MyPackage;
sub subname {
new OtherPackage (args);
}
package OtherPackage;
sub new {
print "OtherPackage here!\n";
}
But if I stick a bare package declaration at the top then the
indirect method works:
package OtherPackage;
package MyPackage;
sub subname {
new OtherPackage (args);
}
package OtherPackage;
sub new {
print "OtherPackage here!\n";
}
This reminds me very much of a forward declaration except it's a
package name!
Like I said, I cannot reproduce this problem in simpler code. But
can anyone tell me from the little I sketched above what might
be going on?
------------------------------
Date: 29 Mar 2007 00:04:06 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Beginning OO help
Message-Id: <slrnf0m0jm.imj.abigail@alexandra.abigail.be>
Arvin Portlock (nomail@sorry.com) wrote on MMMMCMLVII September MCMXCIII
in <URL:news:euer04$hcs$1@agate.berkeley.edu>:
.. Jamie wrote:
..
.. > In ,
.. > Arvin Portlock mentions:
.. >
.. > >Unlearning is definitely necessary to learn this stuff. OO
.. > >really is just grafted onto perl. It's plain old references
.. > >used in clever ways with the help of bless.
.. >
.. >
.. > Yep. :-)
..
.. I need help again! $obj = Package->new (args) works but I can't
.. get $obj = new Package (args) to work. The actual program is too
.. long to post here and I *tried* to reproduce it in a smaller simpler
.. program and failed.
..
.. Interestingly, if I simply declare the package name anywhere before
.. the current package then change it back, then the indirect method
.. works. In pseudo code, this does not work:
..
.. package MyPackage;
..
.. sub subname {
.. new OtherPackage (args);
.. }
..
.. package OtherPackage;
..
.. sub new {
.. print "OtherPackage here!\n";
.. }
..
.. But if I stick a bare package declaration at the top then the
.. indirect method works:
..
.. package OtherPackage;
.. package MyPackage;
..
.. sub subname {
.. new OtherPackage (args);
.. }
..
.. package OtherPackage;
..
.. sub new {
.. print "OtherPackage here!\n";
.. }
..
.. This reminds me very much of a forward declaration except it's a
.. package name!
..
.. Like I said, I cannot reproduce this problem in simpler code. But
.. can anyone tell me from the little I sketched above what might
.. be going on?
Yes.
This unexpected behavious is *exactly* why you shouldn't use the
indirect object method.
Stick to CLASS -> method ().
Abigail
--
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`;
------------------------------
Date: Wed, 28 Mar 2007 20:35:54 -0400
From: "Thrill5" <nospam@somewhere.com>
Subject: Re: DBI MS SQL connection error
Message-Id: <4NGdnSYe2rt3lJbbnZ2dnUVZ_oCmnZ2d@comcast.com>
You are using ODBC to connect to the database, did you create the DSN on the
new server?
Scott
"Saya" <vaqas@hotmail.com> wrote in message
news:1175091703.651421.35830@d57g2000hsg.googlegroups.com...
> Sorry for the mishap but $DSN actuallu looks like the below line. I
> was just experimenting when I removed 1304 from the servername.
> my $DSN = 'driver={SQL Server};Server=servername,
> 1304;database=dbname;Network=DBMSSOCN';
>
> On 28 Mar., 16:14, "Saya" <v...@hotmail.com> wrote:
>> Hi all,
>>
>> I have run into a problem with DBI connection to MS SQL server. I have
>> a script within which the below is executed:
>>
>> my $DSN = 'driver={SQL
>> Server};Server=servername;database=dbname;Network=DBMSSOCN';
>> my $dbh = DBI->connect("DBI:ODBC:$DSN",'dbuser', 'dbpass') or die
>> $DBI::errstr;
>>
>> my $sth = $dbh->prepare("Select categoryName, categoryID from
>> tblCategory Order By categoryName");
>>
>> $sth->execute;
>>
>> Now this script works on server1 and server2, but when I copy this
>> script to NewServer I get the following error:
>>
>> DBI connect('driver={SQL Server};Server=servername,
>> 1304;database=dbname;Network=
>> DBMSSOCN','dbname',...) failed: [Microsoft][ODBC SQL Server Driver]
>> [TCP/IP Sock
>> ets]General network error. Check your network documentation.
>> (SQL-08001)
>> [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]ConnectionOpen
>> (Connect()). (
>> SQL-01000)(DBD: db_login/SQLConnect err=-1) at E:\custom\perl
>> \Category.ipl line 16
>> Can't call method "prepare" on an undefined value at E:\custom\perl
>> \Category.ipl line 18.
>>
>> I can ping servername (the sql server) from the NewServer. The DBI
>> version on all the servers is the same (1.38). Also the perl version
>> is the same (v5.8.2 built for MSWin32-x86-multi).
>>
>> Does anyone have any hints/clues as what might be going wrong here.
>>
>> Any help will be greatly appreciated.
>>
>> regards
>> Saya
>
>
------------------------------
Date: Wed, 28 Mar 2007 12:39:49 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Heroes of the FAQ (was: Re: FAQ 8.4...)
Message-Id: <please-FEF39E.12394928032007@free.teranews.com>
In article <200320071109017211%brian.d.foy@gmail.com>,
brian d foy <brian.d.foy@gmail.com> wrote:
> Someone posts postive and righteous feedback about something I'm doing
> to help Perl, and Uri has to be a dick. I was feeling pretty good
> reading the first message, and now that's gone.
Well, let me see if I can put it back. I read a lot of FAQ posts; I find
them easier to digest than one big man page. There's a huge number of
fat docs on Perl and I read them for hours at a sitting but my peabrain
can only absorb so much, so fast. FAQ posts are great -- and Thank You!
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Wed, 28 Mar 2007 15:05:42 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Heroes of the FAQ
Message-Id: <x7wt11gmll.fsf@mail.sysarch.com>
>>>>> "XC" == Xiong Changnian <please@nospam.net> writes:
XC> In article <200320071109017211%brian.d.foy@gmail.com>,
XC> brian d foy <brian.d.foy@gmail.com> wrote:
>> Someone posts postive and righteous feedback about something I'm doing
>> to help Perl, and Uri has to be a dick. I was feeling pretty good
>> reading the first message, and now that's gone.
XC> Well, let me see if I can put it back. I read a lot of FAQ posts;
XC> I find them easier to digest than one big man page. There's a huge
XC> number of fat docs on Perl and I read them for hours at a sitting
XC> but my peabrain can only absorb so much, so fast. FAQ posts are
XC> great -- and Thank You!
and please note that the OP did post that he appreciated my comments to
him (emailed to him and he replied too). so he didn't perceive me as
being a dick so brian shouldn't either. brian and i know each other and
i hope he doesn't hold on to his bad mood too strongly. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 28 Mar 2007 15:16:52 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Heroes of the FAQ
Message-Id: <1175120212.211712.57910@y66g2000hsf.googlegroups.com>
On Mar 28, 2:05 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "XC" == Xiong Changnian <ple...@nospam.net> writes:
>
> XC> In article <200320071109017211%brian.d....@gmail.com>,
> XC> brian d foy <brian.d....@gmail.com> wrote:
>
> >> Someone posts postive and righteous feedback about something I'm doing
> >> to help Perl, and Uri has to be a dick. I was feeling pretty good
> >> reading the first message, and now that's gone.
>
> XC> Well, let me see if I can put it back. I read a lot of FAQ posts;
> XC> I find them easier to digest than one big man page. There's a huge
> XC> number of fat docs on Perl and I read them for hours at a sitting
> XC> but my peabrain can only absorb so much, so fast. FAQ posts are
> XC> great -- and Thank You!
>
> and please note that the OP did post that he appreciated my comments to
> him (emailed to him and he replied too). so he didn't perceive me as
> being a dick so brian shouldn't either. brian and i know each other and
> i hope he doesn't hold on to his bad mood too strongly. :)
FWIW, I didn't find your reply dick-ish either, Uri. But maybe that
means I'm a dick at heart :-)~
-jp
------------------------------
Date: Wed, 28 Mar 2007 21:45:20 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: LWP hangs
Message-Id: <Lc117509693724180x8d0e7c8@pong.podro.com>
In <1175088931.660927.71200@y66g2000hsf.googlegroups.com>,
yahavba@gmail.com mentions:
>On Mar 23, 3:32 am, nos...@geniegate.com (Jamie) wrote:
>i've tried your solution, and i see that the GET actually receive the
>correct URL. Afterwards, usually after fetching pages for 1-2 hours,
>it hangs. I tried to use "alarm" of 60 seconds (and mapped SIG{ALRM}
>to a subroutine of my own) but it didn't help, even ctrl-C doesn't
>kill the process - only Task Manager kill.
Does it hang on the exact URL each time? The ^C sort of baffles
me. With UNIX, I would probably examine the process and see if it's
taking a lot of memory (even then, ^C should work)
>I'm thinking of another way of running the GET commands in a seperate
>process or thread, and then if i can't see the results of the GET in
>the main process i will kill this thread, what do you think?
I suppose that would work, or, fork a new process for each URL, wait
and then process it, then fork another process each time you fetch
a URL. The hack being, keep resource allocations in a child proc where
they can be cleaned up on exit.
Long running processes are sort of famous for memory leaks. (usually they get
progressively slower and slower and eventually just don't work / memory errors)
The "right way" (IMO) is to find out whats happening though. (this can be
really hard to do. Data::Dumper combined with UNIVERSAL::DESTROY will sometimes
help, but.. it's just not easy)
Doing a "fork()" is a cheap way around the problem, when the child process
dies (at least with unix) the memory is reclaimed. It's more of a band-aid
than a solution though. (useful if you need to do something you /know/ will
take a lot of memory, it's the only way I know of to give it back when
done)
If it's practical, you might take just the part that GET's the URL, without
any other code, run that in a loop and see if it hangs. That might let
you know if it's a problem with LWP or the rest of your code is doing
something that doesn't cause a problem until the GET.
I don't know enough about windows to understand the rest of the story,
could be most anything.. sockets not being closed? handles? collecting
a boatload of UserAgent objects some place?
Jamie
--
http://www.geniegate.com Custom web programming
Perl * Java * UNIX User Management Solutions
------------------------------
Date: 28 Mar 2007 16:45:24 -0700
From: magne.nilsen@gmail.com
Subject: Re: perl + script files from only one directory
Message-Id: <1175125520.764741.302040@e65g2000hsc.googlegroups.com>
On Mar 28, 1:04 pm, Reinhard Pagitsch <r...@gmx.net> wrote:
> > Alternatively, is there any alternative
> > "compilers" that truly compiles absolutely all needed files into a
> > single EXE ?
>
> Yes PAR do it also. Use pp.bat to compile the .pl script and the used
> modules. The documentation can be found under /perl/html/bin/pp.html
>
In my win install there are no pp.bat nor pp.html...
Still, what I've seen from par is a single EXE that when run extracts
a complete perl environment and all files and sundirs to a temp area,
which is the opposite of what I am looking for... :(
Magne
------------------------------
Date: 28 Mar 2007 13:52:38 -0700
From: "danparker276@yahoo.com" <danparker276@yahoo.com>
Subject: perl 5.8.8 with Template::Cache error
Message-Id: <1175115158.055370.189700@y66g2000hsf.googlegroups.com>
We have installed perl 5.8.8 with Template module (installed/tested
without a glitch) and Template::Cache (installed with force: failed
test). Now whenever we use:
use Template::Cache;
we get:
"cache" is not defined in %Template::Constants::EXPORT_TAGS at /usr/
local/lib/perl5/site_perl/5.8.8/x86_64-linux/Template/Constants.pm
line 31
Can't continue after import errors at /usr/local/lib/perl5/site_perl/
5.8.8/Template/Cache.pm line 31
BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/
5.8.8/Template/Cache.pm line 31.
As far as I can see cache exists in /usr/local/lib/perl5/site_perl/
5.8.8/Template/Constants.pm (v. 1.14 of Constants.pm) but not in /usr/
local/lib/perl5/site_perl/5.8.8/x86_64-linux/Template/Constants.pm (v
2.74 of Constants.pm).
The latter version installed with the Template library, while the
first one seems to have come with Template::Cache. How do we fix this
version discrepancy? We need both Template and Template::Cache
installed.
Thanks-
Cindy
------------------------------
Date: Wed, 28 Mar 2007 20:25:45 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Perl package install dll problems
Message-Id: <460ab325$0$20296$9b4e6d93@newsspool3.arcor-online.net>
ChrisC schrieb:
> Hello,
>
> I'm using ActivePerl latest version and have installed the inline-0.44
> package on a Win XP box. Actually I tried this on 2 machines with
> same result.
>
> I'm now trying to install inline-java 0.52. I've set the environment
> variables PERL_INLINE_JAVA_J2SDK=c:
> \jdk1.5.0_11 and PERL_INLINE_JAVA_JNI=1 and the nmake seems to
> complete successfully.
>
> When I run 'nmake test' I get a bunch of errors with a dll file,
> however, the dll is located in the mentioned directories. I search of
> the dll dependency with Dependency Walker doesn't reveal any errors.
>
> A snippet of the errors from 'nmake test' is below. Any suggestions?
>
> Chris
>
> cd ..
> C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e"
> "test_harness(0, 'bl
> ib\lib', 'blib\arch')" t/*.t
> t/01_init..............Can't load JNI module. Did you build it at
> install time?
> Error: Can't load 'C:\inlinejava\Inline-Java-0.52\blib\arch/auto/
> Inline/Java/JNI
> /JNI.dll' for module Inline::Java::JNI: load_file:The specified module
> could not
> be found at C:/Perl/lib/DynaLoader.pm line 230.
[..rest snipped]
I can verify that. At first I thought it may be a binary compatibility
issue with Dynaloader from the ActiveState build, but I've tested it
now on self-compiled Perl-5.8.8 and blead, and both yield the same
result (also independent of the selected JNI version).
I think you should file a bug report for the module.
-Chris
------------------------------
Date: 28 Mar 2007 11:37:23 -0700
From: stu42j@gmail.com
Subject: Re: Problem in the Perl script
Message-Id: <1175107043.280078.193880@o5g2000hsb.googlegroups.com>
On Mar 28, 1:04 pm, "Rashmi Madhukara" <spuur...@gmail.com> wrote:
> Hello All,
>
> For some reason, I am not able to reason out why this piece of
> program is not working.
>
> my $k = 1.0;
> my $num = 3;
>
> for($k = 2.0; $k <= 10.0;)
> {
> $k = $k + 0.1;
> if($k == $num)
> {
> print "True\n";
> }
>
> }
>
> In the above program for some reason, it doesn't print True.
>
> Thanks in advance
> R
See: http://perldoc.perl.org/perlfaq4.html#Data%3a-Numbers
You'll probably want to multiply everything by 10 to keep them
integers.
------------------------------
Date: Wed, 28 Mar 2007 20:51:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Problem in the Perl script
Message-Id: <0pdl03lalt68dr09elk7up35danvm3jkkj@4ax.com>
On 28 Mar 2007 11:04:45 -0700, "Rashmi Madhukara" <spuurthi@gmail.com>
wrote:
>Subject: Problem in the Perl script
Which one? How 'bout putting the subject of your post in the Subject?
>For some reason, I am not able to reason out why this piece of
>program is not working.
How is it failing to work? What do you expect it to do?
>my $k = 1.0;
>my $num = 3;
>
>
>for($k = 2.0; $k <= 10.0;)
I would put the increment in the C-style for loop, if you have to use
such a loop, unless really needed to do otherwise.
>{
> $k = $k + 0.1;
$k+=0.1;
> if($k == $num)
perldoc -q decimals
> {
> print "True\n";
> }
>}
>
>In the above program for some reason, it doesn't print True.
#!/usr/bin/perl
use strict;
use warnings;
my $num=3;
my $epsilon=1e-5;
for (my $k=2; $k<=10; $k+=0.1) {
print "True\n" if abs($k-$num) < $epsilon;
}
__END__
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: Wed, 28 Mar 2007 21:03:05 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Problem in the Perl script
Message-Id: <460abbe6$0$20291$9b4e6d93@newsspool3.arcor-online.net>
Rashmi Madhukara wrote:
> Hello All,
>
> For some reason, I am not able to reason out why this piece of
> program is not working.
>
> my $k = 1.0;
> my $num = 3;
>
>
> for($k = 2.0; $k <= 10.0;)
> {
> $k = $k + 0.1;
> if($k == $num)
> {
> print "True\n";
> }
> }
>
> In the above program for some reason, it doesn't print True.
Welcome to the wonderful world of floating point numbers.
The trouble with those is that they aren't always exactly
what you expect them to be.
You might have seen that if you had printed out the value
in $k, which would have looked like
...
8.09999999999999
8.19999999999999
8.29999999999999
8.39999999999999
8.49999999999999
8.59999999999999
...
This is due to the way floating point numbers are stored
internally, and a lot has already been written about that.
The safest (and easyest) way to go about it would, for your
example, be to stay in the integer range for the loop itself
and only divide it down if neccessary:
my $k = 10;
my $num = 30;
for($k = 20; $k <= 100 ) {
$k += 1;
if( $k == $num ) {
print "True\n";
do_something_with( $k / 10 );
}
Note that "tricks" like that only work as long there is
only a little addition or substraction involved.
In your example you could also have said something like
if( sprintf("%0.2f", $k) eq sprintf("%0.2f", $num) )
which would have been safe in the range you are operating in.
But here's a little example that illustrates the generic problem:
-----------------------------------------------------------------
my $a = 0.1;
for(1..18) {
$a = func($_,$a);
}
sub func {
my $rounds = shift;
my $b = shift() ** 10 * 1000000000;
printf "After %0.2i rounds: %0.20f$/", $rounds, $b;
return $b;
}
-----------------------------------------------------------------
And the result talks for itself:
After 01 rounds: 0.10000000000000006000
After 02 rounds: 0.10000000000000062000
After 03 rounds: 0.10000000000000615000
After 04 rounds: 0.10000000000006154000
After 05 rounds: 0.10000000000061540000
After 06 rounds: 0.10000000000615403000
After 07 rounds: 0.10000000006154028000
After 08 rounds: 0.10000000061540279000
After 09 rounds: 0.10000000615402807000
After 10 rounds: 0.10000006154029775000
After 11 rounds: 0.10000061540468176000
After 12 rounds: 0.10000615421724574000
After 13 rounds: 0.10006155921873015000
After 14 rounds: 0.10061730028152584000
After 15 rounds: 0.10634733311122704000
After 16 rounds: 0.18504017693909758000
After 17 rounds: 47.06091322044940000000
After 18 rounds: 53284820164486796000000000.00000000000000000000
If you are in danger of encountering such situations, you might
want to look at Math::BigFloat.
-Chris
------------------------------
Date: Wed, 28 Mar 2007 21:58:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Problem in the Perl script
Message-Id: <UxBOh.4233$5E3.2419@trndny01>
Rashmi Madhukara wrote:
> Hello All,
>
> For some reason, I am not able to reason out why this piece of
> program is not working.
>
> my $k = 1.0;
> my $num = 3;
>
>
> for($k = 2.0; $k <= 10.0;)
> {
> $k = $k + 0.1;
> if($k == $num)
> {
> print "True\n";
> }
> }
>
> In the above program for some reason, it doesn't print True.
Trivial. You simply missed the first commandment of Computer Numerics.
"Thou shalt not use equal on floating point numbers"
For a 5 second overview about why that is a bad idea see the FAQ 'perldoc -q
999'. For more in-depth explanation see any basic introductory book into
computer numerics, chapter 1.
jue
------------------------------
Date: 28 Mar 2007 17:55:50 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: Replacing characters in file
Message-Id: <1175129750.020929.139420@y80g2000hsf.googlegroups.com>
On Mar 28, 8:31 am, Anony-mouse <anony-mo...@hole.in.the.wall.com>
wrote:
> Many thanks to Klaus and a couple of others who actually tried to help
> me with this problem by posting sensible replies,
All replies to your problem so far were sensible.
> but I now give up wasting time with Perl...
Don't hurt yourself.
> ...and this newsgroup.
Well, that's your opinion, but I would suggest at least that you read
this newsgroup from time to time (I suggest twice a week ?). One never
knows, maybe a satisfactory reply to your problem will be posted
later.
--
Klaus
------------------------------
Date: Wed, 28 Mar 2007 12:14:17 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: Sweetest Accessor?
Message-Id: <please-92B9C8.12141728032007@free.teranews.com>
In article <56ut5uF2ammm2U1@mid.dfncis.de>,
anno4000@radom.zrz.tu-berlin.de wrote:
> Many fields
> take values that happen to be false...
Well, yes; depends on your application. The stuff I'm doing now, this
doesn't usually come up. I make it *not* come up.
Please remember this is all a learning project for me; I'm going in
directions that have nothing to do with getting-the-job-done. With my
background, Perl is a novel and exciting language with amazingly
succinct ways of doing things. I'm pushing the edges of that as far as
possible.
Just to put a little contrast on that, I'm also designing, for the
benefit of some of my students, a set of relay logic gates; I've got up
to the full adder. This has been done before, of course, but perhaps not
with my particular design restrictions: all lines high or low, nothing
open or float; all coils grounded at one end. The intent is to make the
circuits 74CXX compatible and the most fundamental operations of a
binary digital computer as transparent as possible to the student
without sacrificing rigor. Obviously, I could get-the-job-done a lot
more easily.
Sorry if I seem to be banging my head deliberately against the wall.
Xiong wrote:
> > I particularly don't
> > care for mixing shift and @_ in the same sub -- visually.
>
> Why?
I'd like to respond to your question but I'm not sure how; it's just a
stylistic or gut feeling. For complex subs, I like the idiom of shifting
all the params into my variables; it puts a nice little self-documenting
declaration block up top. Now that I've been fooling around awhile, I'm
starting to see the limitations and inefficiencies in this and I'm
trying things the other way. One bone I have to pick with @_ is that it
allows me to clobber the actual param, which I generally don't want to
do. Also, after a lifetime of subscripting, I'm straining now to avoid
it. On the other hand, there are elegant @_ and $_[$n] approaches.
If it makes me look like a more reasonable person, my generic new shifts
for the class, then passes @_ to init.
> > "WARNING: Lvalue subroutines are still experimental and the
> > implementation may change in future versions of Perl."
>
> I'm not much worried by that. There seems to be little ongoing
> discussion of lvalue subs. I think they are here to stay.
Well, I *really* appreciate that assurance. I'm going to take your
comment as a license to go hog wild. The lvalue accessor you posted may
well be the shortest distance between two points -- and looks good in
the calling context. Throw in prototypes and a little overloading and I
can imagine writing some lucid code in the caller. Now, if I could only
figure out how to get rid of those superfluous commas....
Of course, it's all fake and heaven help the intrepid who use my modules
without reading the docs. But then, I don't expect my stuff to be on
CPAN any time soon.
Thanks again.
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 28 Mar 2007 22:06:36 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Sweetest Accessor?
Message-Id: <57077cF2aa31qU1@mid.dfncis.de>
Xiong Changnian <please@nospam.net> wrote in comp.lang.perl.misc:
> In article <56ut5uF2ammm2U1@mid.dfncis.de>,
> anno4000@radom.zrz.tu-berlin.de wrote:
>
> > Many fields
> > take values that happen to be false...
>
> Well, yes; depends on your application. The stuff I'm doing now, this
> doesn't usually come up. I make it *not* come up.
Well, your question came around as being about the style of general-
purpose accessors. I would not recommend a general-purpose accessor
that doesn't transfer certain values.
[snip]
> > > I particularly don't
> > > care for mixing shift and @_ in the same sub -- visually.
> >
> > Why?
>
> I'd like to respond to your question but I'm not sure how; it's just a
> stylistic or gut feeling. For complex subs, I like the idiom of shifting
> all the params into my variables; it puts a nice little self-documenting
> declaration block up top.
That isn't tied to shifting. The most self-documenting way of
parameter assignment would have to be:
my ( $name, $age, $occupation) = @_;
Shifting parameters off @_ is done for various reasons:
- You want to deal with each parameter individually before you
enter the body of the sub
my $name = shift || 'anonymous';
my $age= shift || 0;
my $occupation = $default_occupation[ $age];
- You want to get things out of the way and deal with the
remaining arguments uniformly
my $mode = shift;
for ( @_ ) { # ...
- In method calls, you shift off the invocant (class or object)
to make the content of @_ conform to the parameters given at
the call site;
$obj->meth( $name, $age, $occupation);
# corresponds to
my $obj = shift;
my ( $name, $age, $occupation) = @_;
> Now that I've been fooling around awhile, I'm
> starting to see the limitations and inefficiencies in this and I'm
> trying things the other way. One bone I have to pick with @_ is that it
> allows me to clobber the actual param, which I generally don't want to
> do. Also, after a lifetime of subscripting, I'm straining now to avoid
> it. On the other hand, there are elegant @_ and $_[$n] approaches.
These are usually restricted to small (one-line) subs. If anything
substantial goes on in the sub body, assignment of parameters to
named variables is the norm. Unless you *want* to change an argument,
or do other things that don't work on a copy.
BTW, shift() as such doesn't stop you from changing a parameter.
"
> If it makes me look like a more reasonable person, my generic new shifts
> for the class, then passes @_ to init.
Right, that's one of the cases I mentioned. And congratulations for
providing a separate initializer. It's all too often forgotten.
[snip lvalue, except]
> the calling context. Throw in prototypes and a little overloading and I
> can imagine writing some lucid code in the caller. Now, if I could only
You can't throw prototypes into an OO design. Prototypes are ignored
in method calls. In general, prototypes appear to introduce more
problems than they solve. It is true that they let you (sometimes)
design a particularly intuitive interface. Restrict prototypes to
such cases, don't use them as a matter of course.
Overloading goes a much longer way in the direction of intuitive
interfaces, but is also not without problems. In a general-purpose
class the user should be able to opt out of overloading.
Anno
------------------------------
Date: 28 Mar 2007 16:36:58 -0700
From: "Chris" <foureightyeast@yahoo.com>
Subject: What could potentially be wrong in this script?
Message-Id: <1175125018.580900.182280@p77g2000hsh.googlegroups.com>
I am writing a Perl script to check that dependency files exist that
are included in definition files that we have. However, I am getting
a completely unexplainable problem. For one specific file only, the
algorithm I have doesn't seem to work, or at least the string that is
getting saved from the regex is somehow not working properly with
certain Perl calls. The format of the strings is the same in every
file and in this one in particular, I have even modified the line,
moved it around, etc, etc. I am basically going through each file,
opening it, and then based on the type of file, saving a regex to
use. In one case, "^#tagdef\\s*(.*)" and in the other "^#include\
\s*(.*)" (they are saved off in variables. As I read each line of the
file, I am searching for the currently switched on regex, and then
using $1 to see what I have in the (), which is the file I want to
search for. This file is saved in a list of files that I gather (and
this file is in the list, I've printed and see it is there). I do a
foreach() on this file list, and then use index(fileInlist, $1) != -1
to indicate I have found the file. However, for only one specific
file, this doesn't work. What is even stranger is, if I print "$1\n",
the file prints just fine. But, if I do something like print "$1 after
\n", the whole output is messed up. If I print "before $1\n", nothing
prints at all. If I print "before $1 after\n", only after prints.
Here is a cut-paste of my script:
#!/usr/bin/perl -w
use lib "./scripts/perl/FILES-1.0";
use strict;
use Files::FileModules;
use Cwd;
my $boxPath = $ARGV[0];
my $myPath = "path";
my $startingDir = getcwd;
my @filePostfix = ("\.def\$", "\.cfg\$");
chdir("$boxPath/$myPath");
my @myFiles = FindAllFiles(@filePostfix, "./");
my @myFileCopy = @myFiles;
my $DEFILE = 0;
my $CFGFILE = 1;
foreach my $files (@myFiles)
{
my $searchTag = " ";
if(index($files, 'imgGame') != -1)
{
next;
}
open FILEHANDLE, "< $files" or die "Can't open $files\n";
print "\nIn File $files\n";
if($files =~ /\.def$/)
{
$searchTag = "^#include\\s*(.*)";
}
elsif($files =~ /\.cfg$/)
{
$searchTag = "^#tagdef\\s*(.*)";
}
while(<FILEHANDLE>)
{
if($_ =~ /$searchTag/)
{
my $findThis = $1;
my $foundFile = 0;
print "\nSearching for $findThis\n";
foreach my $thing (@myFileCopy)
{
if(index($thing, 'imgGame') != -1)
{
next;
}
if(index($thing, $findThis) != -1)
{
print "\nFound dependency: $findThis\n";
$foundFile = 1;
last;
}
}
die "Did not find: $findThis in $files\n" if !$foundFile;
}
}
close FILEHANDLE;
}
The index call isn't working on this bizarre string. However, if I do
things like length() on it, it shows the correct length, but other
calls, even the die call at the end, can't print it out. Only if it
is printed by itself with nothing else does it even print out.
------------------------------
Date: 28 Mar 2007 17:33:16 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: What could potentially be wrong in this script?
Message-Id: <1175128396.875091.40270@o5g2000hsb.googlegroups.com>
On Mar 29, 1:36 am, "Chris" <foureightye...@yahoo.com> wrote:
[snip]
> if I print "$1\n",
> the file prints just fine. But, if I do something like print "$1 after
> \n", the whole output is messed up. If I print "before $1\n", nothing
> prints at all. If I print "before $1 after\n", only after prints.
not really sure, but could be a rogue "\r" in $1,
try dumping out the content in hex: print unpack('H*', $1);
--
Klaus
------------------------------
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 V11 Issue 278
**************************************