[22285] in Perl-Users-Digest
Perl-Users Digest, Issue: 4506 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 4 00:13:14 2003
Date: Mon, 3 Feb 2003 21:09:28 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 3 Feb 2003 Volume: 10 Number: 4506
Today's topics:
100 levels deep redux. <rdsmith@sedona.intel.com>
Re: 100 levels deep redux. <goldbb2@earthlink.net>
16 bit application (Scott)
ANNOUNCE: Authen::Krb5::Simple 0.30 <damien.stuart@usi.net>
Re: APL's relation to perl <goldbb2@earthlink.net>
Aren't there any functions in perl similar to print_r i (Makoto)
Re: Aren't there any functions in perl similar to print <tassilo.parseval@post.rwth-aachen.de>
Re: Aren't there any functions in perl similar to print <bart.lateur@pandora.be>
Re: Aren't there any functions in perl similar to print (Tad McClellan)
Re: Aren't there any functions in perl similar to print <ethan@draupnir.gso.saic.com>
Attachments show in body, but only with Kmail (Robert)
Build my own perl html help docs <fma@doe.carleton.ca>
Re: Build my own perl html help docs <bwalton@rochester.rr.com>
Re: Build my own perl html help docs <fma@doe.carleton.ca>
Re: byte array in perl, how? pack, unpack? java to perl <nobull@mail.com>
Re: byte array in perl, how? pack, unpack? java to perl (Lee Goddard)
Class::Struct and hash members <shanem@nospam.ll.mit.edu>
Re: Class::Struct and hash members (Tad McClellan)
comp.lang.perl does not officially exist - was Re: perl <flavell@mail.cern.ch>
Converting C code to perl but the results are not the s <mothra@nowhereatall.com>
Re: Converting C code to perl but the results are not t (Ben Morrow)
Re: Converting C code to perl but the results are not t ctcgag@hotmail.com
Re: Converting C code to perl but the results are not t <mothra@nowhereatall.com>
Re: Converting C code to perl but the results are not t <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 03 Feb 2003 17:06:54 -0700
From: Ron Smith <rdsmith@sedona.intel.com>
Subject: 100 levels deep redux.
Message-Id: <3E3F041E.DAA595BF@sedona.intel.com>
I'm still having the classic 100 levels deep issue when using the
debugger.
For example:
#!/usr/pkgs/perl/5.6.1/bin/perl -d
no warnings 'recursion';
my $level=0;
my $unwind;
sub recurs {
print "level $level\n";
$unwind=1 if ($level++ == 100);
if ($unwind) {return} else {recurs()}
}
recurs();
die "we are done";
Notice if you run this, when you step THROUGH the recurs() call, it
should go 100 levels deep and then start to return. However, what it
really does is:
...
level 97
level 98
main::recurs(test.pl:9): print "level $level\n";
100 levels deep in subroutine calls!
DB<1>
OK, yes, I *did* do a google search (so have the "no warnings
'recursion';" line). Also in this trivial example a single "c"ontinue
will step through the problem and it will return. However, in the
general case, this is not practical. For example, suppose that the call
stack is 1,000 instead of 100? Notice that I am not using the '-w'
switch so I am not asking perl to warn me when there *might* be a
problem. Notice also that this happens only in the debugger.
What I need for the debugger to do for me is ignore this error (and
impeding progress is not a warning, it is an error...) and allow me to
debug my *actual* problem. "Do me a favor and don't do me any favors."
I have a case where it is natural for the recursion depth to be large
(hundreds, and yes, its normal and don't lecture me about recursion,
please), and trying to work around this is destroying my "c" key as well
as my patience. (Particularly because I have as yet to get to where it
goes beyond this error and I'm getting frustrated.)
Thanks
------------------------------
Date: Mon, 03 Feb 2003 19:35:01 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: 100 levels deep redux.
Message-Id: <3E3F0AB5.4D8FEDC4@earthlink.net>
Ron Smith wrote:
>
> I'm still having the classic 100 levels deep issue when using the
> debugger.
>
> For example:
>
> #!/usr/pkgs/perl/5.6.1/bin/perl -d
>
> no warnings 'recursion';
>
> my $level=0;
> my $unwind;
> sub recurs {
> print "level $level\n";
> $unwind=1 if ($level++ == 100);
> if ($unwind) {return} else {recurs()}
> }
> recurs();
> die "we are done";
Try changing the last line of the sub to:
if ($unwind) {return} else {goto &recurs}
Note that this is only a reasonable solution if the recursive call is
the last thing that the subroutine does. If you need to do something
like "recurse(); do_something_else()", then goto &subname isn't going to
be what you want. In addition, if the sub being called examines @_,
then you have to do "@_ = ...arguments...; goto &subname", instead of
merely doing "subname(...arguments...);" ... well, unless @_ for the
called subroutine is going to be the same as @_ in the calling sub.
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: 3 Feb 2003 20:56:17 -0800
From: myhvac@hotmail.com (Scott)
Subject: 16 bit application
Message-Id: <35ff4733.0302032056.5c32783@posting.google.com>
Can Perl interact with a 16 bit application? I have a company where
their software is written in a visual basic 16 bit program and I want
to develop for them a html interface using Perl.
------------------------------
Date: Sun, 2 Feb 2003 13:24:29 -0500
From: "Damien Stuart" <damien.stuart@usi.net>
Subject: ANNOUNCE: Authen::Krb5::Simple 0.30
Message-Id: <3e3ebc0b$1_2@news.teranews.com>
Authen::Krb5::Simple 0.30 is immediatly available from CPAN.
Authen::Krb5::Simple is a Perl module that uses the local system's Kerberos
5 libs to provide a simple mechanism for authenticating a username/password
against a Kerberos 5 server from within a Perl script. It also works with
Microsoft Active Directory Servers (configured to accept Kerberos 5 client
requests).
This module does require valid Kerberos 5 libraries and headers...
=====
NAME
Authen::Krb5::Simple - Basic user authentication using Kerberos 5
SYNOPSIS
use Authen::Krb5::Simple;
my $krb = Authen::Krb5::Simple->new([realm => 'MY.KRB.REALM']);
# Authenticate a user.
#
my $authen = $krb->authenticate($user, $password);
unless($authen) {
my $errmsg = $krb->errstr();
die "User: $user authentication failed: $errmsg\n";
}
# Get the current default realm.
#
my $realm = $krb->realm();
# Set the current realm
#
$krb->realm('MY.NEW.REALM');
DESCRIPTION
The "Authen::Krb5::Simple" module provides a means to authenticate a
user/password using Kerberos 5 protocol. The module's authenticate
function takes a username (or user@kerberos_realm) and a password,
and
authenticates that user using the local Kerberos 5 installation. It
was initially created to allow perl scripts to perform authentication
against a Microsoft Active Directory (AD) server that was configured
to
accept Kerberos client requests.
It is important to note: This module only performs simple authentica-
tion. It does not get, grant, use, or retain any kerberos tickets.
It
will check use credentials against the Kerberos server (as configured
on the local system) each time the authenticate method is called.
CONSTRUCTOR
new
The new method creates the Authen::Krb5::Simple object. It can
take an optional argument hash. At present the only recognized
argument is "realm".
If no realm is specified, the default realm for the local host
will
be assumed. Once set, the specified realm will be used for all
subsequent authentication calls. The realm can be changed using
the realm function (see below).
Examples:
Using the default realm:
my $krb = Authen::Krb5::Simple->new();
specifying a realm:
my $krb = Authen::Krb5::Simple->new(realm =>
'another.realm.net');
METHODS
authenticate($user[@realm], $password)
the authenticate method takes the user (or user@realm) and a
pass-
word, and uses kerberos 5 (the local systems installation) to
authenticate the user.
if the user/password is good, authenticate will return a true
value. Otherwise, a false value is returned and the error code
is
stored in the object.
if($krb->authenticate($user, $pw)) {
print "$user authentication successful\n";
} else {
print "$user authentication failed\n";
}
realm([NEW.REALM])
The realm method is used to set or get the current default realm.
If an argument is passed to this method, the default realm is set
to its value. If no argument is supplied, the current realm is
returned.
errstr
The errstr method will return the error message from the most
recent authentication call.
errcode
The errstr method will return the krb5 error code from the most
recent authentication call. This value will not be very useful.
Use the errstr method to get a meaningful error message.
BUGS
This version of Authen::Krb5::Simple does not support empty
passwords.
If you pass an empty string ('') as a password, authenticate will
print
a warning and return false, but there will be no error code or string
when errstr is called.
AUTHOR
Damien S. Stuart, <damien.stuart@usi.net>
SEE ALSO
perl, Kerberos5 documentation.
------------------------------
Date: Mon, 03 Feb 2003 17:53:19 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: APL's relation to perl
Message-Id: <3E3EF2DF.43D36D04@earthlink.net>
Michele Dondi wrote:
>
> On Sun, 02 Feb 2003 22:13:38 -0500, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
[snip]
> >It does not operate on a list of 'pair' objects (such as the things
> >constructed by perl6's "=>" operator). Err, well, it could, but it
>
> BTW: will "=>" operator be associative and thus enable to build
> triples, etc.?
I've no idea. Ask Larry.
> >Not to mention that one would likely lose the aliasing effect that
> >perl automatically provides when iterating over a list with
> >foreach().
>
> Sorry for my dumb question, but... are you referring to the automatic
> variable "$_"?
You get an aliasing effect regardless of whether you use $_ or some
other variable name.
my @foo = (1, 2, 3);
foreach my $x (@foo) { $x *= 2 }
print @foo; # prints 246
If @foo was an array of pairs, and iterated over those pairs, as in:
foreach my $pair (@foo) { my ($x, $y) = @$pair; ...stuff... }
, then altering $x and $y won't alter the @foo array.
> If so, then this doesn't seem a major concern: one
> array automatic variable might be used instead (or along as), to be
> set with the n entries of a n-tuple (if a n-tuple type will exist,
> considering a scalar as 1-tuple).
>
> >You do realize that in perl6, all of perl's types will be objects?
>
> All I know about perl6 I'm learning from this thread (and a few
> others): incidentally I thank you very much for the provided
> information - I know that I might find them on my own, OTOH it's nicer
> to gather them in an informal discussion.
Read these:
http://dev.perl.org/perl6/apocalypse/1
http://dev.perl.org/perl6/apocalypse/2
http://dev.perl.org/perl6/exegesis/2
http://dev.perl.org/perl6/apocalypse/3
http://dev.perl.org/perl6/exegesis/3
http://dev.perl.org/perl6/apocalypse/4
http://www.perl.com/pub/a/2002/04/01/exegesis4.html
http://dev.perl.org/perl6/apocalypse/5
http://dev.perl.org/perl6/exegesis/5
http://dev.perl.org/perl6/apocalypse/6
(no, I've no idea why exegenesis 4 wasn't on deve.perl.org)
> That all of perl's types will be objects is not too surprising after
> all: AFAIK it's a common trend in modern languages...
>
> >Alternatively, consider that perl6 programmers will probably be able
> >to create their own binary operators... So, one could create an
> > '(x)' operator as follows:
> >
> > my sub operator:(x) is prec(\&operator:+) (@a, @b) {
> > map { my $x = $_; map { $x, $_ } @b } @a;
>
> This would be great in any case!! I wonder, just for curiosity, to
> what extent this might be doable with perl5 and some OO+overloading
> trickery...
I suppose that you could create a 'vector' class, and bless your arrays
into it, and then overload the operations on that class, so that 'x' or
'*' produces a new arrayref, blessed into 'vector', but you wouldn't be
able to define *new* arrays...
The only way, in perl5, to make something like
my @crossprod = @a (x) @b;
work would be to create a source filter, which finds stuff like that
and changes the @a (x) @b into some_function(\@a, \@b).
> Do you happen to know if perl6 will support functional-languages-like
> features too?
Yes. Currying and such will be supported.
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: 3 Feb 2003 13:38:35 -0800
From: mictravel@yahoo.com (Makoto)
Subject: Aren't there any functions in perl similar to print_r in PHP?
Message-Id: <c00b7974.0302031338.17309853@posting.google.com>
Hello,
I'm looking for perl functions/mods similar to print_r() in PHP.
Although I can use perl "print" function to print out any variables/references,
I wonder if anybody knows there are any easier way in perl?
Bellow is my script to print out reference of Hash of Hash.
My problem is that I don't want to rely on my script to print out.
My goal is to use perl default script/mod (if any) to print out.
I do not concern how printout looks to be.
Thank you for your help in advance.
Makoto
#! /usr/bin/perl -w
use strict;
my %HoH = (
flintstones => {
lead => "fred",
pal => "barney",
},
jetsons => {
lead => "george",
wife => "jane",
"his boy" => "elroy",
},
simpsons => {
lead => "homer",
wife => "marge",
kid => "bart",
},
);
my $HoHref= \%HoH;
print "===Type: " . ref($HoHref) . "===\n";
eval {HoHref ($HoHref)};
sub HoHref{
my ($ref)=@_;
my ($key,$i,$j,$num)="";
my ($CRLF)="\r\n";
print "***Hash Of Hash***$CRLF";
print "\($CRLF";
foreach $i(keys(%$ref)) {
print " $i => {$CRLF";
for $j (keys %{$$ref{$i}}){
print "\t$j => \"$ref->{$i}{$j}\",$CRLF";
}
print " },$CRLF";
}
print "\)\;$CRLF";
}
------------------------------
Date: 3 Feb 2003 22:10:18 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Aren't there any functions in perl similar to print_r in PHP?
Message-Id: <b1mpca$6cl$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Makoto:
> I'm looking for perl functions/mods similar to print_r() in PHP.
> Although I can use perl "print" function to print out any
> variables/references, I wonder if anybody knows there are any easier
> way in perl?
[ code snipped ]
There is indeed no need to do it yourself. Use for instance
Data::Dumper:
use Data::Dumper;
print Dumper \%HoH; # always print a reference
A module with similar functionality (but whose output looks different)
is Data::Denter.
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: Mon, 03 Feb 2003 22:14:33 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Aren't there any functions in perl similar to print_r in PHP?
Message-Id: <g2qt3vokskpivin23vm3samso5ei09gv43@4ax.com>
Makoto wrote:
>I'm looking for perl functions/mods similar to print_r() in PHP.
What does print_r() do? Oh, I see:
<http://www.php.net/manual/en/function.print-r.php>. It's a lot like
var_dump(), isn't it?
Anyway, now I know what you're after: use the module Data::Dumper. It
comes with perl. An example similar to the one in the above PHP docs:
use Data::Dumper;
$Data::Dumper::Terse = 1;
$a = { 'a' => 'apple', 'b' => 'banana', 'c' => ['x','y','z'] };
print Dumper $a;
Result:
{
'a' => 'apple',
'b' => 'banana',
'c' => [
'x',
'y',
'z'
]
}
--
Bart.
------------------------------
Date: Mon, 3 Feb 2003 16:25:25 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Aren't there any functions in perl similar to print_r in PHP?
Message-Id: <slrnb3tr2l.4as.tadmc@magna.augustmail.com>
Makoto <mictravel@yahoo.com> wrote:
> I'm looking for perl functions/mods similar to print_r() in PHP.
use Data::Dumper;
> I wonder if anybody knows there are any easier way in perl?
> my %HoH = (
> flintstones => {
> lead => "fred",
> pal => "barney",
> },
> jetsons => {
> lead => "george",
> wife => "jane",
> "his boy" => "elroy",
> },
> simpsons => {
> lead => "homer",
> wife => "marge",
> kid => "bart",
> },
> );
print Dumper(\%HoH);
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 03 Feb 2003 14:36:12 -0800
From: Ethan Brown <ethan@draupnir.gso.saic.com>
Subject: Re: Aren't there any functions in perl similar to print_r in PHP?
Message-Id: <vr1y2pm1pf.fsf@draupnir.gso.saic.com>
>>>>> "Makoto" == Makoto <mictravel@yahoo.com> writes:
Makoto> Hello,
Makoto> I'm looking for perl functions/mods similar to print_r() in PHP.
Makoto> Although I can use perl "print" function to print out any variables/references,
Makoto> I wonder if anybody knows there are any easier way in perl?
Makoto> Bellow is my script to print out reference of Hash of Hash.
Makoto> My problem is that I don't want to rely on my script to print out.
Makoto> My goal is to use perl default script/mod (if any) to print out.
Makoto> I do not concern how printout looks to be.
Makoto> Thank you for your help in advance.
Makoto> Makoto
The Data::Dumper module provides convenient ways to print out
datastructures like the one you're describing.
--Ethan Brown
--In a band? Use http://www.WheresTheGig.com for free.
------------------------------
Date: 3 Feb 2003 16:50:29 -0800
From: robert@nrc.net (Robert)
Subject: Attachments show in body, but only with Kmail
Message-Id: <22d0e990.0302031650.66f5bc18@posting.google.com>
I have a PERL script that mails an attachment of a .csv file. It works
fine with Outlook, Outlook Express, Incredimail, Netscape, and The
Bat. However Kmail with Linux shows the attachment in the mail body,
NOT attaching it at all. Can someone tell me why that may be
happening? Any help is greatly appreciated.
Robert
------------------------------
Date: 3 Feb 2003 23:17:17 GMT
From: Shing-Fat Fred Ma <fma@doe.carleton.ca>
Subject: Build my own perl html help docs
Message-Id: <3E3EF878.97DDD9B0@doe.carleton.ca>
Hello,
Sorry if this shows up twice. Having troubles
posting from home, trying to do so from school.
I've been searching around for info
on how to replicate the info at perldoc.com
on my laptop, in hyperlinked html. It's
alot easier to find myself around compared
to commandline invocation of perldoc.
The documentation section of the FAQ doesn't
address this. From old postings, I should
have a perl documentation folder under
/usr/local/lib, but I don't. Instead, I have
a slew of pod files in /lib/perl5/5.6.1/pods.
From old postings, I cobbled the tcsh lines:
foreach podfile ( *.pod )
set basename = ` echo $podfile | sed -e 's/\.pod$//' `
perldoc -u $podfile | pod2html > ${basename}.html
end
I got lots of error messages about not being
able to resolve L<...>, where ... is (for example):
perlguts, perlapi, perlxs perlmod, etc.
But, I got html. When I open it, though, the files
are not crosslinked. For example, "perldoc perl"
has a table of man sections, which are hyperlinked
on the website documentation. They aren't in my
html files.
Is there a way to get the nice (and easy!) way to
get cross linked html files I find at perldoc.com?
I ftp'd to www.perldoc.com, but didn't file my way
to a nice directory where all the html files are
sitting. If I have to save each html file separately,
I won't bother.
Thanks.
Fred
P.S. I use perl 5.6.1, which comes with the most
recent cygwin 1.3.19-1, which I'm running on
Win2K.
--
Fred Ma, fma@doe.carleton.ca
Carleton University, Dept. of Electronics
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
------------------------------
Date: Tue, 04 Feb 2003 01:41:30 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Build my own perl html help docs
Message-Id: <3E3F1A3C.9060505@rochester.rr.com>
Shing-Fat Fred Ma wrote:
...
> Is there a way to get the nice (and easy!) way to
> get cross linked html files I find at perldoc.com?
...
> --
> Fred Ma, fma@doe.carleton.ca
...
One easy solution: On a Windoze machine somewhere, install the latest
version of ActiveState Perl. Use ppm to install the extra modules you
want docs of. Then copy the c:\perl\html file hierarchy to the machine
where you want the HTML docs.
--
Bob Walton
------------------------------
Date: 4 Feb 2003 03:34:52 GMT
From: Shing-Fat Fred Ma <fma@doe.carleton.ca>
To: bwalton@rochester.rr.com
Subject: Re: Build my own perl html help docs
Message-Id: <3E3F34D5.71DEE2CD@doe.carleton.ca>
Bob Walton wrote:
> Shing-Fat Fred Ma wrote:
>
> ...
> > Is there a way to get the nice (and easy!) way to
> > get cross linked html files I find at perldoc.com?
> ...
> > --
> > Fred Ma, fma@doe.carleton.ca
> ...
>
> One easy solution: On a Windoze machine somewhere, install the latest
> version of ActiveState Perl. Use ppm to install the extra modules you
> want docs of. Then copy the c:\perl\html file hierarchy to the machine
> where you want the HTML docs.
>
> --
> Bob Walton
Hi, Bob,
I'm a bit paranoid about installing something
other than generic Perl on my machine right
now. At this time, I want to stick with something
totally no-name. I may consider otherwise once
I have a solid grounding. My concern about
installing any software on my machine is that
I may not be aware of all the side effects, such
as search paths on *nix, or registry on the PC
(and I admit, I am very unfamiliar with PC, which
again is why I'm cautious). In your opinion,
how self contained is an Active State Perl?
Is it free?
Fred
--
Fred Ma, fma@doe.carleton.ca
Carleton University, Dept. of Electronics
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
------------------------------
Date: 03 Feb 2003 17:48:50 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: byte array in perl, how? pack, unpack? java to perl
Message-Id: <u9isw1xnjx.fsf@wcl-l.bham.ac.uk>
vientoloco@msn.com (vientoloco) top posts:
> How to send/receive the array of bytes through socket?
Please do not top-post - it is considered very rude.
Please do not treat Usenet as a "read the manual to me" service - it
is considered very rude.
Please try looking for the word "socket" in the table of contents of
the Perl manual (perldoc perltoc).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 3 Feb 2003 10:42:26 -0800
From: nospam@leegoddard.com (Lee Goddard)
Subject: Re: byte array in perl, how? pack, unpack? java to perl
Message-Id: <e0d7abe8.0302031042.4272b915@posting.google.com>
perldoc -q bit
perldoc perlfaq4
may help
------------------------------
Date: Mon, 03 Feb 2003 15:41:58 -0500
From: Shane McDaniel <shanem@nospam.ll.mit.edu>
Subject: Class::Struct and hash members
Message-Id: <3E3ED416.66DF73FE@nospam.ll.mit.edu>
I have the following code ( chopped down )
use Class::Struct;
struct Node =>
{
children =>'%';
};
my $parent = new Node->new();
my $child;
foreach $child ( keys ( $parent->children ) )
{...}
I get the following error on the foreach line
Type of arg 1 to keys must be hash (not subroutine entry ) at ..., near
") ) "
I'm screwing my references up somewhere but it looks fine. What am I
doing wrong? $parent->children should return a hash ref.
I've tried $parent->children() and %( $parent->children ) but neteither
work.
-shane
------------------------------
Date: Mon, 3 Feb 2003 16:06:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Class::Struct and hash members
Message-Id: <slrnb3tpur.44c.tadmc@magna.augustmail.com>
Shane McDaniel <shanem@nospam.ll.mit.edu> wrote:
> I have the following code ( chopped down )
^^^^^^^^^^^^^^^^^^^^^^^
I doubt that...
> use Class::Struct;
>
> struct Node =>
> {
> children =>'%';
^
^ syntax error
> };
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
> my $parent = new Node->new();
^^^ ^^^
^^^ ^^^ if 1 new is good, then 2 news must be better :-)
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
> foreach $child ( keys ( $parent->children ) )
> I get the following error on the foreach line
>
> Type of arg 1 to keys must be hash (not subroutine entry ) at ..., near
> ") ) "
> $parent->children should return a hash ref.
Right, so you need to DEreference the hash reference:
foreach $child ( keys %{$parent->children} )
> I've tried $parent->children() and %( $parent->children ) but neteither
> work.
See "Use Rule 1" in :
perldoc perlreftut
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 3 Feb 2003 20:32:33 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: comp.lang.perl does not officially exist - was Re: perlfaq4.pod
Message-Id: <Pine.LNX.4.53.0302032018150.8462@lxplus095.cern.ch>
On Feb 3, Anno Siegel inscribed on the eternal scroll:
> comp.lang.perl is dead.
Since this issue keeps on coming up, maybe it would be useful (even if
off-topic) to mention that the official list of "big eight" groups
gets posted (monthly, I think) on the news.groups group.
Look for the Subject: List of Big Eight Newsgroups , posted around the
middle of the month, normally. You'll see that it doesn't include
comp.lang.perl , for reasons that have been set out here recently
already.
f'ups set, as this is the wrong place to discuss such issues.
------------------------------
Date: Mon, 3 Feb 2003 12:51:29 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Converting C code to perl but the results are not the same
Message-Id: <3e3ed504@usenet.ugs.com>
Hi All,
I am tring to convert some c code to perl and am running into a
problem :-(
I do not understand what I am doing wrong. I execute the same code
in C and perl but the results are different. Can anyone explain
what I am doing wrong? And how to fix it?
Thanks
Mothra
**************c code******************
#define days_since_2000_Jan_0(y,m,d) \
(367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
main()
{
double da; /* Days since 2000 Jan 0.0 (negative before) */
da = days_since_2000_Jan_0(2003,02,03) + 0.5 - -122.3/360.0;
printf( "Day:%5.10f\n", da);
}
F:\scripts>test.exe
Day:1130.8397222222
*************perl code********************
#!/app/perl5.8.0/bin/perl
use strict;
use warnings;
my $year='2003';
my $month='02';
my $day = '03';
my $lon ='-122.3';
my $lat ='47.6';
my $d = days_since_2000_Jan_0($year,$month,$day) + 0.5 -$lon/360.0;
print $d ."\n";
sub days_since_2000_Jan_0 {
my ($y,$m,$d) = @_;
my $dl =
(367*($y)-((7*(($y)+((($m)+9)/12)))/4)+((275*($m))/9)+($d)-730530);
return $dl;
}
prints
F:\scripts>test.pl
1129.09666666672
------------------------------
Date: Mon, 3 Feb 2003 21:20:40 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Converting C code to perl but the results are not the same
Message-Id: <b1mmf8$9mm$1@wisteria.csv.warwick.ac.uk>
"Mothra" <mothra@nowhereatall.com> wrote:
>Hi All,
>
>I am tring to convert some c code to perl and am running into a
>problem :-(
>I do not understand what I am doing wrong. I execute the same code
>in C and perl but the results are different. Can anyone explain
>what I am doing wrong? And how to fix it?
>
>**************c code******************
>
<snip>
>
>F:\scripts>test.exe
>Day:1130.8397222222
>
>*************perl code********************
>
<snip>
>
>prints
>F:\scripts>test.pl
>1129.09666666672
I think the only problem you have here is that C and Perl are using slightly
different floating point representations. Those two numbers are pretty
close: I suspect the difference is just in where and when and how
intermediate rsults are rounded.
Ben
------------------------------
Date: 03 Feb 2003 21:48:52 GMT
From: ctcgag@hotmail.com
Subject: Re: Converting C code to perl but the results are not the same
Message-Id: <20030203164852.876$12@newsreader.com>
"Mothra" <mothra@nowhereatall.com> wrote:
> Hi All,
>
> I am tring to convert some c code to perl and am running into a
> problem :-(
> I do not understand what I am doing wrong. I execute the same code
> in C and perl but the results are different. Can anyone explain
> what I am doing wrong?
If both arguments to a division are integers, C does an integer
division, while Perl does a regular floating point divide.
> And how to fix it?
either use the int function in Perl wherever C is implicitly truncating,
or use the "use integer;" module (pragma?) in your subroutine.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Mon, 3 Feb 2003 13:52:14 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Converting C code to perl but the results are not the same
Message-Id: <3e3ee340$1@usenet.ugs.com>
Hi Ben,
"Ben Morrow" <mauzo@mimosa.csv.warwick.ac.uk> wrote in message
news:b1mmf8$9mm$1@wisteria.csv.warwick.ac.uk...
> "Mothra" <mothra@nowhereatall.com> wrote:
> >I am tring to convert some c code to perl and am running into a
> >problem :-(
> >I do not understand what I am doing wrong. I execute the same code
> >in C and perl but the results are different. Can anyone explain
> >what I am doing wrong? And how to fix it?
> >
> >**************c code******************
> >
> <snip>
> >
> >F:\scripts>test.exe
> >Day:1130.8397222222
> >
> >*************perl code********************
> >
> <snip>
> >
> >prints
> >F:\scripts>test.pl
> >1129.09666666672
>
> I think the only problem you have here is that C and Perl are using
slightly
> different floating point representations. Those two numbers are pretty
> close: I suspect the difference is just in where and when and how
> intermediate results are rounded.
>
Thanks for responding!
Yes, they are close however I need the percision of the c program.
I am the author of the Astro::Sunrise module and this work is for that
module.
It has been brought to my attention that the calculation are incorrect at
the highter latitudes (north/south poles) and this module was based on
c code from Paul Schlyter's web page.
Do you know of any way to get the 2 programs to agree?
Thanks
Mothra
------------------------------
Date: Mon, 03 Feb 2003 18:35:41 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Converting C code to perl but the results are not the same
Message-Id: <3E3EFCCD.CC65E2D@earthlink.net>
Mothra wrote:
[snip]
How about:
use Time::Local;
my $Jan_01_2000 =
timelocal( 0, 0, 0, 1, 1, 2000 );
my ($m, $d, $y) = (2, 3, 2003);
my $today =
timelocal( 0, 0, 0, $m, $d, $y );
my $longitude = -122.3;
my $lattitude = 47.6;
my $d = ($today - $Jan_01_2000) / (60*60*24);
$d += $longitude / 360 + 0.5;
print $d;
This produces 1156.16027777778, which significantly closer to the actual
number of days between the two dates than either of the two numbers that
your own two programs produced.
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
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 4506
***************************************