[24093] in Perl-Users-Digest
Perl-Users Digest, Issue: 6287 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 22 00:05:41 2004
Date: Sun, 21 Mar 2004 21:05:05 -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 Sun, 21 Mar 2004 Volume: 10 Number: 6287
Today's topics:
Capturing errors from sqlplus (David)
Re: Capturing errors from sqlplus (Malcolm Dew-Jones)
Re: dollar sign and spaces from a string <tadmc@augustmail.com>
Re: file upload and STDIN <Joe.Smith@inwap.com>
Re: graph smoothing... moller@notvalid.se
Re: graph smoothing... <nospam@bigpond.com>
Re: graph smoothing... (Jim Keenan)
Re: installing CPAN module <kalinaubears@iinet.net.au>
perl 5.8.3 on windows XP eat an huge amount of memory? <sandrinotrepppalle@sandrino.it>
Re: perl 5.8.3 on windows XP eat an huge amount of memo <sandrinotrepppalle@sandrino.it>
Re: Problem installing Net::DNS <jwillmore@remove.adelphia.net>
Re: Question about scope. <mail@annuna.com>
Re: Redirect problem <Tigerhillsideremove@removenetscape.net>
Re: Redirect problem <Tigerhillsideremove@removenetscape.net>
Re: Redirect problem (David Efflandt)
scope again <mail@annuna.com>
Re: scope again <invalid-email@rochester.rr.com>
Re: scope again <krahnj@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Mar 2004 19:56:19 -0800
From: davidol@hushmail.com (David)
Subject: Capturing errors from sqlplus
Message-Id: <3bef037b.0403211956.e955cbe@posting.google.com>
I'm piping a bunch of insert statements through sqlplus (yes, I know I
should be using the DBI or sql*loader, unfortunately I can't either)
and I'm having trouble capturing errors when they happen.
For example, if I try and insert a row with a duplicate primary key, I
get this error on the terminal ...
ERROR at line 1:
ORA-00001: unique constraint (OPS$N450MAT.INTERFACE_PK) violated
The return code however is 0 ...
DEBUG: return code $? = 0
How can I capture sqlplus errors from within the script? An extract
of the code is below ...
Cheers,
David
open SQL, "| sqlplus -s $orauser/$orapass\@$oradb"
or die ("Can't open sqlplus for write: $!\n");
my $sql;
... generate insert statements ...
print SQL <<EOR;
$sql
commit;
exit
EOR
close SQL or warn ("Couldn't close sqlplus pipe: $!");
print "DEBUG: return code \$\? is $?\n";
------------------------------
Date: 21 Mar 2004 20:24:03 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Capturing errors from sqlplus
Message-Id: <405e6a63@news.victoria.tc.ca>
David (davidol@hushmail.com) wrote:
: I'm piping a bunch of insert statements through sqlplus (yes, I know I
: should be using the DBI or sql*loader, unfortunately I can't either)
: and I'm having trouble capturing errors when they happen.
: For example, if I try and insert a row with a duplicate primary key, I
: get this error on the terminal ...
: ERROR at line 1:
: ORA-00001: unique constraint (OPS$N450MAT.INTERFACE_PK) violated
: The return code however is 0 ...
: DEBUG: return code $? = 0
: How can I capture sqlplus errors from within the script? An extract
: of the code is below ...
: Cheers,
: David
: open SQL, "| sqlplus -s $orauser/$orapass\@$oradb"
: or die ("Can't open sqlplus for write: $!\n");
:
: my $sql;
:
: ... generate insert statements ...
:
: print SQL <<EOR;
: $sql
: commit;
: exit
: EOR
: close SQL or warn ("Couldn't close sqlplus pipe: $!");
: print "DEBUG: return code \$\? is $?\n";
I'm not sure why sqlplus would give an error code since it did its job
with no problem.
In any case, if you wish to get an error from sqlplus then one of the
oracle groups would have people who would know how to arrange that (in
fact a little while ago there was just such a discussion).
With the right options, you can use sqlplus in a here doc, in which case
you could pipe the output and parse it (and use the here doc to feed in
the input).
------------------------------
Date: Sun, 21 Mar 2004 17:38:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: dollar sign and spaces from a string
Message-Id: <slrnc5s9re.6n3.tadmc@magna.augustmail.com>
Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> Also sprach Newbie:
>> - "You have an error on line X" could be changed to "provide some code and
>> we will be able to help you"
>
> Ok, that's a shallow joke that perhaps needs to be replaced by a fresh
> and better one.
Perhaps.
I've used both, each when "appropriate" (IMO).
> However, it is often a sign that the OP didn't bother to
> read the posting guidelines of this group.
I don't pull out that first quote for not following the guidelines,
it needs to be a bit more egregious to "earn" the line number approach.
I'd say:
However, it is often a sign that the OP didn't bother to
think much about what would be needed by a potential answerer.
That is, I pull out the line number approach when it should be
obvious that we need to see the code in order to debug the code.
I don't generally pull it out when they just left out the applicable
code section, I try and reserve it for when they post no code whatsoever.
Either they are disrespectful of the group's time and get it back
in kind, or they are so new to programming that they really think
we can help without the code.
If the former, who cares?
If the latter then the lesson will "stick" better if they figure
it out for themselves from the "line number" approach...
... How did he know what line the problem was on?
...
... Oh. He's being facetious, he means he needs to see the code.
I count the 1st example response quoted above as teaching to fish
and the second as giving a fish.
I give fish aplenty hereabouts, but that is low-payback for both
the answerer and the questioner compared to solving the "big picture"
aspect of a problem.
> That he might not have known
> about them is hardly an excuse. Whenever entering a new surrounding, it
> is better to watch things for a while before making a step forth. If you
> don't, well, you risk stepping on some people's toes.
These "you guys are mean" threads are almost always about the
"Ouch damnit!" that results from when they step on your toe.
> Note that the guidelines don't just "encourage" people to do certain
> things. Some are listed as "musts". Looking up the FAQs is one of those.
^^^^^^^^^^
In the context of "must if you want to avoid making just about
everybody mad".
There aren't any true musts here (hence the trash), it's unmoderated.
>> Wouldn't it be better to
>> simply smile and remember the days where you were a newbie and thought that
>> you knew more than you really did?
>
> From a newbieish point of view, that sounds logical. For a regular of
> this group (and someone who has probably participated in usenet for many
> years), the amount of outright rubbish that gets dumped in here and
> elsewhere is painful. There are many ways to deal with it. The easiest
> (and worst) way is leaving the group and have more time to spend for
> one's family or hobbies.
I used to get my Perl questions answered here by Larry Wall himself...
>> If you feel overwhelmed by the number of stupid posts, save
>> yourself a reply, save us from reading a non technical reply (one could
>> argue that this apply to my reply here :) and just move on to another post.
To me, that sounds like:
When someone cuts in line in front of you, don't say anything to them.
That's going to be a hard sell, given human nature and all.
> The reputation of this group for being a hostile place is probably a
> good thing.
They just need to know about that waiting-in-line thing...
In article <1995Nov9.193745.13694@netlabs.com>, lwall@netlabs.com
(Larry Wall) wrote: ...
[snip] I view a programming language as a place to be
explored, like Disneyland. You don't need to have a lot of preparation
to explore a theme park. You do have to go along with the crowd
control measures, though. In a sense, each ride has its own
prerequisites--if you cut in line, you risk getting tossed out of the
park.
What we have here in this newsgroup is a failure in crowd control.
Reading the FAQ is like staying in line--it's something you should
learn in kindergarten. Usenet needs a better kindergarten.
> It makes first-time posters a bit more cautious in what they
> write (and thus improving the overall quality of the posts). Once they
> do that they'll realize that clpm is in fact quite a friendly group.
I tell people:
Try to find the answer yourself for 10 minutes. If you don't
find it in 10 minutes, post away!
I get less nice when I sense a lesser time commitment.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 22 Mar 2004 04:16:31 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: file upload and STDIN
Message-Id: <zMt7c.55576$1p.932692@attbi_s54>
Jeff Thies wrote:
> #!/usr/bin/perl -w
> $|=1;
> print "Content-type: text/html
>
> It seems that the uploaded file must be transfered before this is printed";
Most browsers won't display anything until a paragraph break or a forced
line break. Add "<br>" or "<hr>" to see if that makes any difference.
-Joe
------------------------------
Date: Mon, 22 Mar 2004 00:00:50 GMT
From: moller@notvalid.se
Subject: Re: graph smoothing...
Message-Id: <u3c81px6q.fsf@notvalid.se>
"Bill Parker" <bill@gites.org.uk> writes:
> I'm using GD::Graph quite successfully to produce a (temperature by time)
> graph.
>
> But it's quite spikey and so I thought I'd overlay it with some sort of
> smoothed graph, so's the trend can (well, may be) displayed. But my
> statistics knowledge is very rusty now:
>
> So can anyone recommend a method for smoothing out the data into something
> "pretty" but with a sound maths or scientific basis behind it? I'd rather to
> use a perl module if one exists - as I said, I'm so rusty on what to do with
> my data that I'm not sure what to look for in a statistics module of some
> sort.
>
> Any help gratefully received etc. etc.
>
> Bill
You can solve the differential equation that satisfies your data points.
That will give you a smooth graph to plot.
Not a perl answer but I'm sure you can find the apropriate math modules
yourself.
------------------------------
Date: Mon, 22 Mar 2004 11:10:05 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: graph smoothing...
Message-Id: <1720462.l3v45c6pRE@GMT-hosting-and-pickle-farming>
Bill Parker wrote:
> I'm using GD::Graph quite successfully to produce a (temperature by time)
> graph.
>
> But it's quite spikey and so I thought I'd overlay it with some sort of
> smoothed graph, so's the trend can (well, may be) displayed. But my
> statistics knowledge is very rusty now:
>
> So can anyone recommend a method for smoothing out the data into something
> "pretty" but with a sound maths or scientific basis behind it? I'd rather
> to use a perl module if one exists - as I said, I'm so rusty on what to do
> with my data that I'm not sure what to look for in a statistics module of
> some sort.
>
> Any help gratefully received etc. etc.
>
> Bill
You can fit a polynomial, or use a moving average.
Moving average is trivial to program.
http://mathworld.wolfram.com/MovingAverage.html
Fitting a polynomial by least squares can be done using matrix algebra.
http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html
Statisticians use this as part of a general technique called Linear
Modelling. Stats packages have this built in.
http://www.nag.co.uk/stats/GDGE_soft.asp
gtoomey
------------------------------
Date: 21 Mar 2004 17:36:13 -0800
From: jkeen_via_google@yahoo.com (Jim Keenan)
Subject: Re: graph smoothing...
Message-Id: <196cb7af.0403211736.15482df8@posting.google.com>
"Bill Parker" <bill@gites.org.uk> wrote in message news:<c3kmp0$bb4$1@news-reader3.wanadoo.fr>...
> I'm using GD::Graph quite successfully to produce a (temperature by time)
> graph.
>
> But it's quite spikey and so I thought I'd overlay it with some sort of
> smoothed graph, so's the trend can (well, may be) displayed. But my
> statistics knowledge is very rusty now:
>
> So can anyone recommend a method for smoothing out the data into something
> "pretty" but with a sound maths or scientific basis behind it? I'd rather to
> use a perl module if one exists - as I said, I'm so rusty on what to do with
> my data that I'm not sure what to look for in a statistics module of some
> sort.
>
Using search.cpan.org and searching for the term "moving average," I
encountered this:
http://search.cpan.org/~jettero/Math-Business-SMA-0.99/
Does it do what you want?
Jim Keenan
------------------------------
Date: Mon, 22 Mar 2004 09:57:51 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: installing CPAN module
Message-Id: <405e1f06$0$16580$5a62ac22@freenews.iinet.net.au>
Roel van der Steen wrote:
> On Fri, 19 Mar 2004 21:14:49 +0000, foobardude wrote:
>>---------------------------------------------------------------------------
>>Did not find GP/PARI build directory around.
>>Do you want to me to fetch GP/PARI automatically?
>> (If you do not, you will need to fetch it manually, and/or direct me to
>> the directory with GP/PARI source via the command-line option
>>paridir=/dir)
>
>
> I tried this myself as root (installs OK) and as normal user (same result as
> you describe). It occurs to me that you don't have PARI/GP intsalled, and
> that package won't "make install" as a non-root user. (It's a C library.)
> I suggest you make sure you have PARI/GP http://pari.math.u-bordeaux.fr/
> installed, and then try again.
>
Built fine for me on Mandrake Linux and the only thing I did as root was
run 'make install' (all as per normal) - all the rest was done as user.
(I wasn't using the CPAN shell, have no interest in so doing, and
certainly no interest in troubleshooting any problems associated with it.)
From memory, I did it following the manual procedure - steps a to h in
the INSTALL file that comes with the Math::Pari distro. I ignored
anything in those steps that was stated as optional.
Guess I'm just trying to say that if you can't get it sorted using the
cpan shell then give the "manual procedure" a shot :-)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Mon, 22 Mar 2004 00:04:23 GMT
From: Sandrino <sandrinotrepppalle@sandrino.it>
Subject: perl 5.8.3 on windows XP eat an huge amount of memory?
Message-Id: <g3bs50hmcp8q0urfm7opisik4b3nmm32vr@4ax.com>
I'm learning perl just now. Trying some very simple examples, I found
that perl requires a very large amount of memory. For example the
following program
print "insert a string: ";
$string = <STDIN>;
print "insert a number: ";
chomp($number = <STDIN>);
$string2 = $string x $number;
print $string2;
if I insert a big number (like 10000000), perl uses about 300MB of
memory. Why?
ciao
Sandrino
------------------------------
Date: Mon, 22 Mar 2004 00:06:46 GMT
From: Sandrino <sandrinotrepppalle@sandrino.it>
Subject: Re: perl 5.8.3 on windows XP eat an huge amount of memory?
Message-Id: <febs50duguffm8a1iitfigvchd6c8512qh@4ax.com>
On Mon, 22 Mar 2004 00:04:23 GMT, Sandrino
<sandrinotrepppalle@sandrino.it> wrote:
>if I insert a big number (like 10000000), perl uses about 300MB of
>memory. Why?
I'm a moron. Definitely a moron. Sorry
------------------------------
Date: Sun, 21 Mar 2004 18:20:49 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Problem installing Net::DNS
Message-Id: <pan.2004.03.21.23.20.47.664450@remove.adelphia.net>
On Sun, 21 Mar 2004 18:05:00 +0000, John Oliver wrote:
> The exact same result... nothing more, nothing less.
Maybe you should contact the author. This *may* be a know issue.
Or, you could submit a bug report at the following URL:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-DNS
Apparently, there *appears* to be a bug that was(n't) fix related to the
Resolver.pm.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Reality is a cop-out for people who can't handle drugs.
------------------------------
Date: Mon, 22 Mar 2004 01:53:46 GMT
From: Joe <mail@annuna.com>
Subject: Re: Question about scope.
Message-Id: <KGr7c.51431$aT1.6705@newsread1.news.pas.earthlink.net>
Roel van der Steen wrote:
> On Sat, 20 Mar 2004 at 19:07 GMT, Joe <mail@annuna.com> wrote:
>
>>I am trying to create an class and then try to access the data members
>>in that class. When I run this piece of code the data prints out in the
>>constructor but when I use the function I get no out put. How do I get
>>this to work?
>>
>>
>
> Actually, your code works. I'm not sure what you mean by "use the
> function". See example below for sample contructor and method
> call.
>
>
> Always:
> use strict;
> use warnings;
>
>
>>package Space;
>>
>>my $space;
>
> ^^^^^^^^^
> Always declare your variables in the smallest possible scope, in this
> case within the object constructor. (Your object instance will be
> returned with the "return" statement from the sub "new"; no need to
> have it in your class package as well.)
>
>
>>#spaces of the grid
>>
>>sub new {
>> $space = {
>
> . . ^
> Insert "my" before this variable name
>
>
>> loc => $_[0],
>
> . . . . . . . ^^^^^
> I assume we have the real problem here -- why do you store the package
> name in the object? I think you want to be able to give some argument
> with the constructor call, but note that is passed in as $_[1].
>
>
>> char => 0,
>
> . . . . . . . ^
> (You may consider renaming this property, since "char" could make a user
> of your class think that this is some string property, but here you do a
> numeric assignment...)
>
>
>> };
>
> . . .^
> (Leave this one off)
>
>
>> print $space->{loc};
>
>
> This effectively prints out your class name: "Space" (but before your
> object is blessed).
>
>
>> bless $space, 'Space';
>> return $space;
>>}
>>
>>sub fchsym{ #returns the symbol for map printing.
>
> . . . ^^^^^^
> Consider revising this name as well -- the user of your class won't
> get much of clue from this what this method does.
>
>
>> print $space->{loc};
>
>
> (I assume this "print" statement is only for testing.)
>
>
>> return $space->{loc};
>>}
>>
>
>
>
> # Now:
>
>
> package main;
>
> my $space_obj = Space->new(); # already prints the text "Space" once...
> my $fchsym_result = $space_obj->fchsym(); # ... that's the 2nd "Space"...
> print $fchsym_result; # ... and the 3rd.
>
> __END__
>
>
> This prints:
>
> SpaceSpaceSpace
>
>
> I suggest you re-read "perltoot", think the whole thing over, and then
> explain us in somewhat more detail what your class needs to do. That
> should get you swiftly on the right track.
What happens is when I create the object it will print what I want in
the constructor so, $space->{loc} prints out in the constructor, but
when I use the function there is no value in $pace->{loc}
------------------------------
Date: Mon, 22 Mar 2004 01:01:53 GMT
From: Tigerhillside <Tigerhillsideremove@removenetscape.net>
Subject: Re: Redirect problem
Message-Id: <iles50l93e6gbac7gdvcs1hf4u81fa1puo@4ax.com>
In comp.lang.perl.misc, Tad McClellan <tadmc@augustmail.com>, I
read and responded
>Tigerhillside <Tigerhillsideremove@removenetscape.net> wrote:
>> In comp.lang.perl.misc, "Matt Garrish"
>><matthew.garrish@sympatico.ca>, I read and responded
>>>"Tigerhillside" <Tigerhillsideremove@removenetscape.net> wrote in message
>>>news:u17r50lmhcbp7s99l65rn6rnnhif885r7s@4ax.com...
>
>>>> But I get an error from the browser
>>>> on system 2.
>
>>can't thunk why
>>>you're asking this question here.
>
>> I am sorry if this is the wrong place, I have to admit I get a
>> bit confused by some of the hierarchy issues.
>
>
>If the error message you are getting appears in perldiag.pod,
>then it is a Perl problem, post here.
>
>Else it is probably not a Perl problem, look elsewhere.
It was the HTTP 500 error so either the perl script had a problem
or something else. Like I said, I went through the
troubleshooting FAQ and stripped down the script. I just hoped
someone had an idea.
------------------------------
Date: Mon, 22 Mar 2004 01:06:51 GMT
From: Tigerhillside <Tigerhillsideremove@removenetscape.net>
Subject: Re: Redirect problem
Message-Id: <sres50l63vavrlgop5lj7v3qmq2ugqmec7@4ax.com>
In comp.lang.perl.misc, "gnari" <gnari@simnet.is>, I read and
responded
>"Tigerhillside" <Tigerhillsideremove@removenetscape.net> wrote in message
>news:u17r50lmhcbp7s99l65rn6rnnhif885r7s@4ax.com...
>
>[problem with redirect]
>
>
>> ... The only other difference is system 2,
>> the non-working, is a secure server. But I am redirecting inside
>> the server. I have tried relative redirection, absolute, but not
>> HTTPS, and the full URI. I have also asked tech support, but
>> gotten no answer. Anyone have any ideas?
>
>I do not know what the problem is, and I don't really understand
>what implications are meant by 'secure server',
I meant https rather than http.
> but your
> 'But I am redirecting inside the server'
>comment suggests to me that you do not realize what the redirect
>does. it send back instructions to the browser with a new url to
>try, so there is no such thing as redirecting inside the server
>with this method.
>
>if this is your problem, then you need some other solution, which
>could be one of:
> using mod_proxy or mod_rewrite with apache
> if mod_perl is used, you can use the Apache API to do
> an internal_redirect()
> proxy the page yourself, using LWP in your cgi
I am directing the use from page A to page B. I think that is a
reasonable use of redirect. I could explain the whole system, but
it is irrelevant to the problem. It is quite a bit easier for me
if I can do this than if not.
------------------------------
Date: Mon, 22 Mar 2004 01:41:56 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Redirect problem
Message-Id: <slrnc5sh34.bg4.efflandt@typhoon.xnet.com>
On Sun, 21 Mar 2004, Tigerhillside
<Tigerhillsideremove@removenetscape.net> wrote:
> Yes, I have walked through the troubleshooting steps. I have
> tried everything I can. I am trying to get redirection to work.
> Here is a simple script that does not work:
>
> #!/usr/bin/perl -w
>
> use strict;
>
> use CGI qw(:standard);
> use CGI qw(-debug);
>
> use Carp;
>
> local $SIG{__WARN__} = \&Carp::cluck;
>
> my $q = new CGI;
>
> print $q->redirect('NewURL');
Why do you 'use' so many variations of CGI.pm in the same script (2
separate function methods and object method)? One: use CGI qw(:standard
-debug); eliminates the need for my $q = new CGI; and $q->.
If you read 'perldoc CGI', it says "relative links may not work
correctly...The solution to this is to use the full URL..." Relative
internal links may be considered insecure for a secure server.
--
David Efflandt - All spam ignored http://www.de-srv.com/
------------------------------
Date: Mon, 22 Mar 2004 02:38:25 GMT
From: Joe <mail@annuna.com>
Subject: scope again
Message-Id: <Bks7c.51457$aT1.2623@newsread1.news.pas.earthlink.net>
This class still will not work. I have stripped the class down to the
basics. I know about the style issue so this is basically bare bones.
package Space;
#spaces of the grid
sub new{
my $space = {
loc => $_[0],
char => 0
};
bless $space, 'Space';
print $space->{loc}; <-- prints here.
return $space;
}
sub fchsym{ #returns the symbol for map printing.
print "k"; <-prints this so I know that it gets accessed.
print "$space->{loc}"; < -won't print these data mbembers.
print "$space->{char}";
return $space->{loc};
}
These are very basic object oriented concepts. I am getting very
fustrated. I am using this version of per with suzi lynx.
This is perl, v5.8.1 built for i586-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2003, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
------------------------------
Date: Mon, 22 Mar 2004 03:10:57 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: scope again
Message-Id: <405E593B.7080704@rochester.rr.com>
Joe wrote:
> This class still will not work. I have stripped the class down to the
> basics. I know about the style issue so this is basically bare bones.
> package Space;
>
>
> #spaces of the grid
>
> sub new{
> my $space = {
> loc => $_[0],
> char => 0
>
> };
>
> bless $space, 'Space';
>
> print $space->{loc}; <-- prints here.
> return $space;
> }
>
> sub fchsym{ #returns the symbol for map printing.
>
> print "k"; <-prints this so I know that it gets accessed.
> print "$space->{loc}"; < -won't print these data mbembers.
--------^-------------^
Inside quotes, the variable $space will be interpolated. If $space
contains the string "Pluto", you would get:
Pluto->{loc}
printed. Interpolation does not evaluate operators. This is different
than the code in your first post, which did not contain this particular
error. Have you been copy/pasting your code, or retyping it in your
posts? Please *please* copy/paste it.
> print "$space->{char}";
--------^--------------^
same thing
> return $space->{loc};
> }
>
...
Well, other than the above, I'll bet it's something in the way you're
calling your module. Here is a complete example that should work if
copy/paste/executed (and note: please pay attention to what the various
replys in your previous thread said about OO-programming in Perl -- they
were right on -- this code is your code almost verbatim, and is *not*
necessarily How It Should Be Done [all one file]:
use warnings;
use strict;
my $s=new Space('location');
print "main program...\n";
print Space::fchsym();
package Space;
my $space;
#spaces of the grid
sub new{
$space = {
loc => $_[1],
char => 0
};
print $space->{loc};
bless $space, 'Space';
return $space;
}
sub fchsym{ #returns the symbol for map printing.
print $space->{loc};
return $space->{loc};
}
1;
When run, that should print:
D:\junk>perl junk440.pl
locationmain program...
locationlocation
D:\junk>
The first 'location' was from the new method; the second was from sub
fchsym, and the third was from the print in package main.
Does this give you these same results when copy/paste/executed? If so,
you have a starting point for figuring out what is going wrong.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Mon, 22 Mar 2004 03:46:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: scope again
Message-Id: <405E6193.C3750D3D@acm.org>
Bob Walton wrote:
>
> Joe wrote:
> >
> > This class still will not work. I have stripped the class down to the
> > basics. I know about the style issue so this is basically bare bones.
> > package Space;
> >
> > #spaces of the grid
> >
> > sub new{
> > my $space = {
> > loc => $_[0],
> > char => 0
> >
> > };
> >
> > bless $space, 'Space';
> >
> > print $space->{loc}; <-- prints here.
> > return $space;
> > }
> >
> > sub fchsym{ #returns the symbol for map printing.
> >
> > print "k"; <-prints this so I know that it gets accessed.
> > print "$space->{loc}"; < -won't print these data mbembers.
>
> --------^-------------^
> Inside quotes, the variable $space will be interpolated. If $space
> contains the string "Pluto", you would get:
>
> Pluto->{loc}
>
> printed. Interpolation does not evaluate operators.
Are you sure about that Bob? It's very easy to test:
$ perl -le'my $space = q(Pluto); print "$space->{loc}";'
$ perl -le'my $space = { loc => 888 }; print "$space->{loc}";'
888
John
--
use Perl;
program
fulfillment
------------------------------
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 6287
***************************************