[24907] in Perl-Users-Digest
Perl-Users Digest, Issue: 7157 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 21 21:13:18 2004
Date: Tue, 21 Sep 2004 18:11:52 -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 Tue, 21 Sep 2004 Volume: 10 Number: 7157
Today's topics:
Re: anonymous hash notation question (Peter Scott)
Re: anonymous hash notation question (wana)
Re: anonymous hash notation question <noreply@gunnar.cc>
Re: anonymous hash notation question (wana)
Re: anonymous hash notation question <spamtrap@dot-app.org>
Re: anonymous hash notation question <nobull@mail.com>
Re: anonymous hash notation question <noreply@gunnar.cc>
Re: anonymous hash notation question <blgl@hagernas.com>
Re: anonymous hash notation question (Peter Scott)
Re: Best place to learn perl? <dave@dave.org.uk>
Can not print blocks to files with << <kerry@whitehouse.gov>
Re: Can not print blocks to files with << <tintin@invalid.invalid>
Re: Can not print blocks to files with << <kerry@whitehouse.gov>
Re: Can not print blocks to files with << <noreply@gunnar.cc>
Re: Can not print blocks to files with << <eric-amick@comcast.net>
Re: Closures with $_? <Joe.Smith@inwap.com>
Re: Closures with $_? ctcgag@hotmail.com
Re: Closures with $_? <usenet@morrow.me.uk>
Re: Closures with $_? <bik.mido@tiscalinet.it>
Re: Closures with $_? <bik.mido@tiscalinet.it>
Create a chinese directory (folder) by Perl in Windows (gaolixin)
Re: Create a chinese directory (folder) by Perl in Win <jurgenex@hotmail.com>
DBI question in PERL <nospam@nospam.com>
Re: DBI question in PERL <spamtrap@dot-app.org>
Re: Defining 3D array (Anno Siegel)
Device::Gsm v1.36 released to CPAN <cosimo@cpan.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 18 Sep 2004 13:47:38 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: anonymous hash notation question
Message-Id: <_%W2d.41266$%S.10835@pd7tw2no>
In article <bf0b47ca.0409170842.6f195504@posting.google.com>,
ioneabu@yahoo.com (wana) writes:
>what is the difference between:
>
>{a=>b, c=>d}
>
>and
>
>{-a=>b, -c=>d}
>
>?
>
>Specifically, what is the significance of the dash?
I believe this extract from the perlop man page addresses
your question:
Unary "-" performs arithmetic negation if the operand is
numeric. If the operand is an identifier, a string consisting
of a minus sign concatenated with the identifier is returned.
Otherwise, if the string starts with a plus or minus, a string
starting with the opposite sign is returned. One effect of
these rules is that -bareword is equivalent to "-bareword".
I also found the usage confusing until I learned of the special
case.
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
------------------------------
Date: 18 Sep 2004 10:07:43 -0700
From: ioneabu@yahoo.com (wana)
Subject: Re: anonymous hash notation question
Message-Id: <bf0b47ca.0409180907.35cea75b@posting.google.com>
ChrisO <ceo@nospam.on.net> wrote in message news:<hoO2d.19985$ZC7.9819@newssvr19.news.prodigy.com>...
> ChrisO wrote:
>
> > And with "-" in most languages, not just Perl, usually having at least
> > one special meaning (negation, urinary significance, etc.), someone with
>
> I about died laughing when I read this over again after posting it. I
> hope no one "pees" on me for spelling "unary" as "urinary" although the
> OP probably felt "peed" on and I just was reflecting that impression.
>
> Two phunny...
>
> -ceo
Thanks for your help. I know I am a relative beginner, but even with
my superficial understanding of the language, I have been able to
write some useful code. I can use the format for passing data to
objects without understanding it fully, but I like to understand what
I am doing. My reference books are 'Learning Perl' and 'Perl in a
Nutshell'. I am currently saving up for 'Programming Perl' (I got the
other two on sale).
I searched google and couldn't find anything on the subject, probably
because it is hard to look up stuff relating to the use of symbols. I
didn't totally get the concept that -a = qa, so I did a little
experiment with a method from CGI.pm:
input/output
textfield({-name=>'text'}) creates <input type="text" name="text" />
#with the -
textfield({name=>'text'}) creates <input type="text" name="text" />
#without the -
textfield({qname=>'text'}) creates <input type="text" name=""
qname="text" /> #replace - with q
textfield({q(name)=>'text'}) creates <input type="text" name="text"
/> # replace - with q(name)
by -a = qa, did you mean q as in quoting, like qw?
I am probably completely off on this one. Can you recommend a good
book that might address the issue? I did lots of searches regarding
OO in Perl, anonymous hashes, module construction etc...
Thanks again!
------------------------------
Date: Sat, 18 Sep 2004 19:33:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: anonymous hash notation question
Message-Id: <2r3a3fF157juaU1@uni-berlin.de>
wana wrote:
> Abigail wrote:
>> wana wrote:
>>> what is the difference between:
>>>
>>> {a=>b, c=>d}
>>>
>>> and
>>>
>>> {-a=>b, -c=>d}
>>>
>>> ?
>>>
>>> Specifically, what is the significance of the dash?
>>
>> Do you understand the difference between:
>>
>> {a => b, c => d}
>>
>> and
>>
>> {qa => b, qc => d}
>>
>> ?
>>
>> Do you understand the significance of the q?
>
> I searched google and couldn't find anything on the subject, probably
> because it is hard to look up stuff relating to the use of symbols. I
> didn't totally get the concept that -a = qa,
It's not. As Chris pointed out, Abigails post was sarcastic.
The '-' is not a symbol in this context. '-a' is nothing but a string
that begins with a dash followed by the character 'a'. 'a', '-a' and
'qa' are simply three different strings.
> I am probably completely off on this one. Can you recommend a good
> book that might address the issue?
There is no issue to be addressed.
Or does Peter's quote from "perldoc perlop" help you?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 18 Sep 2004 11:27:45 -0700
From: ioneabu@yahoo.com (wana)
Subject: Re: anonymous hash notation question
Message-Id: <bf0b47ca.0409181027.50414285@posting.google.com>
peter@PSDT.com (Peter Scott) wrote in message news:<_%W2d.41266$%S.10835@pd7tw2no>...
> Unary "-" performs arithmetic negation if the operand is
> numeric. If the operand is an identifier, a string consisting
> of a minus sign concatenated with the identifier is returned.
> Otherwise, if the string starts with a plus or minus, a string
> starting with the opposite sign is returned. One effect of
> these rules is that -bareword is equivalent to "-bareword".
>
> I also found the usage confusing until I learned of the special
> case.
Thank you, thank you!
------------------------------
Date: Sat, 18 Sep 2004 14:41:02 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: anonymous hash notation question
Message-Id: <_c-dnWwvbZGiHNHcRVn-iw@adelphia.com>
Gunnar Hjalmarsson wrote:
> It's not. As Chris pointed out, Abigails post was sarcastic.
>
> The '-' is not a symbol in this context. '-a' is nothing but a string
> that begins with a dash followed by the character 'a'. 'a', '-a' and
> 'qa' are simply three different strings.
To put it another way: The behavior that you've observed is part of the
CGI module, which recognizes and removes a leading '-' from keys used as
method arguments. Other modules are not required to do the same, and
many in fact do not.
To the core Perl language, those are just ordinary hash keys, nothing
special at all - '-b' is no more special than 'qb'.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sun, 19 Sep 2004 22:24:07 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: anonymous hash notation question
Message-Id: <cikt5m$2cf$1@sun3.bham.ac.uk>
Gunnar Hjalmarsson wrote:
> The '-' is not a symbol in this context. '-a' is nothing but a string
> that begins with a dash followed by the character 'a'. 'a', '-a' and
> 'qa' are simply three different strings.
This is incorrect.
The '-' in this case is a unary operator.
The => causes the word (thats just the 'a') to the left to be quoted so
-a => 'b'
is interpreted as
- 'a' => 'b'
The unary minus applied to a string prepends a minus (unless the string
already starts with a minus - in which case it removes it).
------------------------------
Date: Mon, 20 Sep 2004 00:22:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: anonymous hash notation question
Message-Id: <2r6f2uF16ji3uU1@uni-berlin.de>
Brian McCauley wrote:
> Gunnar Hjalmarsson wrote:
>> The '-' is not a symbol in this context. '-a' is nothing but a
>> string that begins with a dash followed by the character 'a'.
>> 'a', '-a' and 'qa' are simply three different strings.
>
> This is incorrect.
>
> The '-' in this case is a unary operator.
So it seems; thanks for pointing it out. The reason why I didn't
realize it until now is probably that you need rather weird examples
to observe it, such as:
my %hash = (-'-a' => 'b');
print keys %hash, "\n";
Outputs:
+a
> The => causes the word (thats just the 'a') to the left to be
> quoted so
>
> -a => 'b'
>
> is interpreted as
>
> - 'a' => 'b'
>
> The unary minus applied to a string prepends a minus (unless the
> string already starts with a minus - in which case it removes it).
Actually, the latter seems to also be incorrect. It doesn't remove it,
but it replaces it with a plus.
print join "\n", -'-one', -'+two';
Outputs:
+one
-two
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 20 Sep 2004 02:45:22 +0200
From: Bo Lindbergh <blgl@hagernas.com>
Subject: Re: anonymous hash notation question
Message-Id: <blgl-6475EE.02452120092004@news.bahnhof.se>
In article <_%W2d.41266$%S.10835@pd7tw2no>,
peter@PSDT.com (Peter Scott) wrote:
> I believe this extract from the perlop man page addresses
> your question:
>
> Unary "-" performs arithmetic negation if the operand is
> numeric. If the operand is an identifier, a string consisting
> of a minus sign concatenated with the identifier is returned.
> Otherwise, if the string starts with a plus or minus, a string
> starting with the opposite sign is returned. One effect of
> these rules is that -bareword is equivalent to "-bareword".
>
> I also found the usage confusing until I learned of the special
> case.
The exact meaning of "is numeric" is still confusing. Example:
sub analyze (@)
{
foreach (@_) {
print STDERR "Negate\t",$_,"\tto get\t",-$_,"\n";
}
}
my($pos,$neg,$num,$bare)=('+1.0','-1.0','1.0','zero');
analyze($pos,$neg,$num,$bare);
print "Add them all to get\t",$pos+$neg+$num+$bare,"\n";
analyze($pos,$neg,$num,$bare);
------------------------------
Date: Mon, 20 Sep 2004 13:57:59 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: anonymous hash notation question
Message-Id: <HlB3d.58454$%S.18260@pd7tw2no>
In article <blgl-6475EE.02452120092004@news.bahnhof.se>,
Bo Lindbergh <blgl@hagernas.com> writes:
>The exact meaning of "is numeric" is still confusing. Example:
>
>sub analyze (@)
>{
> foreach (@_) {
> print STDERR "Negate\t",$_,"\tto get\t",-$_,"\n";
> }
>}
>
>my($pos,$neg,$num,$bare)=('+1.0','-1.0','1.0','zero');
>
>analyze($pos,$neg,$num,$bare);
>print "Add them all to get\t",$pos+$neg+$num+$bare,"\n";
>analyze($pos,$neg,$num,$bare);
Yes, it is possible to play tricks with Perl's DWIMmer.
Fortunately, real programs that fall afoul of this
behavior accidentally are extremely rare. I tried to
imagine how that could happen and gave up.
(Your example is even stronger without $bare, because
that does at least trigger a "not numeric" warning on
the first usage.)
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
------------------------------
Date: Sat, 18 Sep 2004 09:01:18 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Best place to learn perl?
Message-Id: <pan.2004.09.18.08.01.18.80284@dave.org.uk>
On Fri, 17 Sep 2004 15:40:01 +0200, Daniel Wimpff wrote:
> ft4bredn wrote:
> > Do you know of any books or whatever that break things down like
> that? > Expert explanation man!!
>
> I recommend the book "Programming Perl, 2nd edition" (or a newer if
> exists), O'Reilly & Associates, Inc., Larry Wall, Tom Christiansen &
> Randal L. Schwartz.
The third edition (by Wall, Christiansen and Orwant) has been out for many
years.
Dave...
------------------------------
Date: Sat, 18 Sep 2004 09:39:10 GMT
From: "WH" <kerry@whitehouse.gov>
Subject: Can not print blocks to files with <<
Message-Id: <2nT2d.6028$1Ko.2636@news04.bloor.is.net.cable.rogers.com>
print << 'okok';
lalala
okok
works fine, but with I try to do the same thing to write to a file
print $OUTPUTFILE << 'okok';
lalala
okok
not working
------------------------------
Date: Sat, 18 Sep 2004 21:49:35 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Can not print blocks to files with <<
Message-Id: <2r2ek6F152kj8U1@uni-berlin.de>
"WH" <kerry@whitehouse.gov> wrote in message
news:2nT2d.6028$1Ko.2636@news04.bloor.is.net.cable.rogers.com...
> print << 'okok';
> lalala
>
> okok
>
> works fine, but with I try to do the same thing to write to a file
>
>
> print $OUTPUTFILE << 'okok';
> lalala
>
> okok
>
> not working
"Not working" is a poor description of the problem. It would have been
better if you gave the actual error message generated, ie:
Can't use an undefined value as a symbol reference at foo line 1.
Anyway, move the $ from the filehandle and assuming you opened the file
correctly, you'll be fine.
------------------------------
Date: Sat, 18 Sep 2004 09:52:31 GMT
From: "WH" <kerry@whitehouse.gov>
Subject: Re: Can not print blocks to files with <<
Message-Id: <zzT2d.6029$1Ko.946@news04.bloor.is.net.cable.rogers.com>
> > print << 'okok';
> > lalala
> >
> > okok
> >
> > works fine, but with I try to do the same thing to write to a file
> >
> >
> > print $OUTPUTFILE << 'okok';
> > lalala
> >
> > okok
> >
> > not working
>
> "Not working" is a poor description of the problem. It would have been
> better if you gave the actual error message generated, ie:
>
> Can't use an undefined value as a symbol reference at foo line 1.
>
> Anyway, move the $ from the filehandle and assuming you opened the file
> correctly, you'll be fine.
>
$ has nothing to do with it, as my handle has $. but I fixed it. here is the
current code
print {$OUTPUT} << "header";
I have to {} the output handle. don't know why.
------------------------------
Date: Sat, 18 Sep 2004 11:56:14 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Can not print blocks to files with <<
Message-Id: <2r2f8cF15s0faU1@uni-berlin.de>
WH wrote:
> print << 'okok';
> lalala
>
> okok
>
> works fine, but with I try to do the same thing to write to a file
>
>
> print $OUTPUTFILE << 'okok';
> lalala
>
> okok
>
> not working
To not confuse the print() function you can do
print $OUTPUTFILE (<< 'okok');
or
print $OUTPUTFILE <<'okok'; # space after '<<' removed
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 18 Sep 2004 22:44:28 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Can not print blocks to files with <<
Message-Id: <jespk05mj6s79reo46eebc8e265ammq5u3@4ax.com>
On Sat, 18 Sep 2004 09:52:31 GMT, "WH" <kerry@whitehouse.gov> wrote:
>
>$ has nothing to do with it, as my handle has $. but I fixed it. here is the
>current code
>
>print {$OUTPUT} << "header";
>
>I have to {} the output handle. don't know why.
More than likely because
$xyz << "abc"
looks like you're using the left shift operator. Putting curly brackets
around the filehandle makes your intent clear.
--
Eric Amick
Columbia, MD
------------------------------
Date: Sun, 19 Sep 2004 04:16:03 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Closures with $_?
Message-Id: <7K73d.73332$D%.28120@attbi_s51>
Michele Dondi wrote:
> I have not included any technical difficulty, just *evidence* that
> closures are supported only as far as lexical variables are concerned.
> But I don't know why, because I don't know perl internals.
Closures require at least one lexical variable.
Otherwise it would not be able to distinguish one closure from another.
Just accept the restriction that closures need lexical variables and
move on.
-Joe
------------------------------
Date: 19 Sep 2004 04:42:19 GMT
From: ctcgag@hotmail.com
Subject: Re: Closures with $_?
Message-Id: <20040919004219.227$U9@newsreader.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> >> So I wonder wether, apart possible technical difficulties, there are
> >> other issues against the possibility of having closures using $_.
> >
> >I don't understand what you include in "possible technical
> >difficulties", and therefore don't know what issues there are other than
> >the ones you already include.
>
> I have not included any technical difficulty, just *evidence* that
> closures are supported only as far as lexical variables are concerned.
Maybe I'm overstepping my knowledge, or getting bogged down in semantics,
but I would say that closures are supported for all variables. It is just
that closures are kind of trivial when they don't include any lexical
variables.
> But I don't know why, because I don't know perl internals. So in
> "possible technical difficulties" I include *any* reason p5p's may
> give for e.g.
>
> map { sub { $_ } } qw/f o o/;
Here, $_ is the same variable each time the sub is defined, so all
three subs are effectively equivalent. (The perl implementation is
smart enough to realize this, and makes them exactly equivalent, not
just effectively equivalent; but that is just an optimization, not
a fundamental difference).
The problem you were having is that you kept overwriting the value of
$_ between the time the sub was defined and the time it was used.
> not being equivalent to (the clumsier)
>
> map { my $t=$_; sub { $t } } qw/f o o/;
Here, $t is a different variable each time the sub is defined, so each of
the resultant closures are different. Each one contains a (different)
internal reference to a (different) now-anonymous variable, formerly known
as $t.
The fact that the closure contains a reference to the variables formerly
known as $t keeps the ref counts above zero, so those variables can't
disappear as long as the closures themselves are around. (This point is
irrelevant to package variables, since they don't disappear anyway until
the end of the program anyway.) Furthermore, the closures' references are
the only references to those variables, once you leave the scope of the map
block, so the variables are unlikely to get stepped on like $_ was.
If you change the code just a bit by taking the "my" out of the loop:
my $t;
print map {$_->()} map { $t=$_; sub { $t } } qw/f o o/;
Now, each closures refers to the same $t, just as like in your first case
they all refer to the same $_. All of the subs are effectively equivalent
(but the perl implementation doesn't realize this, so each coderef has a
different address). And that one variable $t gets walked all over, but not
as badly as $_ did in the first example.
to make it even more like the first example:
my $t;
print map {$t=$_; $_->()} map { $t=$_; sub { $t } } qw/f o o/;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Sat, 18 Sep 2004 23:46:36 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Closures with $_?
Message-Id: <cfqu12-7c4.ln1@osiris.mauzo.dyndns.org>
Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> So I wonder wether, apart possible technical difficulties, there are
> other issues against the possibility of having closures using $_.
A closure has to use lexical variables (only), because it relies on the
closure being called *after the variables it closes on have gone out of
(normal) scope*. Globals don't need closures: they are always in scope
anyway. Consider:
{
my $x = 4;
sub foo {
my $y = $x;
$x = shift;
return $y;
}
}
foo 3;
When foo is called, it can get at the lexical $x *even though it has
gone out of scope*, because it is a closure. If $x was a global, there
would be no need for closure: $x is always available from anywhere.
You are perhaps not thinking of this sub foo as a closure; it is,
however. The situation you probably have in mind:
my @a;
for my $x (1..4) {
push @a, sub { $x };
}
print map $_->(), @a;
is slightly more complicated because the scope that is the 'for' loop
runs four times, and each one is *a completely separate scope* from the
others. That is, there are four different variables named '$x' which do
not affect one another, just as there are two here:
{
$x = 1;
}
{
print $x;
}
.
So (and I apologise if you actually understood all this already, but I
got the impression from your example that you didn't), you question is
not 'can closures be made to close on $_' but rather 'can $_ be made
lexical'. The answer to that is that it could except it would break
programs expecting it to be global, so it won't happen till Perl6 (where
$_ is, indeed, lexical, and thus closed upon by closures).
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Sun, 19 Sep 2004 17:42:26 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Closures with $_?
Message-Id: <7igqk0t1ari0spdp3ri9j8nhtu4lf9c3cc@4ax.com>
On 19 Sep 2004 04:42:19 GMT, ctcgag@hotmail.com wrote:
>> I have not included any technical difficulty, just *evidence* that
>> closures are supported only as far as lexical variables are concerned.
>
>Maybe I'm overstepping my knowledge, or getting bogged down in semantics,
>but I would say that closures are supported for all variables. It is just
>that closures are kind of trivial when they don't include any lexical
>variables.
This is what I meant.
[lengthy explanation snipped]
TY for the explanation.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 20 Sep 2004 16:43:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Closures with $_?
Message-Id: <97gtk0hv17qgjbfun7a24mt9ccdetqcvpp@4ax.com>
On Sat, 18 Sep 2004 23:46:36 +0100, Ben Morrow <usenet@morrow.me.uk>
wrote:
>So (and I apologise if you actually understood all this already, but I
I'd say that I "sort of" understood all this in the sense that (IMHO)
I already knew all this much better than I may have given the
impression of. Said this, other posters already made the point and
clarified things up, so in some sense yes: your explanation was
redundant. But you know: repetita iuvant! And all this may be helpful
for others too.
>got the impression from your example that you didn't), you question is
>not 'can closures be made to close on $_' but rather 'can $_ be made
>lexical'. The answer to that is that it could except it would break
>programs expecting it to be global, so it won't happen till Perl6 (where
Indeed I'm aware that hoping for $_ to be made lexical would be too
much. And to be fair I wouldn't regard it as a Good Thing(TM), from a
Perl5's perspective.
Rather I wonder wether, apart possible technical difficulties (as of
my OP), it would be possible to add still some more magic to $_ in
order to make it behave like it were a lexical var in all those
situations in which something is automatically aliased to it (i.e.
C<for>, C<map>, etc.)
After all
map { "\$_=<$_>" } @input;
and
map { my $t=$_; "\$_=<$t>" } @input;
are perfectly equivalent, so I *think* that one could reasonably
wonder why
map { sub { $_ } } @input;
and
map { my $t=$_; sub { $t } } @input;
are not. Then the answer, as you all have been explaining and
stressing, is that (to sum up as briefly as possible) "a sub is not a
string, period". But then there are situations when one would want to
achieve the effect of the second example while I can't see any actual
use for the first. So IMHO it would be a big, typically perlish
dwimmery to have the first one behave like the second one.
Thanks,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 21 Sep 2004 15:51:57 -0700
From: gaolixin@yahoo.com (gaolixin)
Subject: Create a chinese directory (folder) by Perl in Windows 2000 English OS
Message-Id: <b58edc1e.0409211451.1da554e0@posting.google.com>
I am a perl newbie, and I am trying to use a perl program to create a
folder in Window2000. My WINDOWS 2000 is English OS, but setup using
Chinese (PRC) as default locale. I am able to create chinese folders
manually, and able to view them.
The perl program has a statment like
use strict; $|++;
my $VERSION = "1.0";
use File::Spec::Functions;
...
mkdir $dirpath;
where $dirpath has chinese chars inside using GB2312 encoding. It
created a folder but the chinese not readiable .
Can anybody help me through, can you give me a sample program? Thanks
a lot!!!
Thanks, Lixin
------------------------------
Date: Tue, 21 Sep 2004 23:37:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Create a chinese directory (folder) by Perl in Windows 2000 English OS
Message-Id: <qX24d.3324$C8.1973@trnddc05>
gaolixin wrote:
> I am a perl newbie, and I am trying to use a perl program to create a
> folder in Window2000. My WINDOWS 2000 is English OS, but setup using
> Chinese (PRC) as default locale. I am able to create chinese folders
> manually, and able to view them.
>
> The perl program has a statment like
>
> use strict; $|++;
> my $VERSION = "1.0";
> use File::Spec::Functions;
> ...
> mkdir $dirpath;
>
> where $dirpath has chinese chars inside using GB2312 encoding. It
> created a folder but the chinese not readiable .
You may want to try using UTF-16 instead of GB2312 because internally Win2k
is based on Unicode.
jue
------------------------------
Date: Sun, 19 Sep 2004 19:55:10 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: DBI question in PERL
Message-Id: <1095638141.295298@nntp.acecape.com>
soemtimes when i do a mysql select command, instead of getting zero for
$matches, i get this:
4294967294
what gives?
------------------------------
Date: Sun, 19 Sep 2004 20:31:57 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: DBI question in PERL
Message-Id: <1bednfe9Rt1gudPcRVn-qQ@adelphia.com>
daniel kaplan wrote:
> soemtimes when i do a mysql select command, instead of getting zero for
> $matches, i get this:
>
> 4294967294
>
> what gives?
The number itself is -1 being mistakenly treated as an unsigned int.
If I recall correctly, MySQL reports -1 rows returned when an error
occurred. Try checking to see what the errstr() method gives you, or
using the RaiseError option when you connect.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 20 Sep 2004 06:57:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Defining 3D array
Message-Id: <cilv1l$ek9$1@mamenchi.zrz.TU-Berlin.DE>
Duke of Hazard <squash@peoriadesignweb.com> wrote in comp.lang.perl.misc:
> I have searched google, but could not find an answer for how to define
> a 3D array manually. Here is the code:
>
> $schedule[0]= (
> ["0", "0", "0","0"],
> ["0", "0", "0","0"],
> );
>
> $schedule[1]= (
> ["0", "0", "0","0"],
> ["0", "0", "0","0"],
> );
>
> The problem is $schedule[$i][$j][$k] are all undefined for any values
> of i,j, and k?
Switch on strictures and warnings and run it again.
Anno
------------------------------
Date: Wed, 15 Sep 2004 22:23:58 GMT
From: Cosimo Streppone <cosimo@cpan.org>
Subject: Device::Gsm v1.36 released to CPAN
Message-Id: <I49Du0.1G7M@zorch.sf-bay.org>
Version 1.36 of Device::Gsm perl extension has been released to CPAN,
and should be available at your local CPAN mirror in a day or two.
Changes
-------------
1.34 => 1.36
Wed Sep 15 23:43:02 CEST 2004
- finally added encoding/decoding of sms text between
8 bit ASCII (ISO-8859) and 7 bit GSM 03.38
(thanks to Stefano Pisani for his feedback)
What it is?
------------
Device::Gsm is perl extension to talk to your gsm mobile phone
via serial port, bluetooth, irda, ... and reads/writes sms messages,
reads battery level, signal, imei(serial) number, makes calls,
and everything is allowed by the GSM AT+C command set.
It works at least on Windows, Linux, Solaris and *BSD systems.
Prerequisites
-------------
+ working perl installation >= 5.005_03
+ Device::Modem (most recent version is fine)
+ Device::SerialPort (or Win32::SerialPort for Windows systems)
+ a gsm mobile phone, or oem device, compliant with AT+C GSM
command set (nearly every model is AT+C compliant)
Installation
------------
This module installs like all other good old perl modules:
$ perl Makefile.PL
$ make
$ make test
$ make install
Licensing terms
---------------
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
Use it at your own risk, and without ANY warranty!
For any need of commercial support and/or licensing, please contact
me directly: Cosimo Streppone <cosimo@cpan.org>
------------------------------
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 7157
***************************************