[24146] in Perl-Users-Digest
Perl-Users Digest, Issue: 6340 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 30 14:05:51 2004
Date: Tue, 30 Mar 2004 11:05:09 -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 Tue, 30 Mar 2004 Volume: 10 Number: 6340
Today's topics:
Re: Choosing Perl/Python for my particular niche <rmunn@pobox.com>
Re: Converting From C to Perl (Anno Siegel)
Re: Converting From C to Perl <nospamplease@no.com>
Different @inc's for different users? <footnipple@indiatimes.com>
INSERT statement works by itself but not in the script? <bdu@iastate.edu>
Re: INSERT statement works by itself but not in the scr <ittyspam@yahoo.com>
Re: INSERT statement works by itself but not in the scr <nobull@mail.com>
Re: INSERT statement works by itself but not in the scr <nobull@mail.com>
Re: INSERT statement works by itself but not in the scr <bdu@iastate.edu>
Re: Lost data on socket - Can we start over politely? <ThomasKratz@REMOVEwebCAPS.de>
Re: Lost data on socket - Can we start over politely? <ThomasKratz@REMOVEwebCAPS.de>
Re: Net::SSH Need example how to use..can't find one.. <remorse@partners.org>
Re: Passing a struct to a subroutine <nobull@mail.com>
Re: scope again <mail@annuna.com>
Re: scope again <1usa@llenroc.ude>
Re: scope again <xx087@freenet.carleton.ca>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 30 Mar 2004 18:00:51 GMT
From: Robin Munn <rmunn@pobox.com>
Subject: Re: Choosing Perl/Python for my particular niche
Message-Id: <nBiac.42307$PY.17419@newssvr26.news.prodigy.com>
Fred Ma <fma@doe.carleton.ca> wrote:
> Hello,
>
> This is not a troll posting, and I've refrained from
> asking because I've seen similar threads get all
> nitter-nattery.
[snip: poster is basically asking "Should I learn Perl or Python?"]
While availability of libraries for your specific tasks is a major
factor to take into consideration, I'd say that even more important is
to figure out which language fits your brain.
I first learned Perl, then Python. I now use Python almost exclusively,
because I found that Python fits my mental "map" much better than Perl
does. To me, it seemed like in Perl, everything was a string. Sure, you
could have objects and classes, but they felt strange and awkward -- how
do I translate the "bless" keyword into my mental model? Whereas
Python's object model translated perfectly into my mental map, to the
point where programming in Python gave a clarity that I never had when
using Perl. It's hard to explain why, exactly -- it just seemed like
when using Perl, I was always going back down to the level of details,
the trees in the forest. Python allows me to look at the entire forest.
I can still go down and look at trees if I need to, but I don't have to
operate in that mode all the time.
Your mileage *will* vary. There's no substitute for experience. Set
yourself a simple task (say, writing a sieve of Eratosthenes program)
that you could do in about an hour with a language you're familiar with.
Then write the same program in Perl and in Python, and see which one
fits *your* brain better.
--
Robin Munn
rmunn@pobox.com
------------------------------
Date: 30 Mar 2004 16:33:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Converting From C to Perl
Message-Id: <c4c7fv$ssc$2@mamenchi.zrz.TU-Berlin.DE>
SketchySteve <nospamplease@no.com> wrote in comp.lang.perl.misc:
> Hi there,
>
> I'm currently working on neural network project. The program i'm using
> (SNNS) will automaticly create a network as a c function which can be
> called.
>
> I know there are tools for converting Perl into C but I was wondering if
> there were any which worked the other way round.
Don't you rather want to *call* the C function from Perl? Automatically
generating C code and translating that into Perl sounds like too strange
a concept. What would a conversion buy you, except a slowdown by 5 or 10?
Inline::C is good at making C programs callable from Perl. If the function
is in a library and you have a header file for it, with a little luck
it does it all by itself, but even if it doesn't, it's usually easy.
Anno
------------------------------
Date: Tue, 30 Mar 2004 18:18:32 +0100
From: "SketchySteve" <nospamplease@no.com>
Subject: Re: Converting From C to Perl
Message-Id: <uRhac.148$OJ.94@newsfe2-gui.server.ntli.net>
Thanks for the advice, I have looked into the inline module and it seems to
do what I want. The only drawback is that i will need to install Visual
Studio for it to work.
It looks like there is the option of using other utilities but they require
Perl being re-installed.
Ah well, trying to track down visual studio now.
Cheers
Steve
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:c4c7fv$ssc$2@mamenchi.zrz.TU-Berlin.DE...
> SketchySteve <nospamplease@no.com> wrote in comp.lang.perl.misc:
> > Hi there,
> >
> > I'm currently working on neural network project. The program i'm using
> > (SNNS) will automaticly create a network as a c function which can be
> > called.
> >
> > I know there are tools for converting Perl into C but I was wondering if
> > there were any which worked the other way round.
>
> Don't you rather want to *call* the C function from Perl? Automatically
> generating C code and translating that into Perl sounds like too strange
> a concept. What would a conversion buy you, except a slowdown by 5 or 10?
>
> Inline::C is good at making C programs callable from Perl. If the
function
> is in a library and you have a header file for it, with a little luck
> it does it all by itself, but even if it doesn't, it's usually easy.
>
> Anno
------------------------------
Date: Tue, 30 Mar 2004 17:20:26 GMT
From: "sdfgsd" <footnipple@indiatimes.com>
Subject: Different @inc's for different users?
Message-Id: <u%hac.352063$B81.5230606@twister.tampabay.rr.com>
Well this one's got me at my wit's end:
I'll spare the gorry details, but I upgraded from 5.8.0 => 5.8.3 then
down-graded again for apache/mod_perl...duh. Anyway, the original Suse perl
went to /usr/lib and the upgrade went to /usr/local/lib...along with a few
modules.
So now I'm running a few scripts (same old perl executable) as a regular
user and as root and they both seem to be using different @inc's from the
two different libs!
I know I'll eventually be able to solve the problem, but I don't want to
throw the baby out with the bathwater...so to speak.
Any insights on this?
Jim B
------------------------------
Date: Tue, 30 Mar 2004 10:22:39 -0600
From: Bing Du <bdu@iastate.edu>
Subject: INSERT statement works by itself but not in the script??
Message-Id: <c4c6sl$1bu$1@news.iastate.edu>
Greetings,
This is perl, v5.8.0 built for i386-linux-thread-multi.
The result of the following INSERT is '0E0' (value of $rv) if run in a
Perl script that uses DBI and DBD::mysql (version 2.9003). The table
$ltm_ssn_table is still empty after INSERT.
=============
$rv = $mysql_dbh->do(qq{INSERT INTO $ltm_ssn_table (ltm_number,ssn,notes)
SELECT
$source_data_table.crse,$source_data_table.ssn,$old_ltm_ssn_table.notes
FROM $source_data_table LEFT JOIN $old_ltm_ssn_table
ON $source_data_table.crse=$old_ltm_ssn_table.ltm_number
AND $source_data_table.ssn=$old_ltm_ssn_table.ssn
WHERE $source_data_table.offer_dept_abrvn='$ltm_string'
});
============
However, the above INSERT works fine with the MySQL command line client:
========
mysql> INSERT INTO ltm_ssn (ltm_number,ssn,notes) SELECT
source_data.crse, source_data.ssn, old_ltm_ssn.notes FROM source_data
LEFT JOIN old_ltm_ssn ON source_data.crse=old_ltm_ssn.ltm_number AND
source_data.ssn=old_ltm_ssn.ssn WHERE source_data.offer_dept_abrvn='L TM;
Query OK, 485 rows affected (0.03 sec)
Records: 485 Duplicates: 0 Warnings: 0
==========
Would anybody tell me what's wrong with the INSERT within the script?
Appreciate any help.
Bing
------------------------------
Date: Tue, 30 Mar 2004 11:45:51 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: INSERT statement works by itself but not in the script??
Message-Id: <20040330114319.W19862@dishwasher.cs.rpi.edu>
On Tue, 30 Mar 2004, Bing Du wrote:
> Greetings,
>
> This is perl, v5.8.0 built for i386-linux-thread-multi.
>
> The result of the following INSERT is '0E0' (value of $rv) if run in a
> Perl script that uses DBI and DBD::mysql (version 2.9003). The table
> $ltm_ssn_table is still empty after INSERT.
>
> =============
> $rv = $mysql_dbh->do(qq{INSERT INTO $ltm_ssn_table (ltm_number,ssn,notes)
> SELECT
> $source_data_table.crse,$source_data_table.ssn,$old_ltm_ssn_table.notes
> FROM $source_data_table LEFT JOIN $old_ltm_ssn_table
> ON $source_data_table.crse=$old_ltm_ssn_table.ltm_number
> AND $source_data_table.ssn=$old_ltm_ssn_table.ssn
> WHERE $source_data_table.offer_dept_abrvn='$ltm_string'
> });
> ============
>
> However, the above INSERT works fine with the MySQL command line client:
>
> ========
> mysql> INSERT INTO ltm_ssn (ltm_number,ssn,notes) SELECT
> source_data.crse, source_data.ssn, old_ltm_ssn.notes FROM source_data
> LEFT JOIN old_ltm_ssn ON source_data.crse=old_ltm_ssn.ltm_number AND
> source_data.ssn=old_ltm_ssn.ssn WHERE source_data.offer_dept_abrvn='L TM;
> Query OK, 485 rows affected (0.03 sec)
> Records: 485 Duplicates: 0 Warnings: 0
> ==========
>
> Would anybody tell me what's wrong with the INSERT within the script?
>
Have you asked the Database what's wrong first? Check the values of
$dbh->errstr
and
$dbh->{'mysql_error'}
to see if they contain anything useful.
Paul Lalli
------------------------------
Date: 30 Mar 2004 18:11:18 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: INSERT statement works by itself but not in the script??
Message-Id: <u9hdw66z0p.fsf@wcl-l.bham.ac.uk>
Bing Du <bdu@iastate.edu> writes:
> The result of the following INSERT is '0E0' (value of $rv) if run in a
> Perl script that uses DBI and DBD::mysql (version 2.9003). The table
> $ltm_ssn_table is still empty after INSERT.
>
> =============
> $rv = $mysql_dbh->do(qq{INSERT INTO $ltm_ssn_table (ltm_number,ssn,notes)
> SELECT
> $source_data_table.crse,$source_data_table.ssn,$old_ltm_ssn_table.notes
> FROM $source_data_table LEFT JOIN $old_ltm_ssn_table
> ON $source_data_table.crse=$old_ltm_ssn_table.ltm_number
> AND $source_data_table.ssn=$old_ltm_ssn_table.ssn
> WHERE $source_data_table.offer_dept_abrvn='$ltm_string'
> });
> ============
>
> However, the above INSERT works fine with the MySQL command line client:
>
> ========
> mysql> INSERT INTO ltm_ssn (ltm_number,ssn,notes) SELECT
> source_data.crse, source_data.ssn, old_ltm_ssn.notes FROM source_data
> LEFT JOIN old_ltm_ssn ON source_data.crse=old_ltm_ssn.ltm_number AND
> source_data.ssn=old_ltm_ssn.ssn WHERE source_data.offer_dept_abrvn='L
> TM;
> Query OK, 485 rows affected (0.03 sec)
> Records: 485 Duplicates: 0 Warnings: 0
> ==========
Have you tried putting the SQL command into a variable and printing it out
before you do() it just to be sure that it really is the same as the
command you tried in the command line client?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 30 Mar 2004 18:08:05 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: INSERT statement works by itself but not in the script??
Message-Id: <u9llli6z62.fsf@wcl-l.bham.ac.uk>
Paul Lalli <ittyspam@yahoo.com> writes:
> On Tue, 30 Mar 2004, Bing Du wrote:
> > The result of the following INSERT is '0E0' (value of $rv)
> Have you asked the Database what's wrong first? Check the values of
> $dbh->errstr
> and
> $dbh->{'mysql_error'}
> to see if they contain anything useful.
Unlikely, the command didn't fail - it just inserted zero rows.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 30 Mar 2004 11:15:08 -0600
From: Bing Du <bdu@iastate.edu>
Subject: Re: INSERT statement works by itself but not in the script??
Message-Id: <c4c9v3$184$1@news.iastate.edu>
Yes, I have. $mysql_dbh->errstr returned nothing. It finally turned
out something outside of the INSERT statement was not set right. Thanks
for the heads-up.
Bing
Paul Lalli wrote:
> On Tue, 30 Mar 2004, Bing Du wrote:
>
>
>>Greetings,
>>
>>This is perl, v5.8.0 built for i386-linux-thread-multi.
>>
>>The result of the following INSERT is '0E0' (value of $rv) if run in a
>>Perl script that uses DBI and DBD::mysql (version 2.9003). The table
>>$ltm_ssn_table is still empty after INSERT.
>>
>>=============
>>$rv = $mysql_dbh->do(qq{INSERT INTO $ltm_ssn_table (ltm_number,ssn,notes)
>> SELECT
>>$source_data_table.crse,$source_data_table.ssn,$old_ltm_ssn_table.notes
>> FROM $source_data_table LEFT JOIN $old_ltm_ssn_table
>> ON $source_data_table.crse=$old_ltm_ssn_table.ltm_number
>> AND $source_data_table.ssn=$old_ltm_ssn_table.ssn
>> WHERE $source_data_table.offer_dept_abrvn='$ltm_string'
>> });
>>============
>>
>>However, the above INSERT works fine with the MySQL command line client:
>>
>>========
>>mysql> INSERT INTO ltm_ssn (ltm_number,ssn,notes) SELECT
>>source_data.crse, source_data.ssn, old_ltm_ssn.notes FROM source_data
>>LEFT JOIN old_ltm_ssn ON source_data.crse=old_ltm_ssn.ltm_number AND
>>source_data.ssn=old_ltm_ssn.ssn WHERE source_data.offer_dept_abrvn='L TM;
>>Query OK, 485 rows affected (0.03 sec)
>>Records: 485 Duplicates: 0 Warnings: 0
>>==========
>>
>>Would anybody tell me what's wrong with the INSERT within the script?
>>
>
>
> Have you asked the Database what's wrong first? Check the values of
> $dbh->errstr
> and
> $dbh->{'mysql_error'}
> to see if they contain anything useful.
>
> Paul Lalli
------------------------------
Date: Tue, 30 Mar 2004 18:27:41 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Lost data on socket - Can we start over politely?
Message-Id: <4069a132.0@juno.wiesbaden.netsurf.de>
Vorxion wrote:
> In light of some uh...disagreements, I've bent a bit. Hopefully it's taken
> as a token of goodwill. I could use the help, I'm willing to bend a bit to
> do it. SO...
>
> I've reworked this to both make it shorter, and so that my extra curly
> brackets are not present. I also implemented strict and warnings.
>
> In short, connect with anything and toss, say... 4000 thousand lines of
> input at the server. It should give up the ghost far early--somewhere
> around 1120-2200, depending on the phase of the moon. You'll note that if
> you're still connected, you can even send more data. It's purely a
> buffering issue.
>
> I've switched to using only buffered reads and writes on the socket fd's,
> so that's no longer the issue. I'm sure it was contributing, but nothing
> I'm doing here should be affecting it, to the best of my knowledge.
>
> Now that I've cleaned up my code (at least the majority) and am trying to
> appease some people, could I please ask for assistance? (Yes, there are a
> lot of variables in the our() statements that aren't used here...I trimmed
> about 1000 lines of code out this time instead of ~800.)
>
> If you just run it and toss input at it that's newline-separated, you'll
> see what I mean. I'm tossing 3900+ lines at it. It gives up at 1123
> somtimes, 2316 others, etc. Entirely arbitrary. It's not buffering
> corretly, but I know not why at this point.
[ code snipped ]
Sorry, but the code is still too cluttered to debug it. I have tried,
really, for about 45 minutes, then I gave up.
Instead please try this server ( some quickly reduced code from a bigger
server ) and mini client. If this works for you, you could extend it.
I don't loose any data with this setup. And I don't even bother to set
unbuffered mode (tested on Win32).
If you look at the server code, you'll get an idea what is meant by "a
small but complete sample to reproduce the problem". The base
functionality you need is in there. And if I were able to understand, what
your code tries to do, I would be able to shorten it to that level too.
Regards
Thomas
++++ server ++++
use strict;
use warnings;
use IO::File;
use IO::Select;
use IO::Socket;
my $max_buf = 10240;
my $sel = IO::Select->new();
my $srv = IO::Socket::INET->new(
Proto => 'tcp',
LocalPort => 4016,
Listen => SOMAXCONN,
ReuseAddr => 1,
);
$sel->add($srv);
die "couldn't create socket" unless $srv;
my $log = IO::File->new('server.log', '>') or die $!;
$log->autoflush(1);
while ( 1 ) {
foreach my $sock ( $sel->can_read(0.05) ) {
if ( $sock == $srv ) {
my $new = $srv->accept();
$new->autoflush(1);
print $log "new connection from ", $new->peerhost,
':', $new->peerport, "\n";
$sel->add($new);
next;
}
my $buf = '';
my $clsel = IO::Select->new($sock);
while ( $clsel->can_read(0.05) ) {
last unless $sock->sysread($buf, 1024, length($buf))
and (length($buf) <= $max_buf);
}
unless ( $buf ) {
print $log "error or close on socket\n";
$sock->close();
$sel->remove($sock);
next;
}
print $log "\n", length($buf), " bytes read\n";
print $log $buf;
}
}
++++ client ++++
use strict;
use warnings;
use IO::Socket;
my $sock = IO::Socket::INET->new(
PeerAddr => '235p008',
PeerPort => 4016,
Proto => 'tcp',
) or die "couldn't create socket";
my $i = 0;
while ( $sock->connected() ) {
last unless print $sock $i, 'x' x (100-length($i++)), "\n";
}
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
------------------------------
Date: Tue, 30 Mar 2004 18:43:59 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Lost data on socket - Can we start over politely?
Message-Id: <4069a504.0@juno.wiesbaden.netsurf.de>
Thomas Kratz wrote:
> I don't loose any data with this setup. And I don't even bother to set
> unbuffered mode (tested on Win32).
s/unbuffered/non blocking/;
Thomas
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
------------------------------
Date: Tue, 30 Mar 2004 11:06:41 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Net::SSH Need example how to use..can't find one...
Message-Id: <remorse-335018.11064030032004@plato.harvard.edu>
In article <2deb3d1.0403300738.264af0d5@posting.google.com>,
chilecayenne@yahoo.com (cayenne) wrote:
> I do have one last question, with regards to the single part that you
> gave me that made it work. With regards to adding the use qw(ssh_cmd)
> part after the use Net::SSH declaration.
>
> Why do you have to do this?
Every module can specify what it exports by default. In this case, the
Net::SSH module appears not to export any commands into your default
namespace by default. As to how to tell this, it varies. In this case,
the best clue is that in looking at the pod for the module, under the
"SYNOPSIS" section, the first line is:
use Net::SSH qw(ssh issh sshopen2 sshopen3);
which gives you a clue that you might need to specify the commands you
want.
Presumably, you can also look at the source code for the module. I
haven't yet figured out how to use Exporter correctly, so I don't know
for certain how to determine what is exported by default...
HTH,
Ricky
------------------------------
Date: 30 Mar 2004 17:52:32 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Passing a struct to a subroutine
Message-Id: <u9u1066zvz.fsf@wcl-l.bham.ac.uk>
graham@dim.com (Graham) writes:
> #
> # this doesn't work
> #
>
> sub PrintSoldiername {
> my $dude=stuff->new;
> $dude= @_;
This sets $dude to the number of arguments passed to PrintSoldiername().
To set $dude to the first argument:
($dude) = @_;
Please remember that in Perl (like Java and unlike C++) we always
handle objects through references (pointers). Setting $dude to point
to the stuff object that was passed to PrintSoldiername() will stop it
pointing to stuff you created on the line above (which will then be
garbage collected).
sub PrintSoldiername {
my ($dude)= @_;
print $dude->name
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 30 Mar 2004 17:13:05 GMT
From: Joe <mail@annuna.com>
Subject: Re: scope again
Message-Id: <BUhac.8410$lt2.296@newsread1.news.pas.earthlink.net>
Bob Walton wrote:
> John W. Krahn wrote:
>
>> Bob Walton wrote:
>
> ...
>
>>>> 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
>
>
>
> Hmmm...Yes, thanks, I see that you are correct. I should have tested. I
> see it is documented, too, although not super clearly:
>
>
> [from perlop]
>
>
> "Note also that the interpolation code needs to make a decision on
> where the interpolated scalar ends. For instance, whether "a $b -> {c}"
> really means:
>
> "a " . $b . " -> {c}";
>
> or:
>
> "a " . $b -> {c};
>
> Most of the time, the longest possible text that does not include
> spaces between components and which contains matching braces or
> brackets. because the outcome may be determined by voting based on
> heuristic estimators, the result is not strictly predictable.
> Fortunately, it's usually correct for ambiguous cases."
>
> Sounds like it might not be the best thing to actually count on.
I have been working on this bit of code and I am getting to the point
where I think my perl program has an error.
package Space;
my $space;
#spaces of the grid
sub new{
$space = {
char => "@",
tile => $_[0]
};
print $space->{tile}; <-- This print /* OK */
bless $space, 'Space';
return $space;
}
sub fchsym {
print "$space->{tile} \n"; <-- This won't print, why?
print "$space->{char} \n"; <-- This does print.
return $space->{tile};
}
Why am I gettitng the described output where the <-- are? I have been
working with this code. Trying slight veriatians but it refuses to
print out my tilles in my function. In my real program I don't want to
print them I am just doing this for debugging. I want to return a
synbol from the sapce depending in its contencts. I think my next step
will try to update perl.
------------------------------
Date: 30 Mar 2004 17:37:16 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: scope again
Message-Id: <Xns94BC806461909asu1cornelledu@132.236.56.8>
Joe <mail@annuna.com> wrote in
news:BUhac.8410$lt2.296@newsread1.news.pas.earthlink.net:
> I have been working on this bit of code and I am getting to the point
> where I think my perl program has an error.
You have not read or thought about the responses to your previous post. Yo
have also completely ignored the posting quidelines and perlobj and
perltoot.
use strict;
use warnings;
> package Space;
>
> my $space;
What have you seen in any docs that implies that having $space declared in
package scope is a good idea?
>
> #spaces of the grid
>
> sub new{
>
> $space = {
> char => "@",
> tile => $_[0]
> };
> print $space->{tile}; <-- This print /* OK */
> bless $space, 'Space';
> return $space;
> }
>
> sub fchsym {
> print "$space->{tile} \n"; <-- This won't print, why?
> print "$space->{char} \n"; <-- This does print.
>
> return $space->{tile};
> }
>
> Why am I gettitng the described output where the <-- are?
Why am I not getting the behavior you are describing? Nothing prints when I
run this. Ah-a, you haven't shown how you call the method.
> I have been working with this code. Trying slight veriatians but it
You don't learn by trial-and-error until something 'works'. You learn it by
following instructions.
> refuses to print out my tilles in my function. In my real program I
> don't want to print them I am just doing this for debugging. I want to
> return a synbol from the sapce depending in its contencts. I think my
> next step will try to update perl.
Start with your spell-checker ...
If you actually read perldoc perlobj, you will have no difficulty
understanding:
use strict;
use warnings;
package Space;
sub new {
my $class = shift;
my $self = { char => '@', tile => $_[0] };
bless $self, $class;
}
sub fchsym {
my $self = shift;
return $self->{tile};
}
package main;
my $space = Space->new(1);
print $space->fchsym();
__END__
Now, what kind of method name is fchsym?
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: 30 Mar 2004 18:14:12 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: scope again
Message-Id: <slrnc6je7l.ig8.xx087@smeagol.ncf.ca>
Joe <mail@annuna.com> wrote:
[...]
> package Space;
>
> my $space;
>
> #spaces of the grid
>
> sub new{
>
> $space = {
> char => "@",
> tile => $_[0]
> };
> print $space->{tile}; <-- This print /* OK */
> bless $space, 'Space';
> return $space;
> }
>
> sub fchsym {
> print "$space->{tile} \n"; <-- This won't print, why?
> print "$space->{char} \n"; <-- This does print.
>
> return $space->{tile};
> }
>
> Why am I gettitng the described output where the <-- are? I have been
> working with this code. Trying slight veriatians but it refuses to
> print out my tilles in my function. In my real program I don't want to
> print them I am just doing this for debugging. I want to return a
> synbol from the sapce depending in its contencts. I think my next step
> will try to update perl.
If I save your code and use it:
% require 'space.pl'
space.pl did not return a true value at (eval 1) line 1, <> line 1.
% $s=new Space
SpaceSpace=HASH(0x12bfd4)
% use Data::Dumper
% print Dumper($s)
$VAR1 = bless( {
'char' => '@',
'tile' => 'Space'
}, 'Space' );
You probably don't want the class name in $space->{tile}, do you?
Your package should probably look like this:
package Space;
sub new
{
my ($thingy, $tile) = @_;
my $class = ref($thingy) || $thingy;
my $self = { char => '@', tile => $tile, };
bless $self, $class;
return $self;
}
sub fchsym
{
my ($space) = @_;
# ... do stuff
print "tile is '$space->{tile}'\n";
}
# all packages should return true:
1;
Now:
% require 'space.pl'
% $s=Space->new('foo')
Space=HASH(0x12bfd4)
% use Data::Dumper
% print Dumper($s)
$VAR1 = bless( {
'char' => '@',
'tile' => 'foo'
}, 'Space' );
% $s->fchsym
tile is 'foo'
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
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 6340
***************************************