[24931] in Perl-Users-Digest
Perl-Users Digest, Issue: 7181 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 27 06:07:05 2004
Date: Mon, 27 Sep 2004 03:05:09 -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 Mon, 27 Sep 2004 Volume: 10 Number: 7181
Today's topics:
Re: best way to search perldocs <jurgenex@hotmail.com>
Re: best way to search perldocs <abigail@abigail.nl>
Re: best way to search perldocs <Joe.Smith@inwap.com>
Re: Can't locate module despite 'use lib' (David Efflandt)
Re: Can't locate module despite 'use lib' <uri@stemsystems.com>
Determine weekends and compare two days (Prak)
Re: Determine weekends and compare two days <jds@atavailcheck.com>
Re: few question about array <Joe.Smith@inwap.com>
Re: path delimiter in windows platform("/" could change <end@dream.life>
Re: path delimiter in windows platform("/" could change <end@dream.life>
perl string match (Kelvin)
Re: perl string match <mark.clements@kcl.ac.uk>
Re: perl string match <Joe.Smith@inwap.com>
Re: Precedence of exponentiation <see@sig.invalid>
Re: Precedence of exponentiation <nemo@weathersong.net>
Re: Precedence of exponentiation <nemo@weathersong.net>
Re: Precedence of exponentiation <abigail@abigail.nl>
Re: Precedence of exponentiation <nemo@weathersong.net>
Re: Precedence of exponentiation <Joe.Smith@inwap.com>
Re: Precedence of exponentiation <Joe.Smith@inwap.com>
Re: references to filehandle? <stfhostf@kartos.de>
Re: references to filehandle? <Joe.Smith@inwap.com>
Re: Using C::Scan : How to ignore #includes ? <matrix_calling@yahoo.dot.com>
Re: what's wrong in this Perl Regex expression? <Joe.Smith@inwap.com>
Re: what's wrong in this Perl Regex expression? <Joe.Smith@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 27 Sep 2004 04:28:23 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: best way to search perldocs
Message-Id: <HFM5d.9901$Ym1.2711@trnddc03>
wana wrote:
> I was disconnected from the internet and had no access to my books
> today, but I did have access to all of the perldocs saved on my
> computer to look through. I was trying to find a way to change pwd
> from a script.
perldoc -q password
> I just wanted to write the most simple little thing to change
> directories and list the contents. I never really learned shell
> programming and I like to try to do everything with Perl these days.
>
> Once I reconnected, I instantly found chdir with a simple Google
> search. I wish I had Google to look through my perldocs though.
>
> Question: How could I have found this command more easily in perldocs?
"perldoc perlfunc" lists all Perl functions by category. The section for
"Functions for filehandles, files, or directories" contains chdir.
> I was going crazy grepping through perltoc hopelessly to the point
> where I was sure that there was no way to do it. By the way, why
> doesn't system("cd $ARGV[0]") work?
It does work perfectly fine, although it probably doesn't do what you
mistakenly expect it to do. Details see
perldoc -q modified
which by the way has nothing to do with Perl but with basic process
security.
------------------------------
Date: 27 Sep 2004 07:30:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: best way to search perldocs
Message-Id: <slrnclfgcg.hv.abigail@alexandra.abigail.nl>
wana (ioneabu@yahoo.com) wrote on MMMMXLV September MCMXCIII in
<URL:news:bf0b47ca.0409261752.c73b2b1@posting.google.com>:
|| I was disconnected from the internet and had no access to my books
|| today, but I did have access to all of the perldocs saved on my
|| computer to look through. I was trying to find a way to change pwd
|| from a script.
||
|| I just wanted to write the most simple little thing to change
|| directories and list the contents. I never really learned shell
|| programming and I like to try to do everything with Perl these days.
||
|| Once I reconnected, I instantly found chdir with a simple Google
|| search. I wish I had Google to look through my perldocs though.
||
|| Question: How could I have found this command more easily in perldocs?
That's a bit hard to say. What did you use to find 'chdir' in Google?
You might have been able to use 'grep' to find the same results.
|| I was going crazy grepping through perltoc hopelessly to the point
|| where I was sure that there was no way to do it. By the way, why
|| doesn't system("cd $ARGV[0]") work?
O, it does. It just doesn't do what you think it does. Assuming that
$ARGV [0] contains a string without characters special to the shell,
your command will fork, and the *child* process will call the 'cd'
command with $ARGV [0] as argument. The child process will change its
current working directory, and exit. Then the parent process will resume.
But the parent process never has changed its current working directory.
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
Date: Mon, 27 Sep 2004 09:38:02 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: best way to search perldocs
Message-Id: <_bR5d.268692$Fg5.13682@attbi_s53>
wana wrote:
> Once I reconnected, I instantly found chdir with a simple Google search
> Question: How could I have found this command more easily in perldocs?
When learning a language like Perl, one should always look over the
list of built-in functions at least once, even if just a cursory glance.
It is not expected that a beginner memorize all the functions listed
in perlfunc (or listed in an appendix in a book), but the novice is
expected to know that a list of functions exists.
-Joe
------------------------------
Date: Mon, 27 Sep 2004 04:37:37 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Can't locate module despite 'use lib'
Message-Id: <slrnclf68h.b8b.efflandt@typhoon.xnet.com>
On Sat, 25 Sep 2004 22:54:59 GMT, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "g" == gunzip <none@none.com> writes:
>
>
> g> begin_now();
>
> g> Ex.pm is located in /home/zarg/pl with mode 644:
>
> g> use strict;
> g> use lib qw(/home/zarg/pl);
> g> use Ex;
>
> g> "Can't locate Ex.pm in @INC (@INC contains: /home/zarg/pl ....
> g> BEGIN failed
>
> g> Why can't the script see my module when it has found the directory
> g> it lives in?
>
> it didn't find the directory, it just listed it. that means use lib
> worked. there are other permission problems such as 644 on /pl. web
> servers commonly run as nobody so it can't scan the directory for
> entries as it need x perms for that. try 666 permission and also check
> the perm on your home dir which needs to be x (searchable) by others as
> well.
644 should be fine for the module itself. But if running from a web
server, all directories in the path to the module need at least 701
permission (the x bit is needed on a dir to access it). 666 permission
would be incorrect for a directory and not advisable for a file (anybody
could modify it).
------------------------------
Date: Mon, 27 Sep 2004 04:43:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can't locate module despite 'use lib'
Message-Id: <x74qlkl3vq.fsf@mail.sysarch.com>
>>>>> "DE" == David Efflandt <efflandt@xnet.com> writes:
DE> On Sat, 25 Sep 2004 22:54:59 GMT, Uri Guttman <uri@stemsystems.com> wrote:
>> it didn't find the directory, it just listed it. that means use lib
>> worked. there are other permission problems such as 644 on /pl. web
>> servers commonly run as nobody so it can't scan the directory for
>> entries as it need x perms for that. try 666 permission and also check
>> the perm on your home dir which needs to be x (searchable) by others as
>> well.
DE> 644 should be fine for the module itself. But if running from a web
DE> server, all directories in the path to the module need at least 701
DE> permission (the x bit is needed on a dir to access it). 666 permission
DE> would be incorrect for a directory and not advisable for a file (anybody
DE> could modify it).
d'oh! i knew that!
this is why i use symbolic options in chmod :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 27 Sep 2004 00:42:40 -0700
From: prakashp@crt.net.au (Prak)
Subject: Determine weekends and compare two days
Message-Id: <2e7bca68.0409262342.2868fbeb@posting.google.com>
I'm not much of a perl programmer so I was hoping someone could help
me. What I need to do is determine between 2 dates whether there is a
weekend between them inclusive.
eg Between 1 Oct 2004 and 4 Oct 2004 there is a Sat. and a Sunday but
between 5 Oct 2004 and 8 Oct 2004, there is no Sat or Sunday.
Thanks in advance
Prak
------------------------------
Date: Mon, 27 Sep 2004 08:35:31 GMT
From: "Julia De Silva" <jds@atavailcheck.com>
Subject: Re: Determine weekends and compare two days
Message-Id: <nhQ5d.142677$hZ3.14472@fe2.news.blueyonder.co.uk>
> I'm not much of a perl programmer so I was hoping someone could help
> me. What I need to do is determine between 2 dates whether there is a
> weekend between them inclusive.
>
> eg Between 1 Oct 2004 and 4 Oct 2004 there is a Sat. and a Sunday but
> between 5 Oct 2004 and 8 Oct 2004, there is no Sat or Sunday.
>
> Thanks in advance
> Prak
You really ought to try working this one out on your own! That way you'll
understand and improve. Here's a pointer.
use Time::localtime;
my $today = time;
my $day_of_week = localtime($today)->wday;
my @days_of_week = qw(Sun Mon Tues Wed Thur Fri Sat);
print"Today is $days_of_week[$day_of_week]\n";
------------------------------
Date: Mon, 27 Sep 2004 10:04:24 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: few question about array
Message-Id: <IAR5d.119013$MQ5.21802@attbi_s52>
Andrea Spitaleri wrote:
> $initial=$i;
> $endmol=$number_atoms + $i;
Error: Undefined variable $number_atoms;
If you had set $number_atoms to a defined value earlier in your
program, you should have included that with your post.
-Joe
------------------------------
Date: Mon, 27 Sep 2004 15:28:32 +0800
From: Alont <end@dream.life>
Subject: Re: path delimiter in windows platform("/" could change to "\"?)
Message-Id: <4158c04c.82775671@130.133.1.4>
"John W. Kennedy" <jwkenne@attglobal.net>Wrote at Mon, 27 Sep 2004
03:32:12 GMT:
>That is a "feature" of the dialog box itself. The basic, nitty-gritty
>file-opening code of Windows and DOS has accepted either "/" or "\" for
>over twenty years, and if the dialog box weren't deliberately (and, in
>my view, incorrectly) rejecting "/", it would work just fine.
>
Oh, I see, it's a problem about Common Dialog Box.
My fault, sorry
--
Your fault as a Government is My failure as a Citizen.
------------------------------
Date: Mon, 27 Sep 2004 15:44:04 +0800
From: Alont <end@dream.life>
Subject: Re: path delimiter in windows platform("/" could change to "\"?)
Message-Id: <4159c122.82989343@130.133.1.4>
"A. Sinan Unur" <usa1@llenroc.ude.invalid>Wrote at 27 Sep 2004
03:09:06 GMT:
>1. Please quote properly. I did not write that message in response to your
>original post but in response to
>news:slrncldk2h.i8.wcitoan@wcitoan-via.supernews.com
>
>2. cmd.exe is not DOS
>
>3. Windows deals with / just fine
>
>4. Why 'must'? Notepad on Win98 seems not to mind / if it is specified on
>the command line whereas it fails to grok / if specified in the
>File->Open dialog. OTOH, Start->Run or Word's File->Open has no problems.
>On XP, I have not been able create a situation where / leads to problems.
>Specific applications may have bugs. In that case, you should demand that
>the bug be fixed. (By the way, I remember pointing out to you that EditPlus
>is a supported product: <Xns954B80344CE38asu1cornelledu@132.236.56.8>. You
>haven't avoided registering it, have you?)
>
>Sinan.
I'm sorry, You are right, I've tried Word, it really works with "/"
path in it's Common Dialog Box.
and My EditPlus copy as you said: I haven't register it, so? you want
point that you are more moral than me or what you want say?
this topic far from "Perl", I'm sorry start this topic, it's time to
stop.
--
Your fault as a Government is My failure as a Citizen.
------------------------------
Date: 26 Sep 2004 23:50:04 -0700
From: kcassidy@kakelma.mine.nu (Kelvin)
Subject: perl string match
Message-Id: <26b862d9.0409262250.22e46f72@posting.google.com>
Hi All,
Need a bit of help in pattern matching :) How to accomplish the
code below of the string "test" is inside a variable? (e.g. $x="test")
if ($k =~ /^test/)
{
print "1\n";
}
------------------------------
Date: Mon, 27 Sep 2004 10:00:40 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: perl string match
Message-Id: <4157c8a7$1@news.kcl.ac.uk>
Kelvin wrote:
> Hi All,
>
> Need a bit of help in pattern matching :) How to accomplish the
> code below of the string "test" is inside a variable? (e.g. $x="test")
>
>
>
> if ($k =~ /^test/)
> {
> print "1\n";
> }
my $searchString = "test";
if ( $k =~ /^$searchString/) {
}
man perlop
also check out the /o switch
Mark
------------------------------
Date: Mon, 27 Sep 2004 09:49:28 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: perl string match
Message-Id: <ImR5d.125091$D%.121517@attbi_s51>
Mark Clements wrote:
> man perlop
>
> also check out the /o switch
Hmmm. 'perldoc perlop' does not state whether the lack of /o has as
much of a performance impact in perl-5.8 as it had in earlier versions.
-Joe
------------------------------
Date: Mon, 27 Sep 2004 00:11:10 -0400
From: Bob Walton <see@sig.invalid>
Subject: Re: Precedence of exponentiation
Message-Id: <41579100$1_2@127.0.0.1>
David Frauzel wrote:
> Rhetorical question.
>
> Why does Perl give such high precedence to the exponentiation operator,
> "**"?
Because it attempts to follow after the way mathematicians write
algebraic expressions.
>
> perlop makes it very clear that -2**4 is equivalent to -(2**4), not (-2)
> **4. So -2**4 gives you -16, not 16. So Perl facilitates people who
> prefer unary operators to have less significance than binary operators,
--------------------------------------------------------^^^^^^^^^^^^^^^^
only the binary exponentiation operator -- multiplication, division,
addition and subtraction have lower precedence than unary - .
> which seems to be completely counter to the general rules of algebra.
According to perldoc perlop, yes, ** has higher precedence than unary -.
So yes, -2**4 should give -16, since the exponentiation is done first,
then the unary - on that result. And I disagree with you regarding the
"general rules of algebra" -- if a=2 and b=4, then
b -b
-a in algebra would be -16 -- and a would be 0.0625 . For
clarity, though, most folks would probably parenthesize them both.
Also, in the case of computer languages, it may help to give such
examples using variables rather than constants, as in -$a**$b and
$a**-$b, to avoid the issue of whether -4 is a constant or an expression.
>
> But that's not why I'm asking the question, actually. What bugs me is
> this:
>
> 2**-4
>
> ... gives you 2**(-4), not -(2**4). Looking at 2**-4, it seems obvious
> that this should be the case, but it apparently defies the above stated
> precedence rule. A token parser should recognize that the unary minus has
> lower precedence than **, and push ** below the unary minus, in exactly
> the same way it would with -2**4.
In most other languages, 2**-4 would give a syntax error. I think Perl
treats it as special (a DWIM), with the definition 2**(-4), because,
again, that would be the common thing in algebra. It certainly seems
better than returning -16 for 2**-4, which doesn't seem good at all.
But perlop seems to leave that one undefined. One can always use
parentheses to make the intent crystal clear.
Deparse shows $a**-$b deparsing as $a**(-$b).
>
> So, I'm left wondering if the Perl parser is actually going out of its
> way to make sure that a unary minus on the right side of binary
> exponentiation is given higher precedence than exponentiation, while on
> the left side, it has lower precedence. Clearly, if that is indeed the
> case, Perl is going out of its way to make sure that -2**4 arbitrarily
> works one way, and 2**-4 works another. The double standard, coupled with
> the illogical precedence to begin with, smells of some onerous backwards
> compatibility that probably isn't even relevant any longer.
I think Perl's got it right -- certainly what I think it should mean, if
it has to mean something other than a syntax error. It would be good,
though, to have it documented in perlop.
>
> In building a token parser based on Perl, I am tempted to altogether
> abandon this peculiar behavior, and give binary exponentiation the
> precedence it seems to rightly deserve: lower than unary minus.
I reckon you can build your parser any way you want.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Mon, 27 Sep 2004 04:45:48 GMT
From: David Frauzel <nemo@weathersong.net>
Subject: Re: Precedence of exponentiation
Message-Id: <1096260348.KTMmKfM5dStUwlkUNeDPvw@teranews>
Sisyphus <kalinaubears@iinet.net.au> wrote in news:41578337$0$12891
$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
> I think this is so that something like '17 - 2 ** 4' evaluates to 1 ...
> which is certainly what I would want it to evaluate to. Without that
> precedence, wouldn't '17 - 2 ** 4' evaluate to 50625 (ie 15 ** 4) ?
That's the difference between unary minus and binary minus. The parser
picks up on the difference and correctly evaluates the above regardless of
the weird binary exponentiation operator. :}
> Similarly, I don't think I would ever want 2 ** -4 to evaluate to -16.
Yes, I'm sure no one would! :} But do you really want -2**4 to evaluate to
-16? ;}
------------------------------
Date: Mon, 27 Sep 2004 04:53:59 GMT
From: David Frauzel <nemo@weathersong.net>
Subject: Re: Precedence of exponentiation
Message-Id: <1096260839.GO/RR5PNg+xP+vWX0dEBRg@teranews>
Bob Walton <see@sig.invalid> wrote in news:41579100$1_2@127.0.0.1:
> Because it attempts to follow after the way mathematicians write
> algebraic expressions.
Point me to some reference material where it says so? I'm curious,
really. Because I've probably forgotten most of even my high school
algebra - the stuff that doesn't go along with programming, anyway - so
maybe I'm just completely misremembering the part where the teacher said
that unary minus behaves differently on the left and right side of
exponentiation. (And my Windows calc application seems to disagree, too.)
>> who prefer unary operators to have less significance than binary
>> operators,
> --------------------------------------------------------^^^^^^^^^^^^^^^
> ^
Type. Yes, I meant exponentiation operators. :p
> So yes, -2**4 should give -16, since the exponentiation is done
> first,
> then the unary - on that result. And I disagree with you regarding
> the "general rules of algebra" -- if a=2 and b=4, then
>
> b -b
> -a in algebra would be -16 -- and a would be 0.0625 . For
> clarity, though, most folks would probably parenthesize them both.
You only have to paranthesize (-2)**4, since you don't want Perl's whacky
exponentiation precedence to get in the way of what you mean. In the case
of 2**-4, you don't, because Perl knows you mean something else. This is
why I used the word "arbitrary". And continue to wonder about what you're
calling "undefined" - whether it's for some backward-compatibility reason
that is no longer relevant to modern native Perl speakers.
> In most other languages, 2**-4 would give a syntax error. I think
> Perl treats it as special (a DWIM), with the definition 2**(-4),
> because, again, that would be the common thing in algebra. It
> certainly seems better than returning -16 for 2**-4, which doesn't
> seem good at all. But perlop seems to leave that one undefined. One
> can always use parentheses to make the intent crystal clear.
The very point of precedence is so that you don't need to use parantheses
if you're feeling lazy. (Certainly that is so with how list operators
behave - having different precedence on the left and right sides.) We
could throw precedence out the window if you just put everything in
parantheses. Therefore, precedence should be designed with the human in
mind, and what *most* humans will want to "mean" when they do not use
parantheses.
Am I really in the minority in thinking that -2**4 should mean (-2)**4?
> I reckon you can build your parser any way you want.
I'd prefer, though, to know Larry Wall's reasoning - so that if there's
in fact some astoundingly good reason I am just not seeing, I can add the
extra code necessary in my parser to treat exponentiation specially.
(With regards to unary minus as the next lexeme.)
------------------------------
Date: 27 Sep 2004 07:48:58 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Precedence of exponentiation
Message-Id: <slrnclfhfa.hv.abigail@alexandra.abigail.nl>
David Frauzel (nemo@weathersong.net) wrote on MMMMXLV September MCMXCIII
in <URL:news:1096244875.SwmN1svA7N7MUFMdSJ4pgw@teranews>:
^^ Rhetorical question.
^^
^^ Why does Perl give such high precedence to the exponentiation operator,
^^ "**"?
^^
^^ perlop makes it very clear that -2**4 is equivalent to -(2**4), not (-2)
^^ **4. So -2**4 gives you -16, not 16. So Perl facilitates people who
^^ prefer unary operators to have less significance than binary operators,
^^ which seems to be completely counter to the general rules of algebra.
Short answer: because C has the same precedence table. I think it's
commonly regretted in the Perl world that it is this way, but the
advantages of changing the precedence table are dwarved by the pain
it will cause.
^^ But that's not why I'm asking the question, actually. What bugs me is
^^ this:
^^
^^ 2**-4
^^
^^ ... gives you 2**(-4), not -(2**4). Looking at 2**-4, it seems obvious
^^ that this should be the case, but it apparently defies the above stated
^^ precedence rule. A token parser should recognize that the unary minus has
^^ lower precedence than **, and push ** below the unary minus, in exactly
^^ the same way it would with -2**4.
That doesn't make *any* sense at all. A precedence table *never* causes
a rearrangement of operators. If your suggestion would be rule, then
"foo" . length "bar" (equals "foo3")
would be equivalent to
length ("foo" . "bar") (equals 6)
as named unary operators have lower precedence than concatenation.
^^ So, I'm left wondering if the Perl parser is actually going out of its
^^ way to make sure that a unary minus on the right side of binary
^^ exponentiation is given higher precedence than exponentiation, while on
^^ the left side, it has lower precedence. Clearly, if that is indeed the
^^ case, Perl is going out of its way to make sure that -2**4 arbitrarily
^^ works one way, and 2**-4 works another. The double standard, coupled with
^^ the illogical precedence to begin with, smells of some onerous backwards
^^ compatibility that probably isn't even relevant any longer.
It's not a double standard. Rearranging of an expression has little to
do with precedence.
^^ In building a token parser based on Perl, I am tempted to altogether
^^ abandon this peculiar behavior, and give binary exponentiation the
^^ precedence it seems to rightly deserve: lower than unary minus.
Yes, that might be a good idea. It still doesn't follow to parse
a ** -b
as
- (a ** b)
Abigail
--
split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};
------------------------------
Date: Mon, 27 Sep 2004 08:47:51 GMT
From: David Frauzel <nemo@weathersong.net>
Subject: Re: Precedence of exponentiation
Message-Id: <1096274871.IRQ7IrUc0D7p5ylxmw/4bw@teranews>
Abigail <abigail@abigail.nl> wrote in
news:slrnclfhfa.hv.abigail@alexandra.abigail.nl:
> Short answer: because C has the same precedence table. I think it's
> commonly regretted in the Perl world that it is this way, but the
> advantages of changing the precedence table are dwarved by the pain
> it will cause.
Meh, well, that's almost what I thought. <rant> I think that's a fine
historical reason, but Perl is no longer "something C programmers move
to", it's what web designers use, or even new programmers use. Perl is a
language in its own right, I think it's unfair it be "hostage" to C.
</rant>
> That doesn't make *any* sense at all. A precedence table *never*
> causes a rearrangement of operators. If your suggestion would be rule,
> then
>
> "foo" . length "bar" (equals "foo3")
>
> would be equivalent to
>
> length ("foo" . "bar") (equals 6)
>
> as named unary operators have lower precedence than concatenation.
I'm talking about parse trees. (Not sure if we're on the same
wavelength.)
Run Deparse on that statement, and you actually see this:
'foo' . length('bar')
(Which also indicates how the preprocessor detected the useless use of
double-quotes.)
Precedence is working just like it should - but the *parser* is giving
you the extra convenience of treating unary ops differently based on
whether you're looking at the left or right side of them.
Try deparse on these:
length 'foo' x 3
length 'foo' || die
(Use -MO=Deparse,-p for a better visual.)
A lucid example is:
print 1, 2, print 'foo', 'bar'
The parse tree produced demonstrates differential treatment of the
precedence of the list operator from the left side and the right, because
that's how the English language itself works. (Which begets another
interesting conversation, but that's for a different NG.)
Show me some concrete docs if I've got this all wrong?
> It's not a double standard. Rearranging of an expression has little to
> do with precedence.
Please describe to me how Perl builds its parse trees, then, without
using precedence in any part. Precedence plays intimately with parse
trees in all the references I have read, and parse trees imply arranging
tokens (hierarchically).
Thanks for the suggestion about C, though. I do not mean *at all* to
sound snooty when I say "my parser will do it differently". I wouldn't be
basing my parser on Perl if I did not have a tremendous respect for it in
the first place. However, as a computer scientist, I am necessarily
suspect of all things computational, and am intent on building yet
another mousetrap. ;}
------------------------------
Date: Mon, 27 Sep 2004 09:26:51 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Precedence of exponentiation
Message-Id: <v1R5d.267889$mD.34406@attbi_s02>
David Frauzel wrote:
> But that's not why I'm asking the question, actually. What bugs me is
> this:
>
> 2**-4
>
> ... gives you 2**(-4), not -(2**4). Looking at 2**-4, it seems obvious
> that this should be the case, but it apparently defies the above stated
> precedence rule. A token parser should recognize that the unary minus has
> lower precedence than **, and push ** below the unary minus, in exactly
> the same way it would with -2**4.
It would be absurd to expect the minus sign to move like that.
The exponentation operator takes two arguments. It's high precedence
means that the two arguments must be made available before doing
anything else (such as addition or multiplication). -2**-4 is
parsed as -(2**(-4)) which gathers up the right-hand side of the **
before doing exponentiation.
-Joe
------------------------------
Date: Mon, 27 Sep 2004 09:29:07 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Precedence of exponentiation
Message-Id: <D3R5d.32587$He1.18550@attbi_s01>
David Frauzel wrote:
>>Short answer: because C has the same precedence table. I think it's
>>commonly regretted in the Perl world that it is this way, but the
>>advantages of changing the precedence table are dwarved by the pain
>>it will cause.
>
> Meh, well, that's almost what I thought. <rant> I think that's a fine
> historical reason, but Perl is no longer "something C programmers move
> to", it's what web designers use, or even new programmers use. Perl is a
> language in its own right, I think it's unfair it be "hostage" to C.
> </rant>
Your rant is one of many valid reasons why perl6 will be more self-consistent
than perl5. The fact that new programmers are using perl5 is not
sufficient reason to introduce pointless incompatibilities.
-Joe
------------------------------
Date: Mon, 27 Sep 2004 06:35:51 GMT
From: Stefan H. <stfhostf@kartos.de>
Subject: Re: references to filehandle?
Message-Id: <v4dfl09g668sar4tte94g1rqega01cbp2f@4ax.com>
On 27 Sep 2004 03:29:11 GMT, "A. Sinan Unur" <usa1@llenroc.ude.invalid>
wrote:
>Ahem ... I do not see anything that is separated using ;
sorry, I forgot to mention that the data files are semicolon separated
file
> print $out "@{[ join ';', @fields ]}\n";
> } else {
> warn "Cannot open $fields[1].csv: $!";
you don't close the open filehandles. Is this ok?
Thank you very much.
A curiosity:
my code
for (<MYFILE>) {
$splits{[split /;/]->[1]} = '';
}
for (keys %splits) {
open $_, ">$_.csv";
}
was totally wrong? I mean: is it not possible to open filehandles using
scalar variables like that?
And:
$splits{[split /;/]->[1]} = '';
is it correct?
Thank you again
Stefan
------------------------------
Date: Mon, 27 Sep 2004 09:44:41 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: references to filehandle?
Message-Id: <diR5d.125071$D%.70068@attbi_s51>
Stefan H. wrote:
> for (keys %splits) {
> open $_, ">$_.csv";
> }
>
> was totally wrong? I mean: is it not possible to open filehandles using
> scalar variables like that?
Use a hash to store lexical file handles. Also use 3-argument open().
my %fh; # Hash of file handles
for (keys %splits) {
open {$fh{$_}},'>>',"$_.csv";
}
...
$name = $fields[1];
print {$fh{$name}} $_;
-Joe
------------------------------
Date: Mon, 27 Sep 2004 12:55:15 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: Using C::Scan : How to ignore #includes ?
Message-Id: <9qP5d.3$RZ2.83@news.oracle.com>
Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to
> Abhinav
> <matrix_calling@yahoo.dot.com>], who wrote in article <QXP4d.2$vx2.76@news.oracle.com>:
>
>>>You did not explain why the headers are missing. Without headers,
>>>what makes you think the prototypes make sense?
>
>
>>I am checking the C File to ensure that all function definitions have
>>proper documentation. I do this using doxygen (http://www.doxygen.org).
>
>
> I still do not have a slightest idea what you want to achieve, and why
> do you want to achieve it in the way you do it.
>
>
>>I want to "skip" all the #defines, #includes, etc ..
>>Hence,
>>
>>C:Scan should (for my case) ignore any preprocessor directives. (It would
>>be as if I am removing these before running C::Scan on the file.
>
>
> I have no idea what "ignore" means here. If you want a broken
> pre-processor, write one, and set up C::Scan to use it. However, I'm
> not sure that a C preprocessor is a completely trivial program (well,
> probably to write one is trivial, but to *understand* what it must do
> from the C standard may be a non-trivial task).
>
>
>>>Sorry, I cannot understand what you are talking about...
>>
>>I do not need to check if prototypes are having comments, but doxygen
>>apparently has no way to differentiate this, so I used C::Scan to get all
>>the declarations. C::Scan returns declarations for prototypes as well as
>>definitions*, and I see if it really is a prototype by iterating over the
>>returned arrayref and checking whether it ends with a ';'.
>
>
> This is still not a full enough description to understand what you
> want to do. However, why not just redirect STDERR to /dev/null?
I have no doubt that C::Scan is an excellent module. Maybe I am the one wh
is expecting to do things with it which it isn;t meant for..
I have a C source file, sample.c :
#include <stdio.h>
int func1( int x,
int y, /*This is a comment*/
int z);
int main(void){
print ("Hello, World\n");
}
int func1( int x,
int y, /* This is a comment*/
int x)
{
return 0;
}
I used C::Scan (fdecls) to read this files and get a list of the function
declarations.
For the above file, it rightly gives
int func1( int x,
int y,
int z);
I am using this string, returned from C::Scan, to match the protoype in the
file, and comment it out. Thus, the modified file I have should have the
prototype for func1 commented out.
However, since C::Scan->get('fdecls') strips of comments, I am having a
problem. Thus, In the above case. the comment "/* This is a comment*? is
not present in the searcj expression.
I thought using C::Scan's fdecl would help me out here, as it already
provides me with the list of prototypes..
Is there any way I could get the whole prototype text as it is ? Or should
I just stop using C::Scan ?
Thanks for your help ..
Abhinav
------------------------------
Date: Mon, 27 Sep 2004 09:58:46 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: what's wrong in this Perl Regex expression?
Message-Id: <qvR5d.125139$D%.59505@attbi_s51>
Alont wrote:
> Tad McClellan <tadmc@augustmail.com>Wrote at Sat, 25 Sep 2004 11:32:53
> -0500:
>
>>I don't believe you.
>>
>>Either you did not try that, or you did get some error information...
>>
>>If you don't give the correct symptoms, we can't give the correct cure.
>>
>>Please post your real code (use copy/paste, don't re-type it).
>
>
> I have no motive for cheat people here, not everything you can suspect
> on computer programming, what I posted really my real code.
But you posted:
$text_start = "<div id="boxtitle">";
instead of
$text_start = '<div id="boxtitle">';
or
$text_start = q(<div id="boxtitle");
Since the one that you posted (the first one) does not compile, we are
certain that you did not post your real code. Little differences like
single quotes versus double quotes can make a big difference. That's
why we ask that you post (copy-and-paste) your real code.
-Joe
------------------------------
Date: Mon, 27 Sep 2004 10:00:30 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: what's wrong in this Perl Regex expression?
Message-Id: <2xR5d.268777$Fg5.59583@attbi_s53>
Mr. M.J. Lush wrote:
> my ($content) = $body =~ /($text_start.*$text_end)/;
my ($content) = $body =~ /(\Q$text_start\E.*\Q$text_end\E)/;
-Joe
------------------------------
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 7181
***************************************