[26093] in Perl-Users-Digest
Perl-Users Digest, Issue: 8293 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 30 14:05:19 2005
Date: Sat, 30 Jul 2005 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 Sat, 30 Jul 2005 Volume: 10 Number: 8293
Today's topics:
Re: Extract lines by name <tadmc@augustmail.com>
Re: Extract lines by name <dreamer@cox.net>
Re: Help with overload. (Anno Siegel)
How does one find what PL_stack_sp is? <socyl@987jk.com.invalid>
Re: Passing vars to a "require"d script <klaus_gb@yahoo.com>
Re: PERL vs. Ruby <abigail@abigail.nl>
Re: PERL vs. Ruby <socyl@987jk.com.invalid>
Re: true false ? : expression thingy <abigail@abigail.nl>
Re: true false ? : expression thingy <abigail@abigail.nl>
Re: Where to ask mysql questions? <abigail@abigail.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 30 Jul 2005 07:54:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Extract lines by name
Message-Id: <slrndemu3f.4a5.tadmc@magna.augustmail.com>
Fred Hare <dreamer@cox.net> wrote:
> Jim Gibson wrote:
>> push( @{$text{$1}}, $_ );
^^^^^^^^^^^
^^^^^^^^^^^ 2 open curlies, 2 close curlies
> Jim, I tried jour suggested code im my script
That may have been your intention, but I think you were not using
that exact code.
When you put it into your Perl program, did you copy/paste it,
or did you (attempt to) retype it?
> and I got a Perl error
> message:
>
> Scalar value @{text{$1} better written as ${text{$1} at sort.pl line 18.
^^^^^^^^^
^^^^^^^^^ 2 open curlies, *1* close curly!
(don't retype messages either, use copy/paste to avoid introducing typos.)
That one is not an error message. It is a warning message.
You can look up both error and warning messages in:
perldoc perldiag
> Type of arg 1 to push must be array (not hash slice) at sort.pl line 18,
> near "$_) "
To help fix a syntax error, we will need to see the *exact* code that
produced the error.
If you post a short and complete program that we can run that demonstrates
your problem, someone here can surely help you fix the problem.
> I tried a few changes
Try it _without_ changes first.
Jim's code works fine for me.
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 30 Jul 2005 18:42:03 +0200
From: Fred Hare <dreamer@cox.net>
Subject: Re: Extract lines by name
Message-Id: <R8adnb9y1-5AMHbfRVnytQ@giganews.com>
Tad McClellan wrote:
> Fred Hare <dreamer@cox.net> wrote:
>
>>Jim Gibson wrote:
>
>
>>> push( @{$text{$1}}, $_ );
>
> ^^^^^^^^^^^
> ^^^^^^^^^^^ 2 open curlies, 2 close curlies
>
>
>>Jim, I tried jour suggested code im my script
>
>
>
> That may have been your intention, but I think you were not using
> that exact code.
>
> When you put it into your Perl program, did you copy/paste it,
> or did you (attempt to) retype it?
>
>
>
>>and I got a Perl error
>>message:
>>
>>Scalar value @{text{$1} better written as ${text{$1} at sort.pl line 18.
>
> ^^^^^^^^^
> ^^^^^^^^^ 2 open curlies, *1* close curly!
>
> (don't retype messages either, use copy/paste to avoid introducing typos.)
>
>
> That one is not an error message. It is a warning message.
>
> You can look up both error and warning messages in:
>
> perldoc perldiag
>
>
>
>>Type of arg 1 to push must be array (not hash slice) at sort.pl line 18,
>>near "$_) "
>
>
>
> To help fix a syntax error, we will need to see the *exact* code that
> produced the error.
>
> If you post a short and complete program that we can run that demonstrates
> your problem, someone here can surely help you fix the problem.
>
>
>
>>I tried a few changes
>
>
>
> Try it _without_ changes first.
>
> Jim's code works fine for me.
>
>
>
> Have you seen the Posting Guidelines that are posted here frequently?
>
Very embarassing - I typed where I should have pasted ...
Jim's code works fine as posted and also when used in my script
-- Fred
------------------------------
Date: 30 Jul 2005 16:06:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help with overload.
Message-Id: <dcg8j2$rmb$1@mamenchi.zrz.TU-Berlin.DE>
Ignoramus27279 <ignoramus27279@NOSPAM.27279.invalid> wrote in comp.lang.perl.misc:
> Just a pointer to a perl manpage would be great.
You have been pointed to the overload man page.
> I am looking to write a bunch of modules on which to perform
> operations like addition etc.
>
> The modules would represent objects such as constants (1, 2/3, pi/2,
> etc), as well as polynomials and general math functions.
Oh. Good luck!
> What I would like is to overload operations so that I could "drop in"
> the values of that type into existing subroutines.
Well, that's what overloading is for.
> Suppose that I already have a subroutine
>
> sub myGreatComputation {
> my ($a, $b) = @_.
> # do big stuff with arithmetics on $a and $b
> }
Exactly, that's how it is supposed to work.
> is there some way to define my new module so that other subroutines
> that do arithmetics would work properly when passed objects of that
> module rather than regular scalar values, without rewriting that
> subroutine?
The class ModArith below implements modular integer arithmetic using
overload. While that's a little less ambitious than your project, the
basic structure is the same. The "general-purpose" routine factorial()
calculates plain or modular factorials, depending only on the nature
of the input. Since the class ModArith doesn't implement subtraction,
factorial() is written a bit funny ("$n = $n + -1" instead of "-- $n"),
but that's a deficiency of the example, not of the general principle.
my @elem = map ModArith->new( $_), 0 .. 6;
print "Addition:\n";
for my $l ( @elem ) {
my @sums = map $l + $_, @elem;
print "@sums\n";
}
print "\nMultiplication:\n";
for my $l ( @elem ) {
my @prods = map $l * $_, @elem;
print "@prods\n";
}
print "\nFactorial:\n";
for ( 1 .. 5 ) {
my $fac = factorial( $_);
my $modfac = factorial( ModArith->new( $_));
print "$_ : $modfac ($fac)\n";
}
sub factorial {
my $n = shift;
my $res = 1;
while ( $n ) {
$res *= $n;
$n = $n + -1; # in deference to incomplete implementation
}
$res;
}
########################################################################
package ModArith;
use constant MODULUS => 7;
use overload (
'""' => 'value',
'bool' => 'value',
'+' => 'add',
'*' => 'multiply',
);
sub new {
my ( $class, $num) = @_;
bless \ $num, $class;
}
sub value { ${ $_[ 0]} % MODULUS } # subclass and override to change modulus
sub add {
my ( $self, $other) = @_;
my $op = ref $other ? $other->value : $other;
ref( $self)->new( $self->value + $op);
}
sub multiply {
my ( $self, $other) = @_;
my $op = ref $other ? $other->value : $other;
ref( $self)->new( $self->value * $op);
}
__END__
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Sat, 30 Jul 2005 17:42:29 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: How does one find what PL_stack_sp is?
Message-Id: <dcge65$dc5$1@reader2.panix.com>
I'm *astonished* anyone other than the authors can understand the
Perl source. How can *anyone* navigate this maze? It's insane.
(And how can the Perl community defend itself against the common
charge of Perl's unreadability, when all a critic needs to do is
point to the Perl source itself for an unparalleled example of
illegibility? Granted, the Perl source is not written in Perl,
but it is obviously written by people who don't give a fig about
the readability of the code. All the piousness in the umpteen Perl
style guides begins to ring hollow after one takes a look at the
Perl source.)
I've spent a couple of hours (and 100% of my patience) trying to
find what PL_stack_sp is. This is just *one* identifier out of
thousands in the Perl source. At this rate it will take me many
months of solid work to have a sense of where things are *defined*,
let alone figuring out what they do or how they're used.
And yes, I grepped "stack_sp" in perlxstut, perlxs, perlapi, and
perlguts, and pored over Extending and Embedding Perl by Jenness
and Cozens.
The best I was able to find (and purely by random accident, BTW)
is that it is a macro defined in perlapi.h as
(*Perl_Tstack_sp_ptr(aTHX))
Great. More wild goose chases ahead. I have not been able to find
where aTHX is defined. I looked in perlapi.h, and in all the files
#include'd in it, and all the files included by those, etc. Plus
a huge list of other files (configuration files, make files, etc.),
too long to fully enumerate. aTHX is not even mentioned in any of
these.
Doing a recursive grep for Perl_Tstack_sp_ptr in the Perl source
turns up *nothing*, other than the occurrences of this identifier
in the RHS of some definitions (such as PL_stack_sp) in perlapi.h.
So, after hours of searching all I know is that PL_stack_sp is
defined in terms of things I cannot find definitions for.
OK, so what's the trick? How does one navigate this insanity?
Thanks!
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Sat, 30 Jul 2005 19:22:31 +0100
From: "Klaus Eichner" <klaus_gb@yahoo.com>
Subject: Re: Passing vars to a "require"d script
Message-Id: <42ebb5cd$0$14891$626a14ce@news.free.fr>
"Bigus" <personage@myabode.com> wrote in message
news:42eb3dea$0$91525$ed2e19e4@ptn-nntp-reader04.plus.net...
>
> "Klaus Eichner" <klaus_gb@yahoo.com> wrote in message
> news:42ea5707$0$5043$636a15ce@news.free.fr...
> > You can always define your own variables with "our" to pass values,
like:
> > our @param = ('?', '123');
> >
> > Then, inside "/admin/scripts/live/otherscript.pl"
> > our @param;
>
> thanks, that works nicely :)
>
> I had read an article on our() but it didn't mention you had to use our()
> again in "receiving" script. I thought it must make it global to
everything.
>
> Bigus
I can understand what you are saying.
It took me a long time to realise that "my()" and "our()" -- although
similar in a sense that they both declare variables within the enclosing
block, file or eval -- are working rather differently.
"my()" creates a new variable every time it is called, but "our()" doesn't
really do anything, other than allowing access to a global variable. (you
don't even need "our()" at all if you don't "use strict" in your script
! ) -- in particular: a simple "our()" does not make a global variable, it
is the subsequent assignment which makes the global variable.
Therefore, multiple "our()'s" of the same variable in different blocks (or
files, for that matter) really refer to one unique global variable.
--
Klaus
------------------------------
Date: 30 Jul 2005 15:14:13 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: PERL vs. Ruby
Message-Id: <slrnden6a5.7fo.abigail@alexandra.abigail.nl>
Ralph H. Stoos Jr. (rstoos@rochester.rr.com) wrote on MMMMCCCLI September
MCMXCIII in <URL:news:icCGe.616$0m1.326@twister.nyroc.rr.com>:
[] All,
[]
[] I have taken a company sponsored course in PERL taught by a fellow
[] system engineer. He tried his best but, I am still an old dog and
[] well.. that new tricks thing seems to apply.
[]
[] It seems that all courses I find assume you have other programming
[] experience either in C, C++, or Java. Since I have none of these
[] skills, I am hoping to somehow pick up an OOP language.
[]
[] So, I have folks recommending Ruby over PERL as a good language on which
[] to cut my coding teeth.
[]
[] Any opinions on the subject would be appreciated.
I'd go for Python if I were you.
[] Please reply to the newsgroup and also to rstoos@rochester.rr.com so I
[] can get it right away.
No.
[] The next "intermediate" course starts in three
[] days. I will attend it regardless but, would like to know if this is
[] the best way to go for my first foray into programming.
If you're on "old dog", you ought to know how Usenet works.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54";
print if s/<<EOT/<<EOT/e;
Just another Perl Hacker
EOT
------------------------------
Date: Sat, 30 Jul 2005 16:36:27 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: PERL vs. Ruby
Message-Id: <dcgaab$cvo$1@reader2.panix.com>
In <slrnden6a5.7fo.abigail@alexandra.abigail.nl> Abigail <abigail@abigail.nl> writes:
>I'd go for Python if I were you.
Why do you prefer Python over Ruby?
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: 30 Jul 2005 15:17:09 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: true false ? : expression thingy
Message-Id: <slrnden6fl.7fo.abigail@alexandra.abigail.nl>
John W. Kennedy (jwkenne@attglobal.net) wrote on MMMMCCCLI September
MCMXCIII in <URL:news:71CGe.2716$7Q1.1993@fe09.lga>:
!! Ian Wilson wrote:
!! >
!! > What's so horrible about
!! > if (condition) {$this="foo";} else {$this="bar"}
!! > which I find quite readable?
!!
!! For one thing, you can't use it as an alternative to:
!!
!! my $this = condition ? "foo" : "bar";
my $this = do {if (condition) {"foo"} else {"bar"}};
HTH. HAND.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: 30 Jul 2005 15:20:36 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: true false ? : expression thingy
Message-Id: <slrnden6m4.7fo.abigail@alexandra.abigail.nl>
John W. Krahn (someone@example.com) wrote on MMMMCCCLI September MCMXCIII
in <URL:news:oTEGe.162969$9A2.73587@edtnps89>:
__ John W. Kennedy wrote:
__ > Ian Wilson wrote:
__ >> Bigus wrote:
__ >>
__ >>> when you want a
__ >>> 1-line alternative to an if...else.. construct,
__ >>
__ >>
__ >> Whilst I quite like
__ >> $this = condition ? "foo" : "bar";
__ >>
__ >> What's so horrible about
__ >> if (condition) {$this="foo";} else {$this="bar"}
__ >> which I find quite readable?
__ >
__ > For one thing, you can't use it as an alternative to:
__ >
__ > my $this = condition ? "foo" : "bar";
__ >
__ > And it is more economical in a case like:
__ >
__ > $x[$i + $j - 1] = condition ? "foo" : "bar";
__
__ And don't forget you can use it as an lvalue as in:
__
__ ( condition ? $foo : $bar ) = $this;
${;do {if (condition) {\$foo} else {\$bar}}} = $this;
__ Or:
__
__ push @{ condition ? \@foo : \@bar }, $this;
push @{;do {if (condition) {\@foo} else {\@bar}}}, $this;
It ain't pretty, but you can replace ?: with 'if'.
Abigail
--
END {print "Hacker\n"}
CHECK {print "another "}
BEGIN {print "Just " }
INIT {print "Perl " }
------------------------------
Date: 30 Jul 2005 15:29:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Where to ask mysql questions?
Message-Id: <slrnden76o.7fo.abigail@alexandra.abigail.nl>
fishfry (BLOCKSPAMfishfry@your-mailbox.com) wrote on MMMMCCCLI September
MCMXCIII in <URL:news:BLOCKSPAMfishfry-1C4C7F.19553529072005@comcast.dca.giganews.com>:
[] I couldn't find a mysql newsgroup. Where is the appropriate place to ask
[] mysql questions that aren't Perl-related?
I'd say, go to alt.binaries.pictures.furniture, and ask again.
Abigail
--
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";
------------------------------
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 8293
***************************************