[26422] in Perl-Users-Digest
Perl-Users Digest, Issue: 8592 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 1 00:20:41 2005
Date: Mon, 31 Oct 2005 21:20:33 -0800 (PST)
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, 31 Oct 2005 Volume: 10 Number: 8592
Today's topics:
Re: Regex Precedence <1usa@llenroc.ude.invalid>
Re: Regex Precedence <someone@example.com>
Re: Regex Precedence <matthew.garrish@sympatico.ca>
Re: RTF and UTF-8 files in Perl <VSRawat@Invalid.none>
Re: RTF and UTF-8 files in Perl <scobloke2@infotop.co.uk>
Re: RTF and UTF-8 files in Perl <scobloke2@infotop.co.uk>
Re: RTF and UTF-8 files in Perl <rvtol+news@isolution.nl>
Re: RTF and UTF-8 files in Perl <VSRawat@Invalid.none>
Re: The Evil American Corprotocracy <pjh@mps.com>
using perl to print yesterday's date, but with formatti <tomvo@hahaha.be>
Re: using perl to print yesterday's date, but with form <xx087@freenet.carleton.ca>
Re: using perl to print yesterday's date, but with form <mothra@nowhereatall.com>
Re: using perl to print yesterday's date, but with form <darkon.tdo@gmail.com>
Re: using perl to print yesterday's date, but with form <abigail@abigail.nl>
Re: using perl to print yesterday's date, but with form <noreply@gunnar.cc>
Re: using perl to print yesterday's date, but with form <noreply@gunnar.cc>
Re: why the perl docs suck robic0@yahoo.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 01 Nov 2005 01:05:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Regex Precedence
Message-Id: <Xns9700CC77EF003asu1cornelledu@127.0.0.1>
"Kevin Nechodom" <Kevin.Nechodom@nospam.hsc.utah.edu> wrote in
news:dk6c0q$sc6$1@vegh.ks.cc.utah.edu:
> <HTML><HEAD>
> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
> <META content="MSHTML 6.00.2900.2769" name=GENERATOR></HEAD>
Please don't.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 01 Nov 2005 01:21:37 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Regex Precedence
Message-Id: <Bqz9f.93736$Io.12992@clgrps13>
Kevin Nechodom wrote:
> I am trying to format some text in the midst of a s/// substitution. I have a
> field that can be:
> (blank)
> char
> char-num, char - num, char#num
> num
> num-num, num - num, num#num
>
> and I want to reformat it to:
> (char or num)-num
>
> So I'm trying to match it with:
> s/(\w*)(?: |-|\#)*(\w*)/$1-$2/
>
> But when I come to the case of '632', it returns '-632' instead of '632-'. How
> do I change this to return '632-'? I dont' understand regex precedence here.
This may be what you want:
s/(\w+)(?: *[#-] *)?(\d*)/$1-$2/g;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 31 Oct 2005 20:43:55 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Regex Precedence
Message-Id: <sLz9f.3441$J14.162161@news20.bellglobal.com>
"Kevin Nechodom" <Kevin.Nechodom@nospam.hsc.utah.edu> wrote in message
news:dk6c0q$sc6$1@vegh.ks.cc.utah.edu...
> I am trying to format some text in the midst of a s/// substitution. I
> have a field that can be:
> (blank)
> char
> char-num, char - num, char#num
> num
> num-num, num - num, num#num
> and I want to reformat it to:
> (char or num)-num
> So I'm trying to match it with:
> s/(\w*)(?: |-|\#)*(\w*)/$1-$2/
> But when I come to the case of '632', it returns '-632' instead of '632-'.
> How do I change
> this to return '632-'? I dont' understand regex precedence here.
Please do not post html messages to usenet, and vcf files are equally
unwanted.
My guess is that it has to do with making the content inside your first
capture optional (you might want to consider reading Mastering Regular
Expressions). It doesn't have to match, which means that your look-ahead
assertion can, and if it is followed by any \w characters those characters
will come out after the dash in your replacement. For example:
$num = ' -#632';
$num =~ s/(\w*)(?: |-|\#)*(\w*)/$1-$2/;
print $num;
Without seeing any of the actual data you're working with, however, I'm not
going to speculate at what will or will not fix your problem.
Matt
------------------------------
Date: 31 Oct 2005 05:10:23 +0100
From: "V S Rawat" <VSRawat@Invalid.none>
Subject: Re: RTF and UTF-8 files in Perl
Message-Id: <xn0e94cpena2pi000@xananews>
Matt Garrish wrote:
>
> "V S Rawat" <VSRawat@Invalid.none> wrote in message
> news:xn0e93zst5r39c000@xananews...
> > 1. How do I open a RTF file as input in Perl and read
> > formatted ASCII text from it?
> >
>
> You don't. There's no such thing as formatted ASCII text. You
> could look into a module such as RTF::Tokenizer if you want to
> parse apart the RTF file and extract the text from it. If you
> want to know what formatting has been applied you'll also need
> to check the formatting commands as you go.
>
> > 2. How do I open a UTF-8 (Unicode) file as output in Perl and
> > write Unicode text to it?
> >
>
> Assuming your data is not already utf8:
I am reading some unicode char codes, and converting them to
display the unicode chars.
Say, my code is ($cod = ) 0964 (hexadec chars) which should lead
to a unicode char. But, when I do $char = chr($cod), end up
getting "d" in $char.
How do I get 0964 to give the unicode char it represents.
>
> [untested]
>
> use Encode;
>
> open(my $out, '>:utf8', 'somefile.dat') or die "Could not open
> file: $!"; print $out Encode::encode('utf8', $mydata);
> close($out) or die "Could not close file: $!";
>
> Otherwise you could skip the encoding step.
>
> Matt
Thanks Matt.
--
Rawat
------------------------------
Date: Mon, 31 Oct 2005 10:24:20 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: RTF and UTF-8 files in Perl
Message-Id: <dk4rcj$ijv$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>
V S Rawat wrote:
> Matt Garrish wrote:
>
>
>>"V S Rawat" <VSRawat@Invalid.none> wrote in message
>>news:xn0e93zst5r39c000@xananews...
>>
>>>1. How do I open a RTF file as input in Perl and read
>>>formatted ASCII text from it?
>>>
>>
>>You don't. There's no such thing as formatted ASCII text. You
>>could look into a module such as RTF::Tokenizer if you want to
>>parse apart the RTF file and extract the text from it. If you
>>want to know what formatting has been applied you'll also need
>>to check the formatting commands as you go.
>>
>>
>>>2. How do I open a UTF-8 (Unicode) file as output in Perl and
>>>write Unicode text to it?
>>>
>>
>>Assuming your data is not already utf8:
>
>
> I am reading some unicode char codes, and converting them to
> display the unicode chars.
AIUI, it shouldn't be necessary to do this since Perl can work with
Unicode characters in UTF8 form.
AIUI, you should just be able to use any UTF8 capable editor (e.g. VIM)
to write perl code where literal strings contain the unicode characters
you want, just like typing ASCII or Latin-1 characters. These should
display correctly on any UTF8 compatible operating system/display with
the appropriate font.
#!/usr/bin/perl
use strict;
use warnings;
print "Unicode glyph at code point 0x0964 is [।] \n";
The above works OK for me, doubtless my newsreader will mangle the UTF8
text I cut & pasted into it :-)
> Say, my code is ($cod = ) 0964 (hexadec chars) which should lead
> to a unicode char. But, when I do $char = chr($cod), end up
> getting "d" in $char.
>
> How do I get 0964 to give the unicode char it represents.
perldoc perlunicode
perldoc utf8
>>[untested]
>>
>>use Encode;
>>
>>open(my $out, '>:utf8', 'somefile.dat') or die "Could not open
>>file: $!"; print $out Encode::encode('utf8', $mydata);
>>close($out) or die "Could not close file: $!";
>>
>>Otherwise you could skip the encoding step.
>>
>>Matt
>
>
> Thanks Matt.
------------------------------
Date: Mon, 31 Oct 2005 10:53:59 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: RTF and UTF-8 files in Perl
Message-Id: <dk4t47$svo$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>
Ian Wilson wrote:
> V S Rawat wrote:
>
>> Matt Garrish wrote:
>>
>>
>>> "V S Rawat" <VSRawat@Invalid.none> wrote in message
>>> news:xn0e93zst5r39c000@xananews...
>>>
>>>> 1. How do I open a RTF file as input in Perl and read
>>>> formatted ASCII text from it?
>>>>
>>>
>>> You don't. There's no such thing as formatted ASCII text. You
>>> could look into a module such as RTF::Tokenizer if you want to
>>> parse apart the RTF file and extract the text from it. If you
>>> want to know what formatting has been applied you'll also need
>>> to check the formatting commands as you go.
>>>
>>>
>>>> 2. How do I open a UTF-8 (Unicode) file as output in Perl and
>>>> write Unicode text to it?
>>>>
>>>
>>> Assuming your data is not already utf8:
>>
>>
>>
>> I am reading some unicode char codes, and converting them to
>> display the unicode chars.
>
>
> AIUI, it shouldn't be necessary to do this since Perl can work with
> Unicode characters in UTF8 form.
>
> AIUI, you should just be able to use any UTF8 capable editor (e.g. VIM)
> to write perl code where literal strings contain the unicode characters
> you want, just like typing ASCII or Latin-1 characters. These should
> display correctly on any UTF8 compatible operating system/display with
> the appropriate font.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> print "Unicode glyph at code point 0x0964 is [।] \n";
>
Since 0964 is "DEVANGARI DANDA = purna viram * phrase separator" which
isn't in the sort of fonts available on Western Windows PCs, here's an
example which is easier to see if it renders correctly:
#!/usr/bin/perl
use strict;
use warnings;
print "I ♥ UTF8\n";
$ ./utf8.pl
I ♥ UTF8
------------------------------
Date: Mon, 31 Oct 2005 12:24:05 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: RTF and UTF-8 files in Perl
Message-Id: <dk53a2.3uo.1@news.isolution.nl>
Ian Wilson schreef:
> print "Unicode glyph at code point 0x0964 is [।] \n";
print "Unicode glyph at code point 0x0964 is [।] and [\x{0964}]\n";
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 1 Nov 2005 03:41:28 +0100
From: "V S Rawat" <VSRawat@Invalid.none>
Subject: Re: RTF and UTF-8 files in Perl
Message-Id: <xn0e95j3cg8e8r000@xananews>
Ian Wilson wrote:
> AIUI, it shouldn't be necessary to do this since Perl can work
> with Unicode characters in UTF8 form.
In the meantime I have downloaded Activeperl 5.8.0, Build 804.
All 12 MBs of it on my poor dialup.
But, it was every bit worth it. Now, my perl is able to handle
unicode automatically. It is generating Unicode chars from
unicode codes. It is writing to plain text file in unicode. It
is showing out which, on saving in a file, and opening in word,
is showing unicode chars.
However, the display in MSDOS window is not the correct Unicode
character. How do I get a correct display in MSDOS window?
>
> AIUI, you should just be able to use any UTF8 capable editor
> (e.g. VIM) to write perl code where literal strings contain
> the unicode characters you want, just like typing ASCII or
> Latin-1 characters. These should display correctly on any UTF8
> compatible operating system/display with the appropriate font.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> print "Unicode glyph at code point 0x0964 is [।] \n";
>
> The above works OK for me, doubtless my newsreader will mangle
> the UTF8 text I cut & pasted into it :-)
>
My XanaNews reader shows the correct character in above. I had
to copy paste the above in word and save as a .pl file with
UTF-8 encoding. That file duly ran in perl, and though the MSDOS
display was not correct, on redirecting the display to a disc
file, and opening that in word shown the correct unicode
character.
I have downloaded Crimson Editor that I am now using for per.
Though it says that encoding is there, the option does not seem
to work and I could not see any text in unicode character.
Could someone please suggest some free editor for Perl?
> > Say, my code is ($cod = ) 0964 (hexadec chars) which should
> > lead to a unicode char. But, when I do $char = chr($cod),
> > end up getting "d" in $char.
> >
> > How do I get 0964 to give the unicode char it represents.
>
> perldoc perlunicode
> perldoc utf8
OK.
btw, Is there any free download of script availablable anywhere
which does ASCII font conversion (actually Adobe Type Manager's
pfb/pfm font) conversion to Unicode font?
If not source code, even algorithm will do. I have finalised the
mapping of that font to unicode font, now I am developing the
actual conversion module.
Thanks and Regards.
--
Rawat
------------------------------
Date: Sun, 30 Oct 2005 20:52:34 -0800
From: Percival John Hackworth <pjh@mps.com>
Subject: Re: The Evil American Corprotocracy
Message-Id: <pjh-D429BF.20523430102005@comcast.dca.giganews.com>
In article <trtam1hlo9gp4t1vg7kv8jpcgpuc2sqj58@4ax.com>,
robic0@yahoo.com wrote:
> Been at this for 25 years (since writing assemblers on
>
>[brain bilge deleted]
>
> To be continued...
someone needs to take their meds and shouldn't be in the day room using
computers while unsupervised.
--
------------------------------
Date: Mon, 31 Oct 2005 17:57:53 +0100
From: "Tom Van Overbeke" <tomvo@hahaha.be>
Subject: using perl to print yesterday's date, but with formatting options ?
Message-Id: <dk5ime$6le$1@pop-news.nl.colt.net>
Hi,
I need a way to use yesterday's date in a variable. The tricks with 'date'
don't work on my system, but perl does.
so i've got:
perl -le 'print scalar localtime time - 86400' which outputs:
Sun Oct 30 17:56:52 2005
But the format I need is: 30.10.05
Any ideas on how to add this to the above piece of code ?
thanks,
tom.
------------------------------
Date: 31 Oct 2005 20:35:55 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: using perl to print yesterday's date, but with formatting options ?
Message-Id: <slrndmd01c.82e.xx087@smeagol.ncf.ca>
At 2005-10-31 11:57AM, Tom Van Overbeke <tomvo@hahaha.be> wrote:
> Hi,
>
> I need a way to use yesterday's date in a variable. The tricks with 'date'
> don't work on my system, but perl does.
>
> so i've got:
> perl -le 'print scalar localtime time - 86400' which outputs:
subtracting a fixed number of seconds is guaranteed to break twice a
year, for places that have daylight savings.
> But the format I need is: 30.10.05
use Date::Calc qw(Today Add_Delta_Days);
my ($year, $month, $day) = Add_Delta_Days(Today(), -1);
printf "%02d.%02d.%02d", $day, $month, substr($year, 2, 2);
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Mon, 31 Oct 2005 12:57:46 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: using perl to print yesterday's date, but with formatting options ?
Message-Id: <43668c0b$1@usenet.ugs.com>
Glenn Jackman wrote:
> subtracting a fixed number of seconds is guaranteed to break twice a
> year, for places that have daylight savings.
Agreed, That's why there is DateTime :-)
>
>> But the format I need is: 30.10.05
>
> use Date::Calc qw(Today Add_Delta_Days);
> my ($year, $month, $day) = Add_Delta_Days(Today(), -1);
> printf "%02d.%02d.%02d", $day, $month, substr($year, 2, 2);
Or the DateTime version
use strict;
use warnings;
use DateTime;
use DateTime::Format::Strptime;
my $Strp = new DateTime::Format::Strptime(
pattern => '%d.%m.%y',
);
my $dt = DateTime->now()->subtract( days => 1 );
print $Strp->format_datetime($dt);
------------------------------
Date: Mon, 31 Oct 2005 21:40:45 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: using perl to print yesterday's date, but with formatting options ?
Message-Id: <Xns9700A9AB5D079dkwwashere@216.168.3.30>
Glenn Jackman <xx087@freenet.carleton.ca> wrote:
> At 2005-10-31 11:57AM, Tom Van Overbeke <tomvo@hahaha.be> wrote:
>> Hi,
>>
>> I need a way to use yesterday's date in a variable. The tricks
>> with 'date' don't work on my system, but perl does.
>>
>> so i've got:
>> perl -le 'print scalar localtime time - 86400' which outputs:
>
> subtracting a fixed number of seconds is guaranteed to break twice
> a year, for places that have daylight savings.
>
>> But the format I need is: 30.10.05
>
> use Date::Calc qw(Today Add_Delta_Days);
> my ($year, $month, $day) = Add_Delta_Days(Today(), -1);
> printf "%02d.%02d.%02d", $day, $month, substr($year, 2, 2);
printf "%02d.%02d.%02d", $day, $month, $year % 100;
Y10K bug. Your code might be in use longer than you think. :-)
------------------------------
Date: 31 Oct 2005 22:36:57 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: using perl to print yesterday's date, but with formatting options ?
Message-Id: <slrndmd749.b9.abigail@alexandra.abigail.nl>
Tom Van Overbeke (tomvo@hahaha.be) wrote on MMMMCDXLIV September MCMXCIII
in <URL:news:dk5ime$6le$1@pop-news.nl.colt.net>:
^^ Hi,
^^
^^ I need a way to use yesterday's date in a variable. The tricks with 'date'
^^ don't work on my system, but perl does.
^^
^^ so i've got:
^^ perl -le 'print scalar localtime time - 86400' which outputs:
^^ Sun Oct 30 17:56:52 2005
^^
^^ But the format I need is: 30.10.05
^^
^^ Any ideas on how to add this to the above piece of code ?
$ perl -MPOSIX -wle 'print strftime "%d.%m.%y" => localtime time - 86400'
30.10.05
Note that during 2 hours a year, subtracting 86400 seconds will *not* get
you yesterdays date (for one hour, you'll get the day before yesterday,
and for one hour, you'll get todays day).
Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
{["", "Just ", "another ", "Perl ", "Hacker\n"] -> [shift]};
$^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4;
------------------------------
Date: Mon, 31 Oct 2005 18:04:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using perl to print yesterday's date, but with formatting options ?
Message-Id: <3sn143Fp9o1jU1@individual.net>
Tom Van Overbeke wrote:
> I need a way to use yesterday's date in a variable. The tricks with 'date'
> don't work on my system, but perl does.
>
> so i've got:
> perl -le 'print scalar localtime time - 86400' which outputs:
> Sun Oct 30 17:56:52 2005
>
> But the format I need is: 30.10.05
>
> Any ideas on how to add this to the above piece of code ?
Capture the date string in a variable and use the tr/// operator.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 31 Oct 2005 18:25:54 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using perl to print yesterday's date, but with formatting options ?
Message-Id: <3sn2b9Foo0qrU1@individual.net>
Gunnar Hjalmarsson wrote:
> Tom Van Overbeke wrote:
>
>> I need a way to use yesterday's date in a variable. The tricks with
>> 'date' don't work on my system, but perl does.
>>
>> so i've got:
>> perl -le 'print scalar localtime time - 86400' which outputs:
>> Sun Oct 30 17:56:52 2005
>>
>> But the format I need is: 30.10.05
>>
>> Any ideas on how to add this to the above piece of code ?
>
> Capture the date string in a variable and use the tr/// operator.
Sorry, didn't read the question carefully enough.
Either you can get the date components by evaluating localtime() in list
context
perldoc -f localtime
and create the date string you want 'by hand', or you can use one of the
many date modules.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 30 Oct 2005 18:43:04 -0800
From: robic0@yahoo.com
Subject: Re: why the perl docs suck
Message-Id: <pu0bm1ps9qd43cqndin6a8dtcaj60ah7fr@4ax.com>
On Sat, 29 Oct 2005 23:03:45 -0400, "Peter L. Berghold"
<peter@berghold.net> wrote:
>Fred@fred.net wrote:
>
>> I don't fucking *want*
>> to think, I wan't a fucking answer right now!
>
>
>This is a sad self indictment. "I don't want to think... I want an
>answer right now." is an idication to me of a lack of desire to learn.
>
>That's sad.
Yeah but Jim Morrison made millions off that line.
"We want the world and we want it ........... noooowwwwww".
Comes out of most 18-40 yrold's mouths. After 40 you finally
realize it aint coming. Just a fact of life. If your under
40 you want fast everything. How old are you?
------------------------------
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 8592
***************************************