[24591] in Perl-Users-Digest
Perl-Users Digest, Issue: 6767 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 5 09:10:39 2004
Date: Mon, 5 Jul 2004 06:10:10 -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, 5 Jul 2004 Volume: 10 Number: 6767
Today's topics:
Regex to extract CSV file <corleone@godfather.com>
Re: Regex to extract CSV file (Anno Siegel)
Re: Regex to extract CSV file <josef.moellers@fujitsu-siemens.com>
Re: Regex to extract CSV file <corleone@godfather.com>
Re: Regex to extract CSV file <postmaster@castleamber.com>
Re: Regex to extract CSV file <josef.moellers@fujitsu-siemens.com>
Re: Regex to extract CSV file <josef.moellers@fujitsu-siemens.com>
Re: Regex to extract CSV file <postmaster@castleamber.com>
Re: Regex to extract CSV file <postmaster@castleamber.com>
Re: Regex to extract CSV file (Peter J. Acklam)
Re: Regex to extract CSV file <calle@cyberpomo.com>
Re: Regex to extract CSV file <postmaster@castleamber.com>
Re: Regex to extract CSV file (Peter J. Acklam)
Re: Regex to extract CSV file <Joe.Smith@inwap.com>
Re: Regex to extract CSV file <josef.moellers@fujitsu-siemens.com>
Re: undefined subroutine that is defined? mob_perl / p <dburke210@comcast.net>
Re: which book to learn Perl (Anno Siegel)
Re: Why is $ENV{COLUMNS} undefined inside the Perl prog <Joe.Smith@inwap.com>
Re: Win32::OLE Excel Chart SeriesCollection. Problem ch moller@notvalid.se
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 5 Jul 2004 15:50:37 +0900
From: Vito Corleone <corleone@godfather.com>
Subject: Regex to extract CSV file
Message-Id: <20040705155037.4f91378e.corleone@godfather.com>
Hi,
I have CSV file that looks like this:
1,this is the title,2004/03/05,this is details
2,another title,2004/05/05,another details
And I extract it using split like this:
@row = split(",", $line);
The problem is, if there is coma in text, it will turn to this:
1,"title , with coma",2004/03/05,and the details
2,title without coma,2004/05/09,"but details, has coma"
Is there any efficient way to extract this?
------------------------------
Date: 5 Jul 2004 06:59:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regex to extract CSV file
Message-Id: <ccau8v$3q8$1@mamenchi.zrz.TU-Berlin.DE>
Vito Corleone <corleone@godfather.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I have CSV file that looks like this:
> 1,this is the title,2004/03/05,this is details
> 2,another title,2004/05/05,another details
>
> And I extract it using split like this:
> @row = split(",", $line);
>
> The problem is, if there is coma in text, it will turn to this:
> 1,"title , with coma",2004/03/05,and the details
> 2,title without coma,2004/05/09,"but details, has coma"
That is a FAQ: "How can I split a [character] delimited string except
when inside [character]?"
> Is there any efficient way to extract this?
A search on CPAN for "CSV" would have shown you a handful of modules
for that purpose.
Anno
------------------------------
Date: Mon, 05 Jul 2004 09:05:21 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Regex to extract CSV file
Message-Id: <ccauev$5eg$1@nntp.fujitsu-siemens.com>
Vito Corleone wrote:
> Hi,
>=20
> I have CSV file that looks like this:
> 1,this is the title,2004/03/05,this is details
> 2,another title,2004/05/05,another details
>=20
> And I extract it using split like this:
> @row =3D split(",", $line);
>=20
> The problem is, if there is coma in text, it will turn to this:
> 1,"title , with coma",2004/03/05,and the details
> 2,title without coma,2004/05/09,"but details, has coma"
>=20
> Is there any efficient way to extract this?
Use Text::CSV from CPAN.
#! /usr/bin/perl -w
use Text::CSV;
$line =3D '1,"title , with coma",2004/03/05,and the details';
$csv =3D Text::CSV->new();
$status =3D $csv->parse($line);
@columns =3D $csv->fields();
print $columns[1], "\n";
exit 0;
prints
title , with coma
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 5 Jul 2004 17:10:04 +0900
From: Vito Corleone <corleone@godfather.com>
Subject: Re: Regex to extract CSV file
Message-Id: <20040705171004.32c5857c.corleone@godfather.com>
On Mon, 05 Jul 2004 09:05:21 +0200
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
> Use Text::CSV from CPAN.
Thank you very much :)
------------------------------
Date: Mon, 05 Jul 2004 03:54:51 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regex to extract CSV file
Message-Id: <40e9175c$0$875$58c7af7e@news.kabelfoon.nl>
Josef Moellers wrote:
> #! /usr/bin/perl -w
remove -w and:
use strict;
use warnings;
> use Text::CSV;
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 05 Jul 2004 11:45:25 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Regex to extract CSV file
Message-Id: <ccb7pn$pnt$1@nntp.fujitsu-siemens.com>
John Bokma wrote:
> Josef Moellers wrote:
>=20
>> #! /usr/bin/perl -w
>=20
>=20
> remove -w and:
>=20
> use strict;
> use warnings;
Yes, and a mailer and a news reader were also missing.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 05 Jul 2004 11:46:52 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Regex to extract CSV file
Message-Id: <ccb7sd$pnt$2@nntp.fujitsu-siemens.com>
John Bokma wrote:
> Josef Moellers wrote:
>=20
>> #! /usr/bin/perl -w
>=20
>=20
> remove -w and:
From the perl manpage on my system:
"Did we mention that you should definitely consider using the -w switch?"=
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 05 Jul 2004 04:53:12 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regex to extract CSV file
Message-Id: <40e9250a$0$880$58c7af7e@news.kabelfoon.nl>
Josef Moellers wrote:
> John Bokma wrote:
>
>> Josef Moellers wrote:
>>
>>> #! /usr/bin/perl -w
>>
>> remove -w and:
>
> From the perl manpage on my system:
>
> "Did we mention that you should definitely consider using the -w switch?"
" The "warnings" pragma is a replacement for the command line flag "-w",
perldoc warnings
perldoc perllexwarn
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 05 Jul 2004 04:54:23 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regex to extract CSV file
Message-Id: <40e9254f$0$880$58c7af7e@news.kabelfoon.nl>
Josef Moellers wrote:
> John Bokma wrote:
>
>> Josef Moellers wrote:
>>
>>> #! /usr/bin/perl -w
>>
>> remove -w and:
>>
>> use strict;
>> use warnings;
>
> Yes, and a mailer and a news reader were also missing.
Didn't notice that. I missed use strict, and several my's however :-D
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 05 Jul 2004 12:07:05 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Regex to extract CSV file
Message-Id: <isd2zs1i.fsf@online.no>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
> John Bokma wrote:
>
> > Josef Moellers wrote:
> >
> > > #! /usr/bin/perl -w
> >
> > remove -w and:
>
> From the perl manpage on my system:
>
> "Did we mention that you should definitely consider using the -w
> switch?"
It is, in a way, cleaner to "use warnings", but since it was
introduced very recently it can't be used in scripts that are to
be processed by older versions of perl.
I only use "-w" in one-liners, otherwise I use
#!/usr/bin/env perl
...
BEGIN { $^W = 1 } # equivalent to "-w" option
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Mon, 05 Jul 2004 12:10:45 +0200
From: Calle Dybedahl <calle@cyberpomo.com>
Subject: Re: Regex to extract CSV file
Message-Id: <86oemukbmi.fsf@ulthar.bisexualmenace.org>
>>>>> "Peter" == Peter J Acklam <pjacklam@online.no> writes:
> It is, in a way, cleaner to "use warnings", but since it was
> introduced very recently
It was introduced more than four years ago. That's about a quarter of
the time that Perl has existed at all. I really don't think that
qualifies as "very recently".
--
Calle Dybedahl <calle@cyberpomo.com>
http://www.livejournal.com/users/cdybedahl/
"Being stomped on by some sexy commie chick and her perfectly vegan Doc
Martens is not as hot as it sounds." -- babycola
------------------------------
Date: Mon, 05 Jul 2004 05:12:56 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regex to extract CSV file
Message-Id: <40e929a9$0$871$58c7af7e@news.kabelfoon.nl>
Calle Dybedahl wrote:
>>>>>>"Peter" == Peter J Acklam <pjacklam@online.no> writes:
>
>>It is, in a way, cleaner to "use warnings", but since it was
>>introduced very recently
>
> It was introduced more than four years ago. That's about a quarter of
> the time that Perl has existed at all. I really don't think that
> qualifies as "very recently".
OTOH, it's amazing how much hosting providers still offer an antique
version of perl :-( I had to rewrite open my $fh... recently :-(
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 05 Jul 2004 12:40:22 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Regex to extract CSV file
Message-Id: <3c46zqi1.fsf@online.no>
Calle Dybedahl <calle@cyberpomo.com> wrote:
> >>>>> "Peter" == Peter J Acklam <pjacklam@online.no> writes:
>
> > It is, in a way, cleaner to "use warnings", but since it was
> > introduced very recently
>
> It was introduced more than four years ago. That's about a
> quarter of the time that Perl has existed at all. I really don't
> think that qualifies as "very recently".
Ok, then "fairly recently" or whatever. My point is that
countless systems around are still running perl 5.005 and older
where "use warnings" doesn't work.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Mon, 05 Jul 2004 10:41:49 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Regex to extract CSV file
Message-Id: <MfaGc.27381$XM6.18897@attbi_s53>
Josef Moellers wrote:
> John Bokma wrote:
>
>> Josef Moellers wrote:
>>
>>> #! /usr/bin/perl -w
>>
>> remove -w and:
>> use warnings;
>
> From the perl manpage on my system:
> "Did we mention that you should definitely consider using the -w switch?"
How old is your version of perl? If your version of perl understands
use warnings;
then that is recommended in place of the -w switch.
------------------------------
Date: Mon, 05 Jul 2004 13:16:56 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Regex to extract CSV file
Message-Id: <ccbd4h$o9a$1@nntp.fujitsu-siemens.com>
Joe Smith wrote:
> Josef Moellers wrote:
>=20
>> John Bokma wrote:
>>
>>> Josef Moellers wrote:
>>>
>>>> #! /usr/bin/perl -w
>>>
>>>
>>> remove -w and:
>>> use warnings;=20
>>
>>
>> From the perl manpage on my system:
>> "Did we mention that you should definitely consider using the -w switc=
h?"
>=20
>=20
> How old is your version of perl? If your version of perl understands
> use warnings;
> then that is recommended in place of the -w switch.
It's perl v5.8.1. Maybe the version of my brain is quite old, so go figur=
e.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Sun, 4 Jul 2004 19:42:13 -0400
From: "Dan Burke" <dburke210@comcast.net>
Subject: Re: undefined subroutine that is defined? mob_perl / perl 5.8.4 issue?
Message-Id: <Zb-dnfCMi7TaC3XdRVn-uw@comcast.com>
"Richard Gration" <richard@zync.co.uk> wrote in message
news:cc3c4t$1oi$1@news.freedom2surf.net...
> In article <0PGdnW4f_rVzH3ndRVn_iw@comcast.com>, "Dan Burke"
> <dburke210@comcast.net> wrote:
> > I tried specifying the package name, and it still didn't work :( I
> Something else I've just thought of: Is the package returning a true
> value? ie is there a "1;" line at the end of it? I suspect so cos I've
> seen this error reported specifically. If I were you, at this point I'd
> try writing a trivial offline script which uses this file, and then try
and
> get this file running next as a cgi, then under mod_perl. Hopefully this
> will narrow down where the error is occurring. One trick I use is to
> introduce deliberate errors in certain places just to make sure that what
> I think is happening is actually happening.
>
Yeah, and I've seen the missing 1; cause errors at compile time. It kinda
seems to be a mod_perl /perl 5.8 thing though, because running the entire
applicaiton outside mod_perl gives no errors. By design this application
was originally made not to use mod_perl, then some 3 years ago we spent
months making it mod_perl safe (it's huge). For the last two years or so
it's been running in mod_perl 1.27, and perl 5.6.1. We decided it was time
to update a bit, perticularly because one environment in Europe required the
better unicode support in perl 5.8. I'm open to any whacked out ideas at
all at this point; this looks pretty grim :(
Dan.
------------------------------
Date: 5 Jul 2004 08:59:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: which book to learn Perl
Message-Id: <ccb59q$7id$1@mamenchi.zrz.TU-Berlin.DE>
Henry Law <news@lawshouse.org> wrote in comp.lang.perl.misc:
> On 4 Jul 2004 11:05:14 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
>
> >krakle <krakle@visto.com> wrote in comp.lang.perl.misc:
> >
> >> Randal Schwartz blah..
> >
> >Thank you for that insightful comment.
>
> Oh, Anno; you've let me down.
>
> I'd composed a reply to this something along the lines of
>
> "And just what do you mean by that, sonny? Judging by
> your previous posting record on here, Randal has
> forgotten more about coding in general and Perl in
> particular than you'll ever learn."
Absolutely correct. Only traces of signal among the noise from krakle.
> Then I thought "No, Anno or Uri or somebody will compose a better
> reply than that" and I cancelled it.
So sorry. I didn't think it deserved more than a casual reply.
Anno
------------------------------
Date: Mon, 05 Jul 2004 11:55:50 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Why is $ENV{COLUMNS} undefined inside the Perl program?
Message-Id: <albGc.27048$IQ4.6475@attbi_s02>
Adam wrote:
>> use Term::ReadKey;
>> ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
>
> And indeed it does. The only problem is that if the program is run
> non-interactively (e.g. from at or cron) it halts with an error here.
> I assume there is no way to catch the error?
You can catch errors using eval{}.
use Term::ReadKey;
my ($wchar, $hchar, $wpixels, $hpixels);
eval { ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize() };
if (defined $wchar) {
print "Width and height = $wchar, $hchar\n";
} else {
print "Terminal size is undefined\n";
}
------------------------------
Date: Mon, 05 Jul 2004 10:50:14 GMT
From: moller@notvalid.se
Subject: Re: Win32::OLE Excel Chart SeriesCollection. Problem changing from Excel 2000 to 2002
Message-Id: <ufz863ez9.fsf@notvalid.se>
moller@notvalid.se writes:
>
> Win32::OLE Excel Chart SeriesCollection.
> Problem when changing from Excel 2000 to 2002
>
>
> I have a data sheet with 5 columns of data called $Sheet.
> In Excel 2000 each of the columns ends up in a separate series
> when creating a chart with the 5 columns in the datarange.
>
> When switching from Excel 2000 to Excel 2002 the chart creation
> takes the 5 column range and sets the first 4 columns as the
> first series.
>
> Does anyone have any idea how to work around this or why it's happening?
> Or pointers to relevant documentation somwhere. Or any other
> suggestions
I found the problem, locale... or lack of it.
On the first computer the WIN-XP was swedish and MSOffice english [1]
so when perl used dot as a decimal separator it worked fine.
Om the new computer both XP and MSOffice was swedish and it broke
on 23.45 when it expected 23,45.
Example Data:
08:00-08:15 | 148 | 56 | 43.275 | 80
08:15-08:30 | 153 | 18 | 11.999 | 90
Column data should be interped as follows
text | number | number | number | number
but since dot was no longer decimal separator
excel interped it as
text | number | number | text | number
and then decided that the first four
columns should be DataSeries(1). That
gave me this data
text | number
08:15-08:30 153 18 11.999 | 90
I wonder why???
/moller
[1]. Somthing I missed
------------------------------
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 6767
***************************************