[22821] in Perl-Users-Digest
Perl-Users Digest, Issue: 5042 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 26 14:05:38 2003
Date: Mon, 26 May 2003 11: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 Mon, 26 May 2003 Volume: 10 Number: 5042
Today's topics:
Comparison returns unexpected results <marcjmims@hotmail.com>
Re: Help with errors. <mail@annuna.com>
Perl 5.6.1 and Oracle 8.1.7 (Tomasz)
Re: Perl 5.6.1 and Oracle 8.1.7 <mark_rogers@mac.com>
Re: Perl 5.6.1 and Oracle 8.1.7 <andy@andyh.co.uk>
Re: Perl Nightmare on OS X (Nick)
Re: Perl Nightmare on OS X <bwalton@rochester.rr.com>
Re: Perl Script to Caluclate Averages? <jamarier@yahoo.es>
Re: Perl Script to Caluclate Averages? <abigail@abigail.nl>
Re: Perl Script to Caluclate Averages? <abigail@abigail.nl>
Re: Perl Script to Caluclate Averages? (Spread Eagle)
Re: Perl Script to Caluclate Averages? <graham.drabble@lineone.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 26 May 2003 12:45:57 -0500
From: Marc Mims <marcjmims@hotmail.com>
Subject: Comparison returns unexpected results
Message-Id: <eIKcnV76jeVIz0-jXTWcqQ@comcast.com>
I wrote a simple script that works well in Perl 5.8.0 using
NetAddr::IP version 3.14. The same script run on Perl 5.6.1 with
NetAddr::IP version 3.07 returns unexpected results from a call to
'split'.
In Perl 5.8.0, the working case:
@subnet = NetAddr::IP->new('default')->split(1);
results in 2 subnets, 0.0.0.0/1 and 128.0.0.0/1, as expected. But the
same call with Perl 5.6.1 returns an empty array.
I tracked the problem down to lines 740 and 741 of NetAddr/IP.pm (the
first 'if' statement in sub splitref):
if (vec($self->{mask}, 0, $bits)
<= vec($mask, 0, $bits))
vec($self->{mask}, 0,$bits) evaluates to 0
vec($mask, 0, $bits) evaluates to 2147483648
This is true in both versions. However, the test fails in 5.6.1.
I can get the expected behavior by modifying the NetAddr::IP code and
adding some temporary variables:
my $x = vec($self->{mask}, 0, $bits);
my $y = vec($mask, 0, $bits);
if ( $x <= $y )
Obviously, I can resolve this problem with the ugly hack above, or I
can upgrade the target system to Perl 5.8.0. But I would rather
understand why this behaves differently than I expect. Can someone
help me fill this gap in my understanding of perl? Or is this a bug?
-Marc
------------------------------
Date: Mon, 26 May 2003 12:59:43 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Re: Help with errors.
Message-Id: <3ED2560F.2080200@annuna.com>
Bob Walton wrote:
> Joe Creaney wrote:
>
>> I have been working on my role playing game and I am getting errors I
>> can't explain. My two that are really stumping me are first why some
>> values won't print in certain packages the other why it won't perform
>> an if then operation. The first error I wrote a function to
>> generate. The is I have an array and I want to check for the first
>> open space defined by a space " " or the space being undef. If so I
>> want to something there. The first time I use the block it works but
>> if I come back to it it doesn't. I have use all the debugging tricks
>> I know and I can find no reason why I am getting these errors. The
>> program is long nearly 1,000 lines. I am beginning to believe there
>> is a problem with the compiler.
>>
>> The game is at my site www.annuna.com/perl5 and it is under simple RPG
>> 1.2 error.
>>
>> If I can't figure out why the program doesn't work I will have to drop
>> it and focus on learning C++. Once I get proficient enough I will try
>> to write this game in another language.
>>
>
> Just a suggestion: Have you considered using Perl's built-in debugger?
> It is started up like:
>
> perl -d script_name.pl
>
> You can easily set a breakpoint to a line or the name of a sub and trace
> through statement by statement to see exactly what is happening,
> printing the values of variables as you go. The "x" debugger command is
> particularly good at divulging the contents of complex objects like you
> have. Answers to questions like those you are asking above become
> obvious. For example, using the debugger for about 30 seconds:
>
> I note that in your sub error, $play->{bag}->[0] has three elements
> (sometimes -- sometimes, apparently randomly, [0] has two elements and
> [1] has two elements rather than one element, in which case it is
> [1]->[0] which has the blank name), the first of which contains a hash
> with a name consisting of a single space character and undefs for
> several other hash keys. That first array element is the source of the
> blank remainder of the line after the line starting with 0. It appears
> the source of that entry is line 377:
>
> killitem ($play);
>
> sub killitem sets the name to a single blank character.
>
> In regard to your question about variables not printing in certain
> packages: user-defined named Perl variables are by default "package
> globals" and are not available outside their package unless exported or
> referred to by their full name (package::variable_name). If you:
>
> use strict;
>
> and
>
> use warnings;
>
> you will be told about attempts to use variables which don't exist,
> along with many many other things. Let Perl help you by *always* using
> strict and warnings. Maybe
>
> use diagnostics;
>
> too, if you're new to Perl. This is particularly true for longer and
> more complicated programs like yours. Note that you were not using
> warnings because the shebang line in your program wasn't the first line
> of the program, and hence was just an ordinary comment. Also note that
> your program has *many many* places where strict fails and warnings
> gives warnings. Clean those up and see if in the process lots of
> problems don't go away.
>
> There are no known Perl compiler/interpreter problems which would
> generate symptoms such as you describe. I can assure you that the
> problems are something in your code, and that if you write similar code
> in other languages, you will still have similar problems. I doubt that
> anyone in the newsgroup will devote the time and energy needed to debug
> your code for you. But we will help if you get stuck on problems you
> can show in complete programs which anyone can copy/paste/execute
> without making up data, typing in game commands, etc, which illustrate
> the problem and are short and to the point, like no more than 20 lines.
>
> Good luck.
Thanks for the advice. I am starting to get a handle on what the
problems are. First I was treating an object which is a refrence like
it was a normal variable. Although there were two variables bointing to
the name of the objcet there was only one item stored in memory.
This debugging is very confusing. As far as my other errors, I am
going though my code to try to figure them out. It is tricky because
the functions work in the beginning but not later on.
I want to thank all the people who looked at my program and gave me
advice. I wish I knew better and more compact ways to try to write this
program.
This program is a learning exercise and If I ever get it to work righ a
good game.
------------------------------
Date: 26 May 2003 09:04:22 -0700
From: twronapl@yahoo.com (Tomasz)
Subject: Perl 5.6.1 and Oracle 8.1.7
Message-Id: <5979bec2.0305260804.7a04f8b1@posting.google.com>
Hello,
I've got a perl 5.6.1. I would like to connect to Oracle Database
8.1.7 on the remote machine, without installing Oracle Client on my
machine. I've installed DBI package, but there are problems with
DBD-Oracle - installation cannot find the ORACLE_HOME structure. I've
copied some folders to my machine (network, rdbms, lib) and it worked
till 'make test'. How can I connect with the remote machine?
Thanks a lot for any help
Tomasz Wrona
------------------------------
Date: Mon, 26 May 2003 12:34:40 -0500
From: Mark Rogers <mark_rogers@mac.com>
Subject: Re: Perl 5.6.1 and Oracle 8.1.7
Message-Id: <batj7g$eia$1@canopus.cc.umanitoba.ca>
I don't think you can.
Mark
Tomasz wrote:
> Hello,
>
> I've got a perl 5.6.1. I would like to connect to Oracle Database
> 8.1.7 on the remote machine, without installing Oracle Client on my
> machine. I've installed DBI package, but there are problems with
> DBD-Oracle - installation cannot find the ORACLE_HOME structure. I've
> copied some folders to my machine (network, rdbms, lib) and it worked
> till 'make test'. How can I connect with the remote machine?
>
> Thanks a lot for any help
>
> Tomasz Wrona
------------------------------
Date: Mon, 26 May 2003 18:49:22 +0100
From: Andy Hassall <andy@andyh.co.uk>
Subject: Re: Perl 5.6.1 and Oracle 8.1.7
Message-Id: <dfk4dvkvkotdrd7fs71pshkrd1noj9m24i@4ax.com>
On 26 May 2003 09:04:22 -0700, twronapl@yahoo.com (Tomasz) wrote:
>I've got a perl 5.6.1. I would like to connect to Oracle Database
>8.1.7 on the remote machine, without installing Oracle Client on my
>machine. I've installed DBI package, but there are problems with
>DBD-Oracle - installation cannot find the ORACLE_HOME structure. I've
>copied some folders to my machine (network, rdbms, lib)
Whilst you may be able to get it to work by hacking around copying files like
that, it's hardly a supported or reliable way of doing it.
Just install Oracle Client properly on the machine.
>and it worked
>till 'make test'. How can I connect with the remote machine?
If by some chance it is all actually compiled and working, then to get the
DBD::Oracle tests working against a remote machine you can set the
ORACLE_USERID environment variable to a connection string, e.g.
scott/tiger@remotedb.world before running the tests.
--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
------------------------------
Date: 26 May 2003 08:29:19 -0700
From: nick@tiger-marmalade.com (Nick)
Subject: Re: Perl Nightmare on OS X
Message-Id: <6a6938d0.0305260729.31131ca4@posting.google.com>
I understand how package variables work. I apologize -- I didn't
articulate my question very well. If I don't explicitly assign a
package to my variables, my scripts will not run. If I try:
$foo = "bar";
I receive the following when I try and run it:
Global symbol "$foo" requires explicit package name at ./foobar.pl
line 5.
I must assign $foo as $main::foo, even if I state
package main;
at the beginning of a script. I thought that is a package weren't
assigned, it was assumed it belonged to main. If that presumption is
correct, what can account for the behaviour I am getting, or am I way
off base?
Thanks,
Nick
Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3ED1801C.6070507@rochester.rr.com>...
> Nick wrote:
>
> > I believe I've found the answer. The problem lay in
> > /sw/lib/perl5/darwin/Storable.pm. Moving that to /tmp and rebuilding
> > via fink seems to have fixed the problem. One odd things, still --
> > why to package variables have to be declared as belonging to a
> > specific package, even if you want the to belong to main? For example,
> > the following results in compilation errors:
> >
> > $foo = 'bar';
> >
> > while this works:
> >
> > $main::foo = bar;
>
>
> Well, that's the whole point of packages. You want to be able to use
> someone's package without having to worry about stomping on the variable
> names the author chose to use in his/her package. Likewise, the package
> author doesn't want to have to work around whatever variables you might
> choose to use in your package main (as if he/she could ahead of time
> anyway). So all user-defined Perl variables exist by default in a given
> package. They can be accessed in other packages via constructions like
> $package_name::variable_name, as you have demonstrated above. And/or
> they can be exported. Package main is just another package -- about the
> only thing special about it is that it is the package you are in if you
> don't specify a package.
>
>
> ...
>
>
> HTH.
------------------------------
Date: Mon, 26 May 2003 17:43:51 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl Nightmare on OS X
Message-Id: <3ED2519B.60002@rochester.rr.com>
Nick wrote:
> I understand how package variables work. I apologize -- I didn't
> articulate my question very well. If I don't explicitly assign a
> package to my variables, my scripts will not run. If I try:
>
> $foo = "bar";
>
> I receive the following when I try and run it:
>
> Global symbol "$foo" requires explicit package name at ./foobar.pl
> line 5.
That's a message that results because your program includes the line:
use strict;
When use strict is in effect, you must declare all variables, typically
with the "my" or "our" functions, or you must specify the full name of
the variable. Even in package main. Package globals cannot be accessed
without the package name (using my or our makes the variable a lexical
variable, and it is no longer a package global). If you don't want that
behavior, omit "use strict". However, strict is very useful during
program development and debug, helping you to easily catch misspelled
variable names, etc. I recommend using strict (and warnings, of course,
and maybe diagnostics) during development and debug. Once a script is
done, it serves no purpose, and may be omitted.
>
> I must assign $foo as $main::foo, even if I state
>
> package main;
>
> at the beginning of a script. I thought that is a package weren't
> assigned, it was assumed it belonged to main. If that presumption is
> correct, what can account for the behaviour I am getting, or am I way
> off base?
...
> Nick
--
Bob Walton
------------------------------
Date: Mon, 26 May 2003 15:45:17 +0000 (UTC)
From: Javier M Mora <jamarier@yahoo.es>
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <batcqc$p5g$1@nsnmpen2-gest.nuria.telefonica-data.net>
En el artículo <20030526200825.26bd289a.thens@nospam.com>, Thens escribió:
> On 26 May 2003 11:30:43 GMT
> Abigail <abigail@abigail.nl> wrote:
>
>>
>>perl -nle'$;+=$_}{$_=$;/$.}{'
>>
>
> When I do a perldoc perlvar it says $; is "The subscript separator
> for multidimensional array emulation". Any special reasons for using
> this ??
>
> -Thens
>
Yes, it's to obfuscate B-)
>>
>>
>>Abigail
>>--
>># Count the number of lines; code doesn't match \w. Linux specific.
>>()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
>>$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`;
------------------------------
Date: 26 May 2003 15:59:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <slrnbd4ef0.co.abigail@alexandra.abigail.nl>
Abigail (abigail@abigail.nl) wrote on MMMDLV September MCMXCIII in
<URL:news:slrnbd3un3.kuj.abigail@alexandra.abigail.nl>:
:) Spread Eagle (redsky@virtualhosts.net) wrote on MMMDLV September MCMXCIII
:) in <URL:news:7059619f.0305252058.1f2faad4@posting.google.com>:
:) %% I'm trying to teach myself perl, and am just getting the basics down.
:) %% I want to write a script that would allow the user to enter a sequence
:) %% of numbers from the standard input, it would then calculate the
:) %% average of those numbers, then print that average on the standard
:) %% output. Can someone show mw a sample script for that? I keep getting
:) %% compile arrors and syntax errors.
:)
:)
:) perl -nle'$;+=$_}{$_=$;/$.}{'
That should of course be:
perl -ple'$;+=$_}{$_=$;/$.}{'
Abigail
--
perl -wlpe '}{*_=*.}{' file # Count the number of lines.
------------------------------
Date: 26 May 2003 16:01:22 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <slrnbd4eih.co.abigail@alexandra.abigail.nl>
Thens (thens@nospam.com) wrote on MMMDLV September MCMXCIII in
<URL:news:20030526200825.26bd289a.thens@nospam.com>:
^^ On 26 May 2003 11:30:43 GMT
^^ Abigail <abigail@abigail.nl> wrote:
^^
^^ >
^^ >perl -nle'$;+=$_}{$_=$;/$.}{'
^^ >
^^
^^ When I do a perldoc perlvar it says $; is "The subscript separator
^^ for multidimensional array emulation". Any special reasons for using
^^ this ??
Since I'm not using multidimensional array emulation, does it matter?
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;
------------------------------
Date: 26 May 2003 09:20:11 -0700
From: redsky@virtualhosts.net (Spread Eagle)
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <7059619f.0305260820.d97d8ec@posting.google.com>
sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnbd396q.gvn.sholden@flexal.cs.usyd.edu.au>...
> Post what you have (assumming it isn't too long, in which case shorten it
> first).
>
> Then people will be able to help, otherwise the homework smell is too strong.
> If it actually is homework and you just want it done for you then submit
> this:
No it's not homework. I'm 53 years old and don't have homework. I
came to computing in recent years, and part of computing is learning
code. I've learned a little about C and VB, and now I'm trying to
learn a little about Perl. I can always cut and paste scripts from
sites offering such but I want to have some understanding of them.
At this point I'm still trying to get a handle on the basics and a
program like the one I described seems to be a good little challenge.
I don't need an entire script, just a line or two of code that I can
understand, mainly the variable ($_ I assume) that holds the value
entered by the user and increments it with each subsequent number the
user enters, then a line that will divide the running total by "n" to
give a running average on the fly.
I played with the script you gave me and it doesn't work, at least
when I pasted it into a script file.
But let me ask you a few questions about it:
> undef $/;
I assume that's some kind of scaler declaration. What's its purpose?
> $_ = <>;
I understand that. It puts the keyboard entry into the variable $_
> s/^\s*//;
what is s/?
^ denotes the beginning of a string, right?
\s means whitespace, right?
* is multiplication?
what is //?
> s/\s*$//;
> $c = s/\s+/+/g + 1;
Please explain the right side. What is g?
> print eval($_)/$c,"\n";
what is eval? Does it have internal meaning to perl?
Thanks.
Spread Eagle
------------------------------
Date: Mon, 26 May 2003 18:21:36 +0100
From: Graham Drabble <graham.drabble@lineone.net>
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <Xns9387BAC50DCDEgrahamdrabblelineone@ID-77355.user.dfncis.de>
On 26 May 2003 redsky@virtualhosts.net (Spread Eagle) wrote in
news:7059619f.0305252058.1f2faad4@posting.google.com:
> I'm trying to teach myself perl, and am just getting the basics
> down. I want to write a script that would allow the user to enter
> a sequence of numbers from the standard input, it would then
> calculate the average of those numbers, then print that average on
> the standard output. Can someone show mw a sample script for
> that? I keep getting compile arrors and syntax errors.
This might help, it's not the shortest or most efficient method by a
long way but it should be pretty easy to follow.
use strict;
use warnings;
use diagnostics;
#Get Perl to help you.
print "Enter numbers to be averaged, ^Z to exit\n";
chomp(my @numbers = <>); # Get numbers from STDIN and remove newlines.
my $total=0;
$total +=$_ foreach @numbers; # Sum input
print 'The average is ' . $total / @numbers ."\n"
# Uses @numbers is scalar context which returns the number of elements
# in the array.
--
Graham Drabble
If you're interested in what goes on in other groups or want to find
an interesting group to read then check news.groups.reviews for what
others have to say or contribute a review for others to read.
------------------------------
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 5042
***************************************