[31712] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2975 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 7 14:09:45 2010

Date: Mon, 7 Jun 2010 11: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           Mon, 7 Jun 2010     Volume: 11 Number: 2975

Today's topics:
    Re: Get hexa code color from name <genomart@gmail.com>
        How do I properly use the open office page break? <steve@staticg.com>
    Re: How do I properly use the open office page break? <uri@StemSystems.com>
        How to get the class name from the reference to an obje <pengyu.ut@gmail.com>
    Re: How to get the class name from the reference to an  <sreservoir@gmail.com>
    Re: How to get the class name from the reference to an  (Jens Thoms Toerring)
    Re: How to get the class name from the reference to an  <rvtol+usenet@xs4all.nl>
    Re: How to switch floating decimal number char from "." <m@rtij.nl.invlalid>
    Re: How to switch floating decimal number char from "." <ben@morrow.me.uk>
    Re: How to switch floating decimal number char from "." <m@rtij.nl.invlalid>
    Re: ignoring namespaces? <bugbear@trim_papermule.co.uk_trim>
    Re: ignoring namespaces? <peter.nosp@m.silmaril.ie>
    Re: ignoring namespaces? <m@rtij.nl.invlalid>
        locale and Unicode [Was: How to switch floating decimal <ben@morrow.me.uk>
        Module to print hash? <pengyu.ut@gmail.com>
    Re: Module to print hash? <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Module to print hash? <hjp-usenet2@hjp.at>
    Re: Module to print hash? <justin.0911@purestblue.com>
    Re: Module to print hash? <cwilbur@chromatico.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 7 Jun 2010 00:02:12 -0700 (PDT)
From: perlgenome <genomart@gmail.com>
Subject: Re: Get hexa code color from name
Message-Id: <d870ccb6-74ad-43c9-8d65-996fdf45cfa4@c33g2000yqm.googlegroups.com>

On 6 juin, 20:03, perlgenome <genom...@gmail.com> wrote:
> Dear,
>
> In a widget Tk, How can I can hexa code color from a color name ?
>
> For example: which method can give the hexa code of =A0red name
> print $widget->METHOD('red'); # =A0#FF0000
>
> Best Regards,
>
> Djibril

The answer is to use rgb widget method and use sprintf.


------------------------------

Date: Mon, 7 Jun 2010 09:27:28 -0700 (PDT)
From: Steve <steve@staticg.com>
Subject: How do I properly use the open office page break?
Message-Id: <15db1bf0-d4fc-4a2e-b695-181b5084cdac@40g2000pry.googlegroups.com>

I'm trying to intake a bunch of text and format it for open office but
I can't figure out how this works:
http://search.cpan.org/~jmgdoc/OpenOffice-OODoc-2.124/OODoc/Document.pod#setPageBreak%28paragraph_[,_options]%29

I have my file defined as $oofile, my content defined as $content, and
my style defined as $styles (used the variable names from the
examples)

I can't find out why it wont work


------------------------------

Date: Mon, 07 Jun 2010 12:56:19 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: How do I properly use the open office page break?
Message-Id: <87zkz6ixxo.fsf@quad.sysarch.com>

>>>>> "S" == Steve  <steve@staticg.com> writes:

  S> I'm trying to intake a bunch of text and format it for open office but
  S> I can't figure out how this works:
  S> http://search.cpan.org/~jmgdoc/OpenOffice-OODoc-2.124/OODoc/Document.pod#setPageBreak%28paragraph_[,_options]%29

  S> I have my file defined as $oofile, my content defined as $content, and
  S> my style defined as $styles (used the variable names from the
  S> examples)

  S> I can't find out why it wont work

not that i can directly help but you need to learn how to ask for
help. first off, always show your code (don't just say you copied an
example since we all may not have access to it). then saying it doesn't
work is not useful. what did you expect it to do? what output did you
get? did you print all your data before the call and was it what you
expect it to be? in many cases, dealing with those questions and their
answers will solve your problem before you need to reach out to others
for help.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Sun, 6 Jun 2010 15:12:04 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How to get the class name from the reference to an object?
Message-Id: <b213e545-9629-4bfd-bd64-ee22ee2be99f@b21g2000vbh.googlegroups.com>

Suppose I new an object. Is there a way to get the class name from the
reference to the object?


------------------------------

Date: Sun, 06 Jun 2010 18:34:27 -0400
From: sreservoir <sreservoir@gmail.com>
Subject: Re: How to get the class name from the reference to an object?
Message-Id: <huh7q9$tjk$1@speranza.aioe.org>

On 6/6/2010 6:12 PM, Peng Yu wrote:
> Suppose I new an object. Is there a way to get the class name from the
> reference to the object?

perldoc -fref

-- 

  "Six by nine. Forty two."
  "That's it. That's all there is."
  "I always thought something was fundamentally wrong with the universe."


------------------------------

Date: 6 Jun 2010 22:35:47 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: How to get the class name from the reference to an object?
Message-Id: <872m63Fgi0U1@mid.uni-berlin.de>

Peng Yu <pengyu.ut@gmail.com> wrote:
> Suppose I new an object. Is there a way to get the class name from the
> reference to the object?

The ref() function should return the name of the package of the
object - I guess that's what you mean by "class name".

                                Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


------------------------------

Date: Mon, 07 Jun 2010 00:45:27 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: How to get the class name from the reference to an object?
Message-Id: <4c0c2507$0$22941$e4fe514c@news.xs4all.nl>

Peng Yu wrote:

> Suppose I new an object. Is there a way to get the class name from the
> reference to the object?


#!/usr/bin/perl -l

use Data::Dumper;

use Scalar::Util qw(
   blessed
   reftype
);

my $object = bless [], __PACKAGE__;

sub info { Dumper \@_ }

my $i;

print ++$i, ":\t", $_ for
   $object->info(),
   Dumper ( $object ),
   ref    ( $object ),
   blessed( $object ),
   reftype( $object ),
;

__END__


-- 
Ruud


------------------------------

Date: Mon, 7 Jun 2010 13:04:22 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: How to switch floating decimal number char from "." to "," ?
Message-Id: <ma0vd7-p39.ln1@news.rtij.nl>

On Sat, 05 Jun 2010 21:33:20 +0100, Ben Morrow wrote:

> This is a bad plan. Locales (specifically, the 'locale' pragma) and
> Unicode don't play nicely together in Perl, and if you're processing
> international text you will probably end up with Unicode strings. A

Can you expand on this? What exactly goes wrong (or is unexpected)?

M4



------------------------------

Date: Mon, 7 Jun 2010 17:21:07 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to switch floating decimal number char from "." to "," ?
Message-Id: <jsivd7-1gl1.ln1@osiris.mauzo.dyndns.org>


Quoth Martijn Lievaart <m@rtij.nl.invlalid>:
> On Sat, 05 Jun 2010 21:33:20 +0100, Ben Morrow wrote:
> 
> > This is a bad plan. Locales (specifically, the 'locale' pragma) and
> > Unicode don't play nicely together in Perl, and if you're processing
> > international text you will probably end up with Unicode strings. A
> 
> Can you expand on this? What exactly goes wrong (or is unexpected)?

A simple example would be something like this:

    LC_ALL=hu_HU.ISO8859-2 
        perl -Mlocale -E'
            binmode STDOUT, ":utf8";
            my $x = "\xa1";
            say $x =~ /\w/;
            say $x;
        '

0xA1 is inverted-! in ISO8859-1, but A-ogonek in ISO8859-2. The regex
match assumes the bytes of the string are to be interpreted according to
the locale's character set, so it matches; but the output layer upgrades
to UTF8 assuming the bytes are ISO8859-1, so it prints an inverted ! (in
UTF-8, of course).

A stranger example would be:

    LC_ALL=hu_HU.ISO8859-2
        perl -Mlocale -E'
            binmode STDOUT, ":utf8";
            my $x = "\xa1";
            say $x, lc $x;
            $x .= "\x{2013}";
            say $x, lc $x;
        '

which produces the output (all in UTF8)

    (inverted-!) (plus-minus)
    (inverted-!) (en-dash)    (inverted-!) (en-dash)

To understand this we need a table of character values:

    CODE    UNICODE     ISO8859-1   ISO8859-2
    \xA1    inverted-!  inverted-!  A-ogonek
    \xB1    plus-minus  plus-minus  a-ogonek
    \x2013  en-dash     -           -

What's happening here is that the first line, where $x contained only
8-bit characters, is performing the lc according to the locale, so \xA1
goes to \xB1; the second line, where $x has been 'upgraded' to Unicode
internally, is performing lc according to Unicode, so \xA1 stays as
\xA1. Both strings are then subject to the same incorrect-translation-
from-ISO8859-1 as above.

Confused yet? :)

Ben



------------------------------

Date: Mon, 7 Jun 2010 19:00:39 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: How to switch floating decimal number char from "." to "," ?
Message-Id: <n6lvd7-p39.ln1@news.rtij.nl>

On Mon, 07 Jun 2010 17:21:07 +0100, Ben Morrow wrote:

> Quoth Martijn Lievaart <m@rtij.nl.invlalid>:
>> On Sat, 05 Jun 2010 21:33:20 +0100, Ben Morrow wrote:
>> 
>> > This is a bad plan. Locales (specifically, the 'locale' pragma) and
>> > Unicode don't play nicely together in Perl, and if you're processing
>> > international text you will probably end up with Unicode strings. A
>> 
>> Can you expand on this? What exactly goes wrong (or is unexpected)?
> 
(snip)
> 
> Confused yet? :)

That's just plain buggy I would say, or is there some logic I don't see?

Besides, your examples did not work for me completely, to get the same 
regex matching I had to set LANG as well.

M4


------------------------------

Date: Mon, 07 Jun 2010 09:55:07 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: ignoring namespaces?
Message-Id: <8a2dnU30iPt2LpHRnZ2dnUVZ8n-dnZ2d@brightview.co.uk>

Peter Flynn wrote:
> bugbear wrote:
> [...]
>> I also considered walking the entire tree REMOVING namespaces,
>> but that doesn't sound like a high performance solution.
> 
> sed -e "s+<\([/]*\)\([^:]*:\)+<\1+g" ?

Given that my problem
(corrupt data) cannot be solved
by a "squeaky clean" solution (*),
that's strangely appealing.

    BugBear

(*) "one cannot proceed from the informal
to the formal by formal means" Alan Perlis


------------------------------

Date: Mon, 07 Jun 2010 12:32:15 +0100
From: Peter Flynn <peter.nosp@m.silmaril.ie>
Subject: Re: ignoring namespaces?
Message-Id: <8743m1Fuq1U1@mid.individual.net>

bugbear wrote:
> Peter Flynn wrote:
>> bugbear wrote:
>> [...]
>>> I also considered walking the entire tree REMOVING namespaces,
>>> but that doesn't sound like a high performance solution.
>>
>> sed -e "s+<\([/]*\)\([^:]*:\)+<\1+g" ?
> 
> Given that my problem (corrupt data) cannot be solved by a "squeaky
> clean" solution (*), that's strangely appealing.

I always counsel to avoid the non-XML approach because it carries no
guarantee that the object you elect to operate on is actually what you
think it is.

(At least, a formal XML method like XSLT/XPath doesn't have any
"guarantee" as such, but at least I can be reasonably certain that if I
select the fifth paragraph of section 4 of chapter 6, then that is what
I will get, leaving aside my own programming errors.)

But there are times (and invalid XML is one of them) when a combination
of sed, awk, grep, tr, and the rest if the tribe, including Perl, Emacs,
Python, and your own personal favourite, are the only viable solution.

sed has the advantage and disadvantage of being spectacularly fast: get
it wrong and it will eat your data. Properly tested, however, the above
will remove all namespace prefixes to element type names within the
document element. It will not remove the xmlns:* namespace binding
attributes from the root element start-tag, nor will it remove
namespaces prefixes from attributes anywhere (the addition of more REs,
alternations, subexpressions, and backreferences to achieve this is left
as an exercise to the reader :-). Because it is unparsed, it *will*
remove the namespace prefixes from examples of XML markup in CDATA
marked sections in documentation, for example.

P. Lepin wrote:
> Peter Flynn wrote:
>> bugbear wrote:
>> [...]
>>> I also considered walking the entire tree REMOVING namespaces,
>>> but that doesn't sound like a high performance solution.
>> sed -e "s+<\([/]*\)\([^:]*:\)+<\1+g" ?
>
> Haven't posted anything for a long while, but I cannot keep quiet
> after seeing this.
>
> That's barbarous, sir! Just barbarous!
> (smileys implied)

Peh. I have seen *far* worse [better], both in the Humanities and the
Natural Sciences, trying to coerce evilly-formed documents into XML :-)

///Peter
-- 
XML FAQ: http://xml.silmaril.ie/


------------------------------

Date: Mon, 7 Jun 2010 14:53:07 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: ignoring namespaces?
Message-Id: <jm6vd7-p39.ln1@news.rtij.nl>

On Mon, 07 Jun 2010 09:55:07 +0100, bugbear wrote:

> Peter Flynn wrote:
>> bugbear wrote:
>> [...]
>>> I also considered walking the entire tree REMOVING namespaces, but
>>> that doesn't sound like a high performance solution.
>> 
>> sed -e "s+<\([/]*\)\([^:]*:\)+<\1+g" ?
> 
> Given that my problem
> (corrupt data) cannot be solved
> by a "squeaky clean" solution (*),
> that's strangely appealing.

It is also very error prone, but may be acceptable. To improve on the 
above solution, do split it in two steps. First step, a custom program 
(instead of sed) cleans up the files and produces clean files without 
namespaces, second step program(s) processes those clean files.

By creating a separate program for the first step, you can have it do 
checks to see if the output it produces is sensible and die (to let you 
investigate the problem) if it is not.

After cleaning the files, all programs that process them (second step) 
don't have to carry convoluted logic to deal with the dirty files).

M4


------------------------------

Date: Mon, 7 Jun 2010 18:27:08 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: locale and Unicode [Was: How to switch floating decimal...]
Message-Id: <comvd7-cpl1.ln1@osiris.mauzo.dyndns.org>


Quoth Martijn Lievaart <m@rtij.nl.invlalid>:
> On Mon, 07 Jun 2010 17:21:07 +0100, Ben Morrow wrote:
> > Quoth Martijn Lievaart <m@rtij.nl.invlalid>:
> >> On Sat, 05 Jun 2010 21:33:20 +0100, Ben Morrow wrote:
> >> 
> >> > This is a bad plan. Locales (specifically, the 'locale' pragma) and
> >> > Unicode don't play nicely together in Perl, and if you're processing
> >> > international text you will probably end up with Unicode strings. A
> >> 
> >> Can you expand on this? What exactly goes wrong (or is unexpected)?
> > 
> (snip)
> > 
> > Confused yet? :)
> 
> That's just plain buggy I would say, or is there some logic I don't see?

No, it's just plain buggy. The bugs have been there since 5.8.0, they
are well known, and the only reason they haven't been fixed yet is
because it's extremely difficult (both to work out what the behaviour
*should* be, and to write the actual code). The problem *is* currently
being worked on (mostly by Karl Williamson), but don't hold your breath.

> Besides, your examples did not work for me completely, to get the same 
> regex matching I had to set LANG as well.

You probably had LANG set in your environment already, which I don't.
IIRC LANG overrides LC_ALL.

Ben



------------------------------

Date: Sun, 6 Jun 2010 17:58:35 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: Module to print hash?
Message-Id: <ba5d8407-5d77-433d-8980-fee2d12f8049@q33g2000vbt.googlegroups.com>

Whenever, I want to print a hash for inspection of its content. I
could write the following while loop. But I feel this is a common task
and probably should be factor out into a module. Could you please let
me know if there is a well designed module that can print an
arbitrarily complex hash?

while (($key, $value) = each(%coins)){
     print $key.", ".$value."\n";
}


------------------------------

Date: Sun, 6 Jun 2010 18:16:53 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Module to print hash?
Message-Id: <6tttd7xmtr.ln2@goaway.wombat.san-francisco.ca.us>

On 2010-06-07, Peng Yu <pengyu.ut@gmail.com> wrote:
> Whenever, I want to print a hash for inspection of its content. I
> could write the following while loop. But I feel this is a common task
> and probably should be factor out into a module. Could you please let
> me know if there is a well designed module that can print an
> arbitrarily complex hash?

Use the Data::Dumper module.  I am not sure if the following still
applies for your version of Perl, but read your Data::Dumper docs to be
sure:

BUGS
       Due to limitations of Perl subroutine call semantics, you cannot
       pass an array or hash.  Prepend it with a "\" to pass its
       reference instead.  This will be remedied in time, now that Perl has
       subroutine prototypes.  For now, you need to use the extended usage
       form, and prepend the name with a "*" to output it as a hash or
       array.


--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



------------------------------

Date: Mon, 7 Jun 2010 11:02:55 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Module to print hash?
Message-Id: <slrni0pde0.tm.hjp-usenet2@hrunkner.hjp.at>

On 2010-06-07 01:16, Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote:
> BUGS
>        Due to limitations of Perl subroutine call semantics, you cannot
>        pass an array or hash.  Prepend it with a "\" to pass its
>        reference instead.  This will be remedied in time, now that Perl has
>        subroutine prototypes.

Perl has had prototypes for 15 years now, so I think it's a safe bet
that this "bug" will never be remedied. 

	hp


------------------------------

Date: Mon, 07 Jun 2010 12:19:06 -0000
From: Justin C <justin.0911@purestblue.com>
Subject: Re: Module to print hash?
Message-Id: <5d2c.4c0ce3ba.6384b@zem>

On 2010-06-07, Peng Yu <pengyu.ut@gmail.com> wrote:
> Whenever, I want to print a hash for inspection of its content. I
> could write the following while loop. But I feel this is a common task
> and probably should be factor out into a module. Could you please let
> me know if there is a well designed module that can print an
> arbitrarily complex hash?
>
> while (($key, $value) = each(%coins)){
>      print $key.", ".$value."\n";
> }

Look for the module Data::Dumper. I believe that it's part of a standard
install.

	Justin.

-- 
Justin C, by the sea.


------------------------------

Date: Mon, 07 Jun 2010 11:56:23 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Module to print hash?
Message-Id: <861vci96qg.fsf@mithril.chromatico.net>

>>>>> "PY" == Peng Yu <pengyu.ut@gmail.com> writes:

    PY> Whenever, I want to print a hash for inspection of its
    PY> content. I could write the following while loop. But I feel this
    PY> is a common task and probably should be factor out into a
    PY> module. Could you please let me know if there is a well designed
    PY> module that can print an arbitrarily complex hash?

You've been asking a lot of really fundamental questions.

Do you have a copy of _Programming Perl_ within arm's length?  If not,
why not?  Consulting that book *before* asking a question would probably
save you the time it takes to wait for a response, and would probably
save the people who read this newsgroup a lot of time.

Further, people only have so much patience to expend on other people's
questions.  Would you rather get the help of the experts in this group
on basic questions that you could look up in _Programming Perl_, or
would you rather save their patience for when you have a *really*
difficult question?

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2975
***************************************


home help back first fref pref prev next nref lref last post