[31666] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2929 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 3 00:09:21 2010

Date: Sun, 2 May 2010 21:09:04 -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           Sun, 2 May 2010     Volume: 11 Number: 2929

Today's topics:
    Re: length in (utf8) characters ? <hjp-usenet2@hjp.at>
    Re: length in (utf8) characters ? <hjp-usenet2@hjp.at>
        Perl 5.8.3 <moongeegee@gmail.com>
    Re: Perl 5.8.3 <sreservoir@gmail.com>
    Re: Perl 5.8.3 <moongeegee@gmail.com>
    Re: Perl 5.8.3 <ben@morrow.me.uk>
    Re: Perl 5.8.3 <jurgenex@hotmail.com>
        using Spreadsheet::ParseExcel problems <jeep@rahul.net>
    Re: using Spreadsheet::ParseExcel problems <uri@StemSystems.com>
    Re: using Spreadsheet::ParseExcel problems <justin.1005@purestblue.com>
    Re: using Spreadsheet::ParseExcel problems <stevem_clipthis_@clubtrout.com>
    Re: using Spreadsheet::ParseExcel problems <derykus@gmail.com>
    Re: using Spreadsheet::ParseExcel problems <ben@morrow.me.uk>
    Re: XML Replace sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 2 May 2010 14:24:39 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: length in (utf8) characters ?
Message-Id: <slrnhtqro7.4bo.hjp-usenet2@hrunkner.hjp.at>

On 2010-04-29 14:54, Peter Billam <peter@www.pjb.com.au> wrote:
> Perl should know if it's in a utf environment and printing to a utf8
> device; python does, and so does vi, less, slrn, alpine, firefox and
> everything else I use (except fmt).

vi, less, slrn, and alpine know that they are dealing with a terminal
and can assume that the environment correctly describes properties of
this terminal. 

Perl or Python don't know this - the program written in Perl or Python
does not necessarily read from or write to a terminal - very often it
deals with files. These files are not necessarily text files and even if
they are, they are not necessarily in the native encoding. 

I don't know how Python deals with this. Perl does have an environment
variable (PERL_UNICODE) which can be used to control the default
encoding. I've used it a lot during the early days of Perl 5.8.x and can
only say that it causes more trouble than it's worth. Just set the
appropriate encoding *in* your script - you have to think about your I/O
anyway while writing the script.

	hp



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

Date: Sun, 2 May 2010 17:44:36 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: length in (utf8) characters ?
Message-Id: <slrnhtr7f4.mq4.hjp-usenet2@hrunkner.hjp.at>

On 2010-05-02 12:24, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> On 2010-04-29 14:54, Peter Billam <peter@www.pjb.com.au> wrote:
>> Perl should know if it's in a utf environment and printing to a utf8
>> device; python does, and so does vi, less, slrn, alpine, firefox and
>> everything else I use (except fmt).
>
> vi, less, slrn, and alpine know that they are dealing with a terminal
> and can assume that the environment correctly describes properties of
> this terminal. 

Actually, it is much more complicated:

All of these programs deal not only with the terminal, but with "files"
(I put quotes around that because it doesn't matter whether they are
stored on disk or received via a socket or pipe). 

So while slrn may for example assume that the terminal sends and expects
UTF-8 (because the user told it by setting LANG), it cannot just
use UTF-8 for decoding Usenet postings. Instead it has inspect the
headers of each posting to find the Content-Type header and decode the
posting according to its charset parameter (and that still ignores the
complexities of multi-part MIME messages which slrn can't handle).

The situation is worse for vi: Unlike mail messages, text files aren't
supposed to be portable between systems. So the user has to tell the
editor for every file which charset it is unless it is the local charset
or the editor can guess (UTF-8 is pretty easy to detect but most of the
8-bit charsets are hard to distinguish).

	hp



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

Date: Sun, 2 May 2010 06:30:16 -0700 (PDT)
From: moongeegee <moongeegee@gmail.com>
Subject: Perl 5.8.3
Message-Id: <2eb81738-cc94-42f4-bdb2-36ecd3a25f04@k19g2000yqm.googlegroups.com>

I need Perl 5.8.3 for Windows XP, but could not find the download web
site.
Please help.


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

Date: Sun, 02 May 2010 09:49:35 -0400
From: sreservoir <sreservoir@gmail.com>
Subject: Re: Perl 5.8.3
Message-Id: <hrjvtp$3eo$1@speranza.aioe.org>

On 5/2/2010 9:30 AM, moongeegee wrote:
> I need Perl 5.8.3 for Windows XP, but could not find the download web
> site.
> Please help.

why specifically 5.8.3? that's... ancient.

unless it's for debugging purposes, you don't want it, but you should
try cpan/ports or grab a copy of the source and compile it yourself.

-- 

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


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

Date: Sun, 2 May 2010 08:26:16 -0700 (PDT)
From: moongeegee <moongeegee@gmail.com>
Subject: Re: Perl 5.8.3
Message-Id: <69eff9c2-abcd-4f03-bb04-b5ece16c5717@24g2000yqy.googlegroups.com>

On May 2, 9:49=A0am, sreservoir <sreserv...@gmail.com> wrote:
> On 5/2/2010 9:30 AM, moongeegee wrote:
>
> > I need Perl 5.8.3 for Windows XP, but could not find the download web
> > site.
> > Please help.
>
> why specifically 5.8.3? that's... ancient.
>
> unless it's for debugging purposes, you don't want it, but you should
> try cpan/ports or grab a copy of the source and compile it yourself.
>
> --
>
> =A0 "Six by nine. Forty two."
> =A0 "That's it. That's all there is."
> =A0 "I always thought something was fundamentally wrong with the universe=
 ."

I don't need the 8.5.3 software anymore.
Thanks


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

Date: Sun, 2 May 2010 16:28:18 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl 5.8.3
Message-Id: <i9i0b7-61f.ln1@osiris.mauzo.dyndns.org>


Quoth sreservoir <sreservoir@gmail.com>:
> On 5/2/2010 9:30 AM, moongeegee wrote:
> > I need Perl 5.8.3 for Windows XP, but could not find the download web
> > site.
> > Please help.
> 
> why specifically 5.8.3? that's... ancient.
> 
> unless it's for debugging purposes, you don't want it, but you should
> try cpan/ports or grab a copy of the source and compile it yourself.

Better would be to get the latest version from strawberryperl.com.
Compiling perl under Win32 is not entirely straightforward.

Ben



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

Date: Sun, 02 May 2010 10:23:33 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Perl 5.8.3
Message-Id: <86drt5drbadk1mnc3ncpqn62j59lgf71i9@4ax.com>

moongeegee <moongeegee@gmail.com> wrote:
>On May 2, 9:49 am, sreservoir <sreserv...@gmail.com> wrote:
>> On 5/2/2010 9:30 AM, moongeegee wrote:
>> > I need Perl 5.8.3 for Windows XP, but could not find the download web
>> > site.
>>
>> why specifically 5.8.3? that's... ancient.
>
>I don't need the 8.5.3 software anymore.

???

jue


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

Date: Sun, 2 May 2010 10:06:30 -0700 (PDT)
From: Jeff <jeep@rahul.net>
Subject: using Spreadsheet::ParseExcel problems
Message-Id: <3b575382-284e-448e-a8fb-050bcde54355@11g2000prw.googlegroups.com>

Hi-

Im trying to use this the Spreadsheet::ParseExcel module and
having difficulty getting started.  When I use the examples Ive
seen I get the following error:

Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
5.10.0/Spreadsheet/ParseExcel.pm line 178.

I havent coded much since I was trying to figure out how to use it,
my code is just:

#!/usr/bin/perl -w

use Spreadsheet::ParseExcel;

my $parse = new Spreadsheet::ParseExcel->new() || die "ERROR creating
new object";
exit 0

I just downloaded the module today so it should be the latest.
Im running perl 5.10.0 on Linux fedora core.

Any suggestions as to what to check?
Thanks




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

Date: Sun, 02 May 2010 13:40:44 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: using Spreadsheet::ParseExcel problems
Message-Id: <877hnmnqw3.fsf@quad.sysarch.com>

>>>>> "J" == Jeff  <jeep@rahul.net> writes:

  J> my $parse = new Spreadsheet::ParseExcel->new() || die "ERROR creating

why are you calling new() twice there? pick on (the ->new() is better).

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, 2 May 2010 18:53:39 +0100
From: Justin C <justin.1005@purestblue.com>
Subject: Re: using Spreadsheet::ParseExcel problems
Message-Id: <3qq0b7-g5u.ln1@purestblue.com>

In article <3b575382-284e-448e-a8fb-050bcde54355@11g2000prw.googlegroups.com>, Jeff wrote:
> Hi-
> 
> Im trying to use this the Spreadsheet::ParseExcel module and
> having difficulty getting started.  When I use the examples Ive
> seen I get the following error:
> 
> Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
> 5.10.0/Spreadsheet/ParseExcel.pm line 178.
> 
> I havent coded much since I was trying to figure out how to use it,
> my code is just:
> 
> #!/usr/bin/perl -w
> 
> use Spreadsheet::ParseExcel;
> 
> my $parse = new Spreadsheet::ParseExcel->new() || die "ERROR creating
> new object";
> exit 0
> 
> I just downloaded the module today so it should be the latest.
> Im running perl 5.10.0 on Linux fedora core.
> 
> Any suggestions as to what to check?
> Thanks

You've got too many 'new's on the "my $parse" line. Instead try:

my $parse = Spreadsheet::ParseExcel->new();

I think the "or die" bit is redundant too, if it doesn't succeed then
there will be an error anyway. The module documentation has an
alternative based on the fact that you're also going to want an Excel
workbook to parse:

my $parser   = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');

if ( !defined $workbook ) {
    die $parser->error(), ".\n";
}

I don't know what documentation you are reading, but take a look at
what's here:
<URL:http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel-0.57/lib/Spreadsheet/ParseExcel.pm>.

   Justin.

-- 
Justin C, by the sea.


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

Date: Sun, 02 May 2010 13:05:06 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: using Spreadsheet::ParseExcel problems
Message-Id: <80lDn.60750$4W2.23190@newsfe01.iad>

On 5/2/2010 10:06 AM, Jeff wrote:
> Hi-
>
> Im trying to use this the Spreadsheet::ParseExcel module and
> having difficulty getting started.  When I use the examples Ive
> seen I get the following error:
>
> Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
> 5.10.0/Spreadsheet/ParseExcel.pm line 178.
>
> I havent coded much since I was trying to figure out how to use it,
> my code is just:
>
> #!/usr/bin/perl -w
>
> use Spreadsheet::ParseExcel;
>
> my $parse = new Spreadsheet::ParseExcel->new() || die "ERROR creating
               ^^^^  ???

> new object";
> exit 0
>
> I just downloaded the module today so it should be the latest.
> Im running perl 5.10.0 on Linux fedora core.
>
> Any suggestions as to what to check?
> Thanks
>
>

use Spreadsheet::ParseExcel;

my $file = '/path/to/file.xls';

my $parser    = Spreadsheet::ParseExcel->new();
my $workbook  = $parser->Parse($file);
my $worksheet = $workbook->Worksheet(0); # assume first sheet

hth,

\s
-- 
"There is no use in your walking five miles to fish when you can depend 
on being just as unsuccessful near home." M. Twain


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

Date: Sun, 2 May 2010 15:57:57 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: using Spreadsheet::ParseExcel problems
Message-Id: <68d78175-3ceb-41ca-983e-2fedde8cb8ea@6g2000prg.googlegroups.com>

On May 2, 10:53=A0am, Justin C <justin.1...@purestblue.com> wrote:
> In article <3b575382-284e-448e-a8fb-050bcde54...@11g2000prw.googlegroups.=
com>, Jeff wrote:
> > Hi-
>
> > Im trying to use this the Spreadsheet::ParseExcel module and
> > having difficulty getting started. =A0When I use the examples Ive
> > seen I get the following error:
>
> > Attempt to bless into a reference at /usr/local/lib/perl5/site_perl/
> > 5.10.0/Spreadsheet/ParseExcel.pm line 178.

>
> > ...
>
> > my $parse =3D new Spreadsheet::ParseExcel->new() || die "ERROR creating
> > new object";
> > exit 0


The additional 'new' results in

 my $parse =3D Spreadsheet::ParseExcel->new->new

which causes perl to die:

perl -MSpreadsheet::ParseExcel -e '$p=3DSpreadsheet::ParseExcel
->new->new'
Attempt to bless into a reference at -e line 1.

> ...
>
> my $parse =3D Spreadsheet::ParseExcel->new();
>
> I think the "or die" bit is redundant too, if it doesn't succeed
> ...

Or you may want to wrap the call in an eval {} for more
control...

  my $parse =3D eval { Spreadsheet::ParseExcel->new(); };
  die "error: ...  $@" if $@;

--
Charles DeRykus


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

Date: Mon, 3 May 2010 00:48:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using Spreadsheet::ParseExcel problems
Message-Id: <kif1b7-enh.ln1@osiris.mauzo.dyndns.org>


Quoth "C.DeRykus" <derykus@gmail.com>:
> 
> Or you may want to wrap the call in an eval {} for more
> control...
> 
>   my $parse = eval { Spreadsheet::ParseExcel->new(); };
>   die "error: ...  $@" if $@;

It's always safer to use the return value of eval, rather than testing
$@:

    my $parse = eval { Spreadsheet::ParseExcel->new }
        or die "error: ... $@";

If a signal comes in between the 'eval' and the 'if', or if S::PE->new
leaves something on the stack with a destructor, and that code clears
$@, the first construction will miss the error. The second will still
see the wrong value for $@, but that's better than not catching the
error at all.

Ben



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

Date: Sun, 02 May 2010 13:20:33 -0700
From: sln@netherlands.com
Subject: Re: XML Replace
Message-Id: <b2mrt5hd04ln1b14bdje5ool0p12g89jh0@4ax.com>

On Wed, 28 Apr 2010 10:01:37 -0700 (PDT), Trev <trevor.dodds@gmail.com> wrote:

>I'm trying to use Perl to replace a line in a few XML files I have.
>
>Example XML below, I'm wanting to change the Id= part from  Id="/Local/
>App/App1" to Id=/App1". I know there's an easy way to do this with
>perl alone however I'm trying to use XML::Simple or any XML plugin for
>perl.
>
><?xml version="1.0" encoding="UTF-8" standalone="no" ?>
>
><Profile xmlns="xxxxxxxxx" name="" version="1.1" xmlns:xsi="http://
>www.w3.org/2001/XMLSchema-instance">
>
>
>	<Application Name="App1" Id="/Local/App/App1" Services="1" policy=""
>StartApp="" Bal="5" sessInt="500" WaterMark="1.0"/>
>
>
><AppProfileGuid>586e3456dt</AppProfileGuid>
>
></Profile>

If what you need is all you state,
this code should fix up your xml.
Its restricted to just single tag-attribute pair.
It works by parsing exclusionary and specific markup.

The advantage here is that nothing else changes in the
original markup, only the string content of Id is changed
via the replacement side of the regex.
This avoids formatting headaches with some writers.

The regex may look simple for a parser, thats becuse it
is custom to the specific task.
The markup interraction is correct.

-sln

# -------------------------------------------
# rx_xml_fixval.pl
# -sln, 5/2/2010
# 
# Util to extract some attribute/val's from
# xml/xhtml
# -------------------------------------------

use strict;
use warnings;

##
 my $rxopen  = "(?: Application )"; # Open tag , cannot be empty alternation
 my $rxattr  = "(?: Id )";          # Attribute we seek, cannot have an empty alternation

 my $Rxmarkup = qr/
   [^<]*
   (?:
      # Things that hide markup
      (?: <! (?:  \[CDATA\[.*?\]\] | --.*?-- | \[[A-Z][A-Z\ ]*\[.*?\]\] ) > ) \K
      |
      # Specific markup
      (?: < (?<OPEN> $rxopen ) \s+[^>]*? (?<=\s) (?<ATTR> $rxattr) \s*=\s* \K(?<VAL> ".+?"|'.+?')
          (?= [^>]*? \s* \/? > )
      )
   )
   |
   < \K
 /xs;

##
 my $html = join '', <DATA>;
 $html =~ s/ $Rxmarkup/ fixval( $+{VAL} ) /eg;
 print "\n",$html;

 exit (0);

##
sub fixval {
    return '' unless defined $_[0];
    if ($_[0] =~ / \/ \s* (?<val>[^\/]+?) \s* (?<delim>["']) $/x) {
        return "$+{delim}$+{val}$+{delim}";
    } 
    return $_[0];
}


__DATA__

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<Profile xmlns="xxxxxxxxx" name="" version="1.1" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance">


	<Application Name="App1" Id="/Local/App/App1" Services="1" policy=""
StartApp="" Bal="5" sessInt="500" WaterMark="1.0"/>


<AppProfileGuid>586e3456dt</AppProfileGuid>

</Profile>




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

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 2929
***************************************


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