[31082] in Perl-Users-Digest
Perl-Users Digest, Issue: 2327 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 8 21:09:43 2009
Date: Wed, 8 Apr 2009 18:09: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 Wed, 8 Apr 2009 Volume: 11 Number: 2327
Today's topics:
Re: Ambiguity with lc <ced@blv-sam-01.ca.boeing.com>
Re: Ambiguity with lc <devnull4711@web.de>
calculate CDF <hirenshah.05@gmail.com>
Re: calculate CDF <tadmc@seesig.invalid>
Re: calculate CDF <hirenshah.05@gmail.com>
Re: calculate CDF <hirenshah.05@gmail.com>
Re: calculate CDF <noreply@gunnar.cc>
Re: I hate having to say the exists argument twice <smallpond@juno.com>
Re: I hate having to say the exists argument twice <uri@stemsystems.com>
Re: Modification of a hash-by-reference parameter in a <tadmc@seesig.invalid>
Re: Modification of a hash-by-reference parameter in a <smallpond@juno.com>
MooseX::ClassAttribute: read-only outside, writable ins (Tim McDaniel)
Re: perl values for batch script to use <rkb@i.frys.com>
Re: XML::LibXML UTF-8 toString() -vs- nodeValue() <benkasminbullock@gmail.com>
Re: XML::LibXML UTF-8 toString() -vs- nodeValue() <hsomob1999@yahoo.com>
Re: XML::LibXML UTF-8 toString() -vs- nodeValue() <benkasminbullock@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 8 Apr 2009 10:20:33 -0700 (PDT)
From: "C.DeRykuks" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Ambiguity with lc
Message-Id: <b3af5203-3f6e-449a-9c35-e01b2793e324@e25g2000vbe.googlegroups.com>
On Apr 6, 5:07=A0am, Frank Seitz <devnull4...@web.de> wrote:
> Ben Morrow wrote:
> > Quoth Frank Seitz <devnull4...@web.de>:
>
> >> This is the explanation in perldiag, I know. But I don't understand
> >> what this has to do with my code.
>
> > Neither could I when I wrote that, and I thought the warning was firing
> > in error. However, it *is* actually ambiguous. Consider
>
> > =A0 =A0 lc.5
>
> > This parses as
>
> > =A0 =A0 lc(.5)
>
> > rather than
>
> > =A0 =A0 lc() . 5
>
> > since the '.' can be interpreted as the start of a number.
>
> Okay, but in my case there is no digit following the dot,
> the dot is evidently the binary concatenation operator.
>
The Camel, 3rd ed., pg 96-7:
"Another funny thing about named unary operators is
that many of them default to $_ if you don't supply
an argument. However, if you omit the argument but
the token following the named unary operator looks
like it might be the start of an argument,Perl will
get confused because it's expecting a term."
Maybe I'm wrong but I suspect the tokener doesn't look ahead to check
context, ie, that there's no digit. It's confused and figures the next
victim probably will be too ...:)
--
Charles DeRykus
------------------------------
Date: Wed, 08 Apr 2009 19:38:30 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Ambiguity with lc
Message-Id: <7445omF112u3nU3@mid.individual.net>
C.DeRykuks wrote:
> On Apr 6, 5:07 am, Frank Seitz <devnull4...@web.de> wrote:
>> Ben Morrow wrote:
>>> Quoth Frank Seitz <devnull4...@web.de>:
>>>> This is the explanation in perldiag, I know. But I don't understand
>>>> what this has to do with my code.
>>> Neither could I when I wrote that, and I thought the warning was firing
>>> in error. However, it *is* actually ambiguous. Consider
>>> lc.5
>>> This parses as
>>> lc(.5)
>>> rather than
>>> lc() . 5
>>> since the '.' can be interpreted as the start of a number.
>> Okay, but in my case there is no digit following the dot,
>> the dot is evidently the binary concatenation operator.
>
> The Camel, 3rd ed., pg 96-7:
>
> "Another funny thing about named unary operators is
> that many of them default to $_ if you don't supply
> an argument. However, if you omit the argument but
> the token following the named unary operator looks
> like it might be the start of an argument,Perl will
> get confused because it's expecting a term."
>
> Maybe I'm wrong but I suspect the tokener doesn't look ahead to check
> context, ie, that there's no digit. It's confused and figures the next
> victim probably will be too ...:)
Thank you! I agree. This quotation explains everything!
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Wed, 8 Apr 2009 06:55:12 -0700 (PDT)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: calculate CDF
Message-Id: <529a6f4f-b97b-404f-b715-0f89c5f20219@q9g2000yqc.googlegroups.com>
I have large set of data.
Previously I was using matlab to plot CDF(cumulative distribution
function). But now very large set of data. matlab can't handle such
big data.
does anyone how can I calculate CDF using perl script.
Thanks.
------------------------------
Date: Wed, 8 Apr 2009 09:37:15 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: calculate CDF
Message-Id: <slrngtpdkr.k2i.tadmc@tadmc30.sbcglobal.net>
friend.05@gmail.com <hirenshah.05@gmail.com> wrote:
>
> Previously I was using matlab to plot CDF(cumulative distribution
> function).
> does anyone how can I calculate CDF using perl script.
What happened when you typed
cumulative distribution function
into the little box at:
http://search.cpan.org/
??
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 8 Apr 2009 08:12:37 -0700 (PDT)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: Re: calculate CDF
Message-Id: <68758bcd-2f57-4c77-8274-952cc9a6638a@z15g2000yqm.googlegroups.com>
On Apr 8, 10:37=A0am, Tad J McClellan <ta...@seesig.invalid> wrote:
> friend...@gmail.com <hirenshah...@gmail.com> wrote:
>
> > Previously I was using matlab to plot CDF(cumulative distribution
> > function).
> > does anyone how can I calculate CDF using perl script.
>
> What happened when you typed
>
> =A0 =A0 cumulative distribution function
>
> into the little box at:
>
> =A0 =A0http://search.cpan.org/
>
> ??
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
I found Math::CDF this module. but is there a place where I can find
example of this.
------------------------------
Date: Wed, 8 Apr 2009 08:49:36 -0700 (PDT)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: Re: calculate CDF
Message-Id: <d97da007-8b48-4997-8e98-8b35f2e45c6d@y13g2000yqn.googlegroups.com>
On Apr 8, 11:12=A0am, "friend...@gmail.com" <hirenshah...@gmail.com>
wrote:
> On Apr 8, 10:37=A0am, Tad J McClellan <ta...@seesig.invalid> wrote:
>
>
>
>
>
> > friend...@gmail.com <hirenshah...@gmail.com> wrote:
>
> > > Previously I was using matlab to plot CDF(cumulative distribution
> > > function).
> > > does anyone how can I calculate CDF using perl script.
>
> > What happened when you typed
>
> > =A0 =A0 cumulative distribution function
>
> > into the little box at:
>
> > =A0 =A0http://search.cpan.org/
>
> > ??
>
> > --
> > Tad McClellan
> > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>
> I found Math::CDF this module. but is there a place where I can find
> example of this.- Hide quoted text -
>
> - Show quoted text -
In Math::CDF
function: pnorm($x)
what is $x? how can I get value of $x.
------------------------------
Date: Wed, 08 Apr 2009 18:03:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calculate CDF
Message-Id: <74405rF119t50U1@mid.individual.net>
friend.05@gmail.com wrote:
> In Math::CDF
>
> function: pnorm($x)
>
> what is $x? how can I get value of $x.
The name of the function is pnorm. $x is a variable representing a
value. There is an example of using pnorm() in the SYNOPSIS section of
the Math::CDF documentation.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 8 Apr 2009 12:53:59 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: I hate having to say the exists argument twice
Message-Id: <1c1ce75e-6ed1-43e1-96f5-d3c857c0e593@e38g2000vbe.googlegroups.com>
On Apr 7, 8:29 pm, jida...@jidanni.org wrote:
> I'm sorry I don't understand smallpond and Dr. Rudd's answers.
> Is there a solution that won't make a warning when -w is in use and the
> item doesn't exist or is defined I suppose?
perl 5.10 has this new operator. $a // $b is short for:
defined($a) ? $a : $b
It would be nice if there was a similar op for exists, but
for many uses of hashes a value is always defined when the
key exists. It depends on your program.
------------------------------
Date: Wed, 08 Apr 2009 16:37:04 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: I hate having to say the exists argument twice
Message-Id: <x7vdpeanm7.fsf@mail.sysarch.com>
>>>>> "s" == smallpond <smallpond@juno.com> writes:
s> On Apr 7, 8:29 pm, jida...@jidanni.org wrote:
>> I'm sorry I don't understand smallpond and Dr. Rudd's answers.
>> Is there a solution that won't make a warning when -w is in use and the
>> item doesn't exist or is defined I suppose?
s> perl 5.10 has this new operator. $a // $b is short for:
s> defined($a) ? $a : $b
s> It would be nice if there was a similar op for exists, but
s> for many uses of hashes a value is always defined when the
s> key exists. It depends on your program.
from a point of view of a hash element having a value, //= is good
enough. in many cases ||= is also good enough if you never allow 0 or ''
as a legal value. and autovivication handles all cases where you want a
ref in the slot and you never need to deal with exists. as i posted
before, exists is a useful but rarely needed function. we never got
(even though i asked) why the OP must use exists.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 8 Apr 2009 06:55:36 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Modification of a hash-by-reference parameter in a recursive sub
Message-Id: <slrngtp45o.i53.tadmc@tadmc30.sbcglobal.net>
CoDeReBeL <CoDeReBeL@live.com> wrote:
> $_ =~ s/(,|\.)'/$1’/g ;
s/([,.])'/$1’/g;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 8 Apr 2009 08:13:15 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Modification of a hash-by-reference parameter in a recursive sub
Message-Id: <0450bf93-fe5f-4f45-a5ef-f93cda8d6bf7@e12g2000vbe.googlegroups.com>
On Apr 7, 10:46 pm, CoDeReBeL <CoDeRe...@live.com> wrote:
> OK, it's like this... I am far from an expert in Perl but I really
> think this should work...
>
> use strict;
> use warnings;
> use diagnostics;
> use HTML::TreeBuilder;
> use HTML::Entities;
> use HTML::Element;
>
> sub traverse {
> foreach (@_) {
> if (ref $_) {
> if ($_->tag() ne "head"
Why use $_ and not a named variable?
foreach my $html(@_) {
if (ref $html) {
if ($html->tag() ne "head"
etc.
It's more readable and less likely that you accidentally
modify $_ in any loop longer than a few lines.
------------------------------
Date: Thu, 9 Apr 2009 00:09:47 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: MooseX::ClassAttribute: read-only outside, writable inside
Message-Id: <grjecb$1k0$1@reader1.panix.com>
I'm very new to Moose, and I'm probably missing something very simple.
Does anyone have examples of code that
- provides a class attribute via MooseX::ClassAttribute
- that class attribute is readable but not changable by the outside
world
- that class attribute can be changed within the package itself?
In my case, I have a class of objects that each have an integer key
(set once at new() time, never changed thereafter). I'd like to
provide to the user of the class a way to get the minimum key so far
and the maximum key so far, but I don't want them to be able to change
it. Within the package, though, I need to conditionally update max
and min at every object creation (currently, I'm using "sub BUILD" to
catch the event).
I have a basic notion of how to do it outside Moose, but I'd like to
do it "the usual Moose|MooseX way", especially as they may handle
grungy details that I know nothing about, such as correct inheritance.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Wed, 8 Apr 2009 06:52:25 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: perl values for batch script to use
Message-Id: <9f290ea6-327e-45d4-b6db-3b5ebe552a0b@f18g2000vbf.googlegroups.com>
On Apr 7, 3:50=A0pm, s...@netherlands.com wrote:
> On Tue, 7 Apr 2009 14:09:10 -0700 (PDT), Ron Bergin <r...@i.frys.com> wro=
te:
> >On Apr 7, 10:58 am, Slickuser <slick.us...@gmail.com> wrote:
> >> I have a filename (file.txt)
>
> >> file.txt contains:
> >> Sample4.1.2009_US
> >> Sample4.2.2009_ASIA
>
> >> I can parse this file in Perl fine. Now I want this value to be
> >> available to use in a batch script.
> >> I try using "set" but the info get clear once I exit perl script.
>
> >> perl_script.pl
> >> open file.txt
> >> parse info
> >> use system to execute command ("set xxyz_US=3DSample4.1.2009_US")
> >> ("set xxyz_ASIA=3DSample4.2.2009_ASIA")
>
> >Use setenv instead of the set command.
>
> >http://barnyard.syr.edu/~vefatica/#SETENV
>
> >Or, you could use the standard set command and then use Win32::API to
> >call 2 C functions (RegFlushKey and BroadcastSystemMessage) to force
> >that setting to be retained after the perl script ends, which is
> >basically what setenv does.
>
> I don't understand posters taken verbatim. The dumb shmuks here
> think a perl script can realistically shine shoes if asked. Literally.
>
> -sln
I don't understand how your comment applies to mine. What you're
trying to convey?
------------------------------
Date: 08 Apr 2009 11:05:25 GMT
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: XML::LibXML UTF-8 toString() -vs- nodeValue()
Message-Id: <49dc84f5$0$31430$c5fe31e7@read01.usenet4all.se>
On Tue, 07 Apr 2009 16:07:05 -0700, MaggotChild wrote:
> Wide character in print at ./utf8-lib-xml.pl line 18.
You need to use binmode like this:
binmode STDOUT ":encoding(cp932)";
etc. If you don't tell Perl what you want it to do with the wide
characters, it moans about wide characters to STDERR.
> âERâ
> to string
> âERâ
> is utf-8:
>
>
> Why is toString no longer UTF-8?
It is UTF-8 but it longer has the flag telling Perl it is UTF-8.
You can get a similar effect using Encode's encode_utf8 and decode_utf8.
> And, since the wide char has been broken down into octets, how does
> one know that it's composed of 2 octets when its interpreted on the
> receiving end (or even in my terminal)?
I'm not sure I understand your question. The length of a UTF-8 character
is unambiguous provided you know that it's UTF-8.
> On the surface it seems as if I'd be breaking the UTF-8.
There are two different and yet confusingly similar things here, Perl's
internal representation of Unicode and UTF-8 encoded text which Perl has
not been told is UTF-8.
> Is the toSting() method the preferred way to send the value of a
> TextNode across the network?
I have no idea.
------------------------------
Date: Wed, 8 Apr 2009 10:16:54 -0700 (PDT)
From: MaggotChild <hsomob1999@yahoo.com>
Subject: Re: XML::LibXML UTF-8 toString() -vs- nodeValue()
Message-Id: <5439ba3e-d0d7-40bf-8883-49dfcb737f8f@e38g2000vbe.googlegroups.com>
On Apr 8, 4:05=A0am, Ben Bullock <benkasminbull...@gmail.com> wrote:
> > =E2ER=E2
> > to string
> > =E2ER=E2
> > is utf-8:
>
> > Why is toString no longer UTF-8?
>
> It is UTF-8 but it longer has the flag telling Perl it is UTF-8.
Hi, thanks for your reply.
How can one tell that the string is UTF-8 without checking Perl's utf8
flag?
Or is this not possible?
> You can get a similar effect using Encode's encode_utf8 and decode_utf8.
>
> > And, since the wide char has been broken down into octets, how does
> > one know that it's composed of 2 octets when its interpreted on the
> > receiving end (or even in my terminal)?
OK, The receiver would have to be UTF-8 aware, unlike my terminal, and
check the encoding info in each byte (or the 1st), sucking up any
additional bytes and building the character accordingly.
> I'm not sure I understand your question. The length of a UTF-8 character
> is unambiguous provided you know that it's UTF-8.
I think I'm confusing the character representation (composing more
than 1 byte, causing the wide char error) and the toString() (or
binmode) representation which outputs the actual code points.
------------------------------
Date: 09 Apr 2009 00:24:02 GMT
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: XML::LibXML UTF-8 toString() -vs- nodeValue()
Message-Id: <49dd4021$0$31434$c5fe31e7@read01.usenet4all.se>
On Wed, 08 Apr 2009 10:16:54 -0700, MaggotChild wrote:
> How can one tell that the string is UTF-8 without checking Perl's utf8
> flag?
> Or is this not possible?
You can check whether a string is correctly encoded as UTF-8 by using
the "decode_utf8" routine of the Encode module. If it is not UTF-8 you will
get an error message.
If you have a random stream of bytes and you want to check whether they
might be correct UTF-8 or some other encoding, you could try Encode::Guess.
(You can read my review of this module at
"cpanratings.perl.org/dist/Encode". My cpanratings name is "BKB".).
If you want to know whether Perl has marked a string as being UTF-8, in
other words whether Perl thinks that a string is UTF-8 or not, the only
way of doing this is to look at Perl's flag, using utf8::is_utf8 or
the similar routine in Encode.
The important point here is that there are three types of strings:
1) Strings which are not UTF-8, e.g. strings in latin-1 or CP932 etc
2) Strings which are UTF-8 but Perl is not aware of this
3) Strings which are UTF-8 and Perl is aware of this
>> You can get a similar effect using Encode's encode_utf8 and decode_utf8.
>>
>> > And, since the wide char has been broken down into octets, how does
>> > one know that it's composed of 2 octets when its interpreted on the
>> > receiving end (or even in my terminal)?
>
> OK, The receiver would have to be UTF-8 aware, unlike my terminal, and
> check the encoding info in each byte (or the 1st), sucking up any
> additional bytes and building the character accordingly.
I use Cygwin on a Japanese-language Microsoft Windows and I have to
convert every output to the terminal using
binmode STDOUT, ":encoding(cp932)";
Also I have to convert every file name using something like
open my $input, "<:utf8", encode("cp932", "filename")
I'm not too sure why Perl is not set up to use the Windows "wchar" versions
of file system functions when the strings contain internally-encoded UTF-8,
but unfortunately Perl programmers on Windows are still stuck with using
code pages.
>> I'm not sure I understand your question. The length of a UTF-8 character
>> is unambiguous provided you know that it's UTF-8.
>
> I think I'm confusing the character representation (composing more
> than 1 byte, causing the wide char error) and the toString() (or
> binmode) representation which outputs the actual code points.
You have a string of type 3) described above, but Perl does not know
what to do with it.
--
perl -e'@a=qw/Harder Better Faster Stronger/;use Time::HiRes"ualarm";@z=(0,2,4,
6);@v=("Work It","Make It","Do It","Makes Us");sub w{("")x$_[0]}$|=$t=432250;@f
=split"/","More Than/Ever/Hour/After/Our/Work Is/Never/Over";@e=((map{join(":",
@f[$_,$_+1])}@z),"");@w=map"$v[$_]:$a[$_]",0..3;@h=(@w,@e);@j=w(5);@t=(@v,@j,@a
,@j);@l=(@t,@f[@z],@j,(map{$f[$_+1]}@z),@j,@t,@w,@j,@e,w(4),(@h)x6,w(9),(@h)x7)
;ualarm$t,$t;$SIG{ALRM}=sub{print p()};a:goto a;sub p{if(($c++)%2){exit if!@l;
$_=shift@l&&if(/(.*):(.*)/){$s=$2;$1}else{"$_\n"}}}elsif($s){" $s\n",$s=""}'
------------------------------
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 V11 Issue 2327
***************************************