[31466] in Perl-Users-Digest
Perl-Users Digest, Issue: 2718 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 13 06:09:41 2009
Date: Sun, 13 Dec 2009 03:09:07 -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, 13 Dec 2009 Volume: 11 Number: 2718
Today's topics:
Re: Any way to tell if a scalar is a string? <hjp-usenet2@hjp.at>
Come on Perl, rescue me one more time! <laredotornado@zipmail.com>
Re: Come on Perl, rescue me one more time! <tadmc@seesig.invalid>
Re: Come on Perl, rescue me one more time! <jurgenex@hotmail.com>
Re: How big do your programs get before you modularise <hjp-usenet2@hjp.at>
Re: Simple loop error <jurgenex@hotmail.com>
Re: Simple loop error <tadmc@seesig.invalid>
Re: Simple loop error <spam.meplease@ntlworld.com>
Re: Simple loop error <tadmc@seesig.invalid>
Re: Simple loop error <jurgenex@hotmail.com>
Re: Simple loop error sln@netherlands.com
Re: Simple loop error <hjp-usenet2@hjp.at>
Re: Simple loop error <hjp-usenet2@hjp.at>
Re: Unblessed reference. <source@netcom.com>
Re: Unblessed reference. <tadmc@seesig.invalid>
Re: Unblessed reference. <ben@morrow.me.uk>
Re: Unblessed reference. <justin.0912@purestblue.com>
Re: Want to judge some remote hosts online or not quick <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 12 Dec 2009 23:11:11 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Any way to tell if a scalar is a string?
Message-Id: <slrnhi8580.5oi.hjp-usenet2@hrunkner.hjp.at>
On 2009-12-10 20:55, jl_post@hotmail.com <jl_post@hotmail.com> wrote:
> On Dec 10, 1:19 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
>> so your pack string knows the format, then you can
>> use it to tell you what is a number or a string.
>> in either case you have the info and don't need
>> to determine the data type after the unpacking.
>
>
> I have to disagree. I've worked with packstrings similar to:
>
> 'I/i I/(a10) I/i'
>
> and, as I've mentioned in an earlier post, there's no way for me to
> necessarily know where the first set (of integers) ends and the second
> set (of text) begins and ends, especially if all the text strings in
> the second set all happen to look like integers.
I'm missing something in this discussion:
Except for some simple data munging (transfer some data from a flat file
to a databases, for example) you need to know what the data *is* to
process it properly. And by "what it is" I don't mean "an integer" or "a
string", but things like "a credit card number", "a part number", "the
length of the vehicle in meters", "the number of life kangaroos exported
from Australia in 2007".
Once you know that you also know what kind of operation makes sense on
the data (e.g., even though a part number is "a number", it doesn't make
sense to add two part numbers) and the actual representation (is it a
string, an integer, a floating point number, a bit-packed structure?)
becomes secondary or is implicit.
So if you have a pack string like 'I/i I/(a10) I/i' you don't just need
to know that 1st and 3rd thing are unsigned integers, you also need to
know that the 1st one is a count of items, while the 3rd one is a
product class, to process them properly.
hp
------------------------------
Date: Sat, 12 Dec 2009 13:16:41 -0800 (PST)
From: laredotornado <laredotornado@zipmail.com>
Subject: Come on Perl, rescue me one more time!
Message-Id: <0f453a48-8fa0-4e3d-b864-02b1eccfb01c@w19g2000pre.googlegroups.com>
Hi,
I'm using Perl 5.8.8 on Mac 10.5.6. I have a text file with the
following content pattern ...
(newline)
line 1
line 2
line 3
(newline)
line 1
line 2
line 3
line 4
line 5
(new line)
line 1
line 2
What I would like to do is remove the first line immediately after any
new line (carriage return) and keep all the other lines. How can I do
this with perl?
Thanks, - Dave
------------------------------
Date: Sat, 12 Dec 2009 16:10:18 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Come on Perl, rescue me one more time!
Message-Id: <slrnhi8503.1ji.tadmc@tadbox.sbcglobal.net>
laredotornado <laredotornado@zipmail.com> wrote:
> I have a text file with the
> following content pattern ...
Please post real Perl code that represents your data.
Have you seen the Posting Guidelines that are posted here frequently?
> What I would like to do is remove the first line immediately after any
> new line (carriage return) and keep all the other lines. How can I do
> this with perl?
I think you want to remove a line if it follows a blank line (but I'm
not sure because of your ambiguous description of your data).
----------------------
#!/usr/bin/perl
use warnings;
use strict;
my $prev=1;
while ( <DATA> ) {
print if $prev;
chomp;
$prev = $_;
}
__DATA__
line 1
line 2
line 3
line 1
line 2
line 3
line 4
line 5
line 1
line 2
----------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Sat, 12 Dec 2009 14:18:44 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Come on Perl, rescue me one more time!
Message-Id: <nc58i5d2h67aip2alqn7ustnjc715pp31a@4ax.com>
laredotornado <laredotornado@zipmail.com> wrote:
>I'm using Perl 5.8.8 on Mac 10.5.6. I have a text file with the
>following content pattern ...
>
>(newline)
>line 1
>line 2
>line 3
>(newline)
>line 1
>line 2
>line 3
>line 4
>line 5
>(new line)
>line 1
>line 2
>
>What I would like to do is remove the first line immediately after any
>new line (carriage return) and keep all the other lines. How can I do
>this with perl?
Where are you stuck? General algorithmic idea? A specific function that
you don't know how to use? What code do you have so far that doesn't
work?
It's about a 5 line program at most. You may find
perldoc -f open
perldoc -f print
perldoc -f next
perldoc -q "change, delete"
as well as if() and while() to be helpful in your task.
jue
------------------------------
Date: Sun, 13 Dec 2009 10:23:42 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How big do your programs get before you modularise most of it?
Message-Id: <slrnhi9cku.aeu.hjp-usenet2@hrunkner.hjp.at>
On 2009-12-10 22:33, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth ccc31807 <cartercc@gmail.com>:
>> I haven't written any OO Perl, but I have written Java, and I find the
>> Java development style completely different. With Java, I will
>> decompose the requirements into classes, write the test cases for each
>> of the classes, and then write the classes. When the classes behave as
>> they ought, I'll write the main application. In essence, this turns
>> the development process I use with Perl on its head.
>
> You can do this with Perl as well, of course, and with function-based
> modules just as well as with OO modules. The key is to separate out
> pieces of your problem that can be solved (and tested) as individual,
> well-defined problems on their own.
And perl even comes with a testing framework and everybody who has ever
installed a module from CPAN has seen it in action - so I'd argue that
Perl is one of the languages which very much encourage this type of
development.
hp
------------------------------
Date: Sat, 12 Dec 2009 11:30:01 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Simple loop error
Message-Id: <qfr7i5pj0eo9b2h10m7glo1c9kvr3kplsi@4ax.com>
dan <spam.meplease@ntlworld.com> wrote:
>The following code does not print 1, because it goes from 0.81 to
>0.820000000000001. This is quite a big deal isn't it?
No, only for those, who missed the first class in Basics of Computer
Numerics:
"Thou shalt not test floating point numbers for equality"
I'm still amazed how often this topic comes up. See 'perldoc -q 999' for
a very brief introduction why this is a bad idea and otherwise check the
archives for previous discussions of this topic or a see a book about
Computer Numerics or even basic introduction about about the difference
between decimal and binary numbers.
jue
------------------------------
Date: Sat, 12 Dec 2009 13:50:53 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Simple loop error
Message-Id: <slrnhi7sqm.i2.tadmc@tadbox.sbcglobal.net>
dan <spam.meplease@ntlworld.com> wrote:
> On Sat, 12 Dec 2009 18:17:11 +0100, Dr.Ruud wrote:
>
>> dan wrote:
>>
>>> The following code does not print 1, because it goes from 0.81 to
>>> 0.820000000000001. This is quite a big deal isn't it?
>>>
>>> for ($i = 0; $i <= 1; $i += 0.01) {
>>> print "$i\n";
>>> }
>>>
>>> Using perl v5.10.0
>>
>> perldoc -q 999
>
> So something like this is necessary?
>
> for ($i = 0; $i <= 1; $i = sprintf("%.2f", $i + 0.01)) {
> print "$i\n";
> }
You would need something like
for (my $i = 0; $i <= 1; $i = sprintf("%.2f", $i + 0.01)) {
print "$i\n";
}
Since you should have "use strict" turned on in all of your Perl programs!
Necessary for what?
Necessary for whatever it is that you are doing with those numbers?
Only you can answer that.
Necessary for having the loop terminate after getting to one?
No, it is not necessary.
The standard way of dealing with an equality test of floating point
numbers is to instead test whether the number is within a (small)
range of the number you want to test for equality.
Say within one-thousandth of the number you want to test for, so:
for (my $i = 0; $i <= 1.001; $i += 0.01) {
print "$i\n";
}
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Sat, 12 Dec 2009 20:38:21 GMT
From: dan <spam.meplease@ntlworld.com>
Subject: Re: Simple loop error
Message-Id: <1bTUm.13677$o73.11042@newsfe27.ams2>
On Sat, 12 Dec 2009 16:49:12 +0000, dan wrote:
> The following code does not print 1, because it goes from 0.81 to
> 0.820000000000001. This is quite a big deal isn't it?
>
> for ($i = 0; $i <= 1; $i += 0.01) {
> print "$i\n";
> }
>
> Using perl v5.10.0
Over time I have posted a few questions to this newsgroup, and have been
impressed with the level of expertise and helpfulness of the anwers.
However with respect to this issue, a hint of hysteria has crept in to
some of the responses. Probably because to the uninitiated, it appears
that floating-point arithmetic is simply broken.
------------------------------
Date: Sat, 12 Dec 2009 16:02:40 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Simple loop error
Message-Id: <slrnhi84hp.1ji.tadmc@tadbox.sbcglobal.net>
dan <spam.meplease@ntlworld.com> wrote:
> However with respect to this issue, a hint of hysteria has crept in to
> some of the responses.
That can happen with Frequently Asked Questions.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Sat, 12 Dec 2009 14:12:51 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Simple loop error
Message-Id: <p758i5tratq9tf8kqerf4v72asua83g3kp@4ax.com>
dan <spam.meplease@ntlworld.com> wrote:
>On Sat, 12 Dec 2009 16:49:12 +0000, dan wrote:
>
>> The following code does not print 1, because it goes from 0.81 to
>> 0.820000000000001. This is quite a big deal isn't it?
>
>Over time I have posted a few questions to this newsgroup, and have been
>impressed with the level of expertise and helpfulness of the anwers.
>However with respect to this issue, a hint of hysteria has crept in to
>some of the responses. Probably because to the uninitiated, it appears
>that floating-point arithmetic is simply broken.
More like because it is the same old broken record played a gazillion
times before. And because if you are writing any code you REALLY should
know that computers are using binary arithmetic, not decimal.
jue
------------------------------
Date: Sat, 12 Dec 2009 18:15:29 -0800
From: sln@netherlands.com
Subject: Re: Simple loop error
Message-Id: <rag8i5lmepfhduk4snhbsgerp4v6se22bo@4ax.com>
On Sat, 12 Dec 2009 20:38:21 GMT, dan <spam.meplease@ntlworld.com> wrote:
>On Sat, 12 Dec 2009 16:49:12 +0000, dan wrote:
>
>> The following code does not print 1, because it goes from 0.81 to
>> 0.820000000000001. This is quite a big deal isn't it?
>>
>> for ($i = 0; $i <= 1; $i += 0.01) {
>> print "$i\n";
>> }
>>
>> Using perl v5.10.0
>
>Over time I have posted a few questions to this newsgroup, and have been
>impressed with the level of expertise and helpfulness of the anwers.
>However with respect to this issue, a hint of hysteria has crept in to
>some of the responses. Probably because to the uninitiated, it appears
>that floating-point arithmetic is simply broken.
Yes, a little hysterical.
IMO there is nothing wrong with comparing floating point numbers
and testing for equality. I would not do it any other way.
As long as you realize that you are actually comparing binary conversions
(base 2) of decimal numbars. You may get equality once in a while, however,
it may not be translatable into the equality of the original decimal.
-sln
------------
use strict;
use warnings;
my @tests = (
1.0 , 2.0 , 0.1 ,
1.0 , 10.0 , 1.0 ,
.0 , .09 , .01 ,
.7 , 1.0 , .01 ,
);
while (my ($start,$limit,$incr) = splice (@tests,0,3))
{
my $curval = $start;
my $i = $start;
for ($i = $start; $i <= $limit; $i += $incr) {
if ($curval != $i) {
print "Whoa!!, not equal ... ";
}
$curval += $incr;
print sprintf("%f", $i), "\t$i\n";
if ($i == $limit) {
print "Value equals limit ($i, $limit)\n";
}
}
print "$i\n\n";
}
__END__
1.000000 1
1.100000 1.1
1.200000 1.2
1.300000 1.3
1.400000 1.4
1.500000 1.5
1.600000 1.6
1.700000 1.7
1.800000 1.8
1.900000 1.9
2
1.000000 1
2.000000 2
3.000000 3
4.000000 4
5.000000 5
6.000000 6
7.000000 7
8.000000 8
9.000000 9
10.000000 10
Value equals limit (10, 10)
11
0.000000 0
0.010000 0.01
0.020000 0.02
0.030000 0.03
0.040000 0.04
0.050000 0.05
0.060000 0.06
0.070000 0.07
0.080000 0.08
0.090000 0.09
Value equals limit (0.09, 0.09)
0.1
0.700000 0.7
0.710000 0.71
0.720000 0.72
0.730000 0.73
0.740000 0.74
0.750000 0.75
0.760000 0.76
0.770000 0.77
0.780000 0.78
0.790000 0.79
0.800000 0.8
0.810000 0.81
0.820000 0.82
0.830000 0.83
0.840000 0.84
0.850000 0.85
0.860000 0.86
0.870000 0.87
0.880000 0.88
0.890000 0.89
0.900000 0.9
0.910000 0.91
0.920000 0.92
0.930000 0.93
0.940000 0.94
0.950000 0.95
0.960000 0.96
0.970000 0.97
0.980000 0.98
0.990000 0.99
1
------------------------------
Date: Sun, 13 Dec 2009 10:48:15 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Simple loop error
Message-Id: <slrnhi9e2v.aeu.hjp-usenet2@hrunkner.hjp.at>
On 2009-12-12 17:32, dan <spam.meplease@ntlworld.com> wrote:
> On Sat, 12 Dec 2009 18:17:11 +0100, Dr.Ruud wrote:
>
>> dan wrote:
>>
>>> The following code does not print 1, because it goes from 0.81 to
>>> 0.820000000000001.
Wrong. It goes from 0.8100000000000004973799150320701301097869873046875
to 0.8200000000000005062616992290713824331760406494140625
>>> This is quite a big deal isn't it?
>>>
>>> for ($i = 0; $i <= 1; $i += 0.01) {
>>> print "$i\n";
Change this to
printf("%.60f\n", $i);
to see what's going on.
>>> }
>>>
>>> Using perl v5.10.0
>>
>> perldoc -q 999
>
> So something like this is necessary?
>
> for ($i = 0; $i <= 1; $i = sprintf("%.2f", $i + 0.01)) {
> print "$i\n";
> }
No. Use something like this:
for (my $ii = 0; $ii <= 100; $ii++)) {
my $i = $ii / 100;
print "$i\n";
}
or more idiomatically:
for my $ii (0 .. 100) {
my $i = $ii / 100;
print "$i\n";
}
More generally, if you want to want to go from $begin to $end in $steps
steps, use:
for my $i (0 .. $steps) {
my $value = $begin + ($end - $begin) * $i / $steps;
...
}
As a general rule, with floating point arithmetic, try to avoid repeated
addition and subtraction.
hp
------------------------------
Date: Sun, 13 Dec 2009 11:03:22 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Simple loop error
Message-Id: <slrnhi9eva.aeu.hjp-usenet2@hrunkner.hjp.at>
On 2009-12-12 17:52, Bradley K. Sherman <bks@panix.com> wrote:
> In article <cQPUm.29534$3M1.8149@newsfe18.ams2>,
> dan <spam.meplease@ntlworld.com> wrote:
>>The following code does not print 1, because it goes from 0.81 to
>>0.820000000000001. This is quite a big deal isn't it?
>>
>>for ($i = 0; $i <= 1; $i += 0.01) {
>> print "$i\n";
>>}
>
> It is ancient knowledge that one does not compare IEEE Standard 754
> floating point numbers for equality.
I'd like to call this an ancient myth instead of ancient knowledge. It's
complete and utter bullshit. If you need to know whether two numbers are
equal, use ==. If you just need to know whether two numbers are similar,
compare the difference to some epsilon. That doesn't have anything to do
with whether you are using IEEE Standard 754 floating point numbers or
not. It doesn't even have anything to do with whether you are using
floating point - the same is true for fixed point or even integers. It's
just that FP numbers are typically used for values for which the exact
value is not only irrelevant but inherently unknowable, so a comparison
for equality doesn't make sense (or the other way around: If you need to
represent exact values, FP is probably the wrong type).
And it's irrelevant in this case because he *didn't* compare for
equality.
hp
------------------------------
Date: Sat, 12 Dec 2009 17:31:25 -0800
From: David Harmon <source@netcom.com>
Subject: Re: Unblessed reference.
Message-Id: <vZednbbdMMPd2bnWnZ2dnUVZ_q-dnZ2d@earthlink.com>
On Fri, 11 Dec 2009 23:28:22 +0000 in comp.lang.perl.misc, Ben Morrow
<ben@morrow.me.uk> wrote,
>
>Quoth "Newsgroup only please, address is no longer replyable." <bad@example.invalid>:
>> On Wed, 9 Dec 2009 23:10:17 +0000 in comp.lang.perl.misc, Ben Morrow
>> <ben@morrow.me.uk> wrote,
>> > In simple terms, an object is just a
>> >refrence with a bit of magic attached.
>>
>> "bit of magic attached" isn't simple terms; it's pure obfuscation.
>
>If you say so. Would you rather I said 'an object is a reference to a
>SV that is at least a PVMG, with SvSTASH set to point to the stash of
>the class it's blessed into'?
All those things, "SV", "PVMG", "SvSTASH", and "stash" are as opaque to
me as "magic".
> Perhaps you would like to provide a simple
>explanation of Perl objects, suitable for someone who hasn't met the
>concept before?
Perhaps I would, when I understand it. For now about all I get is that
the object is connected in some hidden way to the module it is "blessed"
into, so that one of the subs in that module can be located and called
when the object method call syntax is used. But that is guesswork,
coming mostly from what I think would have to happen for OOP to work,
(and coming from C++) and not from anybody's explanation.
Either that, or it is wearing a new magic hat and I have no idea what
that means. In my experience, with programming there is always a
non-magic explanation, once you find it.
Speaking of "blessed". When I was five years old, I asked a nun what
the difference was between holy water and regular water. After the
first attempt at an answer, the answer became "It's a mystery." She got
a bit upset before I figured out that "It's a mystery" means "don't ask
me any more questions." I think "magic" means the same thing, along
with "blessed", and I think those are all obfuscation.
And yes, I would prefer "SV", "PVMG", and "SvSTASH" as at least those
suggest that searching for those keywords might eventually lead to the
explanation, whereas "magic" surely will not.
------------------------------
Date: Sat, 12 Dec 2009 20:26:38 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Unblessed reference.
Message-Id: <slrnhi8k0m.2nj.tadmc@tadbox.sbcglobal.net>
David Harmon <source@netcom.com> wrote:
> On Fri, 11 Dec 2009 23:28:22 +0000 in comp.lang.perl.misc, Ben Morrow
><ben@morrow.me.uk> wrote,
>>
>>Quoth <bad@example.invalid>:
>>> On Wed, 9 Dec 2009 23:10:17 +0000 in comp.lang.perl.misc, Ben Morrow
>>> <ben@morrow.me.uk> wrote,
>>> > In simple terms, an object is just a
>>> >refrence with a bit of magic attached.
In simple terms, push down on the right pedal and the car goes faster.
>>> "bit of magic attached" isn't simple terms;
Yes it is.
>> it's pure obfuscation.
On purpose.
And that is a good thing, not a bad thing, when teaching.
If you overwhelm the student with details they will likely miss
out on grasping the important fundamentals.
So you give the simple version first, and elaborate after they
have digested that.
>>If you say so. Would you rather I said 'an object is a reference to a
>>SV that is at least a PVMG, with SvSTASH set to point to the stash of
>>the class it's blessed into'?
Would you rather I said depressing the pedal sends a SIGGAS to
the ECM, which increases the air-fuel mixture to move the engine
higher on its horsepower curve?
> All those things, "SV", "PVMG", "SvSTASH", and "stash" are as opaque to
> me as "magic".
Yet less simple.
>> Perhaps you would like to provide a simple
>>explanation of Perl objects, suitable for someone who hasn't met the
>>concept before?
>
> Perhaps I would, when I understand it.
Ben already has. (as he does understand it)
> For now about all I get is that
> the object is connected in some hidden way to the module it is "blessed"
> into, so that one of the subs in that module can be located and called
> when the object method call syntax is used. But that is guesswork,
But that is all you need to know in order to use objects.
You don't need to know how a car works in order to use a car.
If you want to know how objects are implemented or how a car works,
then "simple terms" are not what you are looking for.
> In my experience, with programming there is always a
> non-magic explanation, once you find it.
Yes, but then it won't be "simple".
> And yes, I would prefer "SV", "PVMG", and "SvSTASH"
Then you don't want it "in simple terms".
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
------------------------------
Date: Sun, 13 Dec 2009 02:49:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Unblessed reference.
Message-Id: <5b1ev6-khd.ln1@osiris.mauzo.dyndns.org>
Quoth "Newsgroup only please, address is no longer replyable." <bad@example.invalid>:
> On Fri, 11 Dec 2009 23:28:22 +0000 in comp.lang.perl.misc, Ben Morrow
> <ben@morrow.me.uk> wrote,
> >
> >Quoth "Newsgroup only please, address is no longer replyable."
> <bad@example.invalid>:
> >> On Wed, 9 Dec 2009 23:10:17 +0000 in comp.lang.perl.misc, Ben Morrow
> >> <ben@morrow.me.uk> wrote,
> >> > In simple terms, an object is just a
> >> >refrence with a bit of magic attached.
> >>
> >> "bit of magic attached" isn't simple terms; it's pure obfuscation.
> >
> >If you say so. Would you rather I said 'an object is a reference to a
> >SV that is at least a PVMG, with SvSTASH set to point to the stash of
> >the class it's blessed into'?
>
> All those things, "SV", "PVMG", "SvSTASH", and "stash" are as opaque to
> me as "magic".
Right. (I think perhaps your sarcasm detecter need recalibrating.)
> > Perhaps you would like to provide a simple
> >explanation of Perl objects, suitable for someone who hasn't met the
> >concept before?
>
> Perhaps I would, when I understand it. For now about all I get is that
> the object is connected in some hidden way to the module it is "blessed"
> into, so that one of the subs in that module can be located and called
> when the object method call syntax is used. But that is guesswork,
> coming mostly from what I think would have to happen for OOP to work,
> (and coming from C++) and not from anybody's explanation.
OK, that is pretty much right. You probably already know that every
(defined) scalar has a 'string' slot and a 'number' slot; every scalar,
array, hash, regex, sub, glob and IO also has a 'class' slot. When you
say
bless $ref, "Package";
perl dereferences $ref and sets the 'class' slot of whatever it
referenced to the symbol table of the package "Package". Later on, when
you call a method on $ref, perl starts its search for a method to use in
that package.
> And yes, I would prefer "SV", "PVMG", and "SvSTASH" as at least those
> suggest that searching for those keywords might eventually lead to the
> explanation, whereas "magic" surely will not.
Feel free to go through S_method_common in pp_hot.c in the perl
distribution until you understand what it's *actually* doing. I did, and
I learned a lot.
Ben
------------------------------
Date: Sun, 13 Dec 2009 09:31:39 +0000
From: Justin C <justin.0912@purestblue.com>
Subject: Re: Unblessed reference.
Message-Id: <rsoev6-26r.ln1@purestblue.com>
In article <5b1ev6-khd.ln1@osiris.mauzo.dyndns.org>, Ben Morrow wrote:
> OK, that is pretty much right. You probably already know that every
> (defined) scalar has a 'string' slot and a 'number' slot; every scalar,
> array, hash, regex, sub, glob and IO also has a 'class' slot. When you
> say
>
> bless $ref, "Package";
>
> perl dereferences $ref and sets the 'class' slot of whatever it
> referenced to the symbol table of the package "Package". Later on, when
> you call a method on $ref, perl starts its search for a method to use in
> that package.
>
> Feel free to go through S_method_common in pp_hot.c in the perl
> distribution until you understand what it's *actually* doing. I did, and
> I learned a lot.
I wish I'd stopped reading this thread sometime around Thursday! :)
Justin.
--
Justin C, by the sea.
------------------------------
Date: Sat, 12 Dec 2009 23:21:13 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Want to judge some remote hosts online or not quickly over WAN.
Message-Id: <slrnhi85qp.5oi.hjp-usenet2@hrunkner.hjp.at>
On 2009-12-11 19:45, Kevin Collins <spamtotrash@toomuchfiction.com> wrote:
> On 2009-12-04, smallpond <smallpond@juno.com> wrote:
>> On Dec 4, 8:28 am, Hongyi Zhao <hongyi.z...@gmail.com> wrote:
>>> I want to judge some remote hosts online or not quickly over WAN. I've
>>> learned that ping command will not work in this case if the icmp ack
>>> is blocked locally by firewall. Is it possiable for me to do this job
>>> by perl codes?
>>
>>
>> So the problem is that they are online but you aren't.
>> There is no valid reason to block ICMP packets.
>
> Really? Lots of people do...
Lots of people don't understand what they are doing.
> I believe the idea is to prevent ping floods.
To prevent ping floods you need to block ICMP echo requests to broadcast
addresses (or just don't reply to them) - blocking echo requests to
unicast adresses gains you (or the victim) nothing.
Anyway the idea is more that some people think that they can't be
attacked if they hide.
hp
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2718
***************************************