[28650] in Perl-Users-Digest
Perl-Users Digest, Issue: 10014 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 28 11:10:15 2006
Date: Tue, 28 Nov 2006 08:10:08 -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 Tue, 28 Nov 2006 Volume: 10 Number: 10014
Today's topics:
regex matching exactly 10 digits <jtbutler78@comcast.net>
Re: regex matching exactly 10 digits <mritty@gmail.com>
Re: regex matching exactly 10 digits <jtbutler78@comcast.net>
Re: regex matching exactly 10 digits <MisterPerl@gmail.com>
Re: regex matching exactly 10 digits <bugbear@trim_papermule.co.uk_trim>
Re: regex matching exactly 10 digits <someone@example.com>
Translating RAD-50 code <bol@adv.magwien.gv.at>
Re: Translating RAD-50 code <antispam@randometry.com>
Re: Translating RAD-50 code <benmorrow@tiscali.co.uk>
Re: Validation with XSD using XML::LibXML::Schema, and <nobull67@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Nov 2006 05:58:09 -0800
From: "jtbutler78@comcast.net" <jtbutler78@comcast.net>
Subject: regex matching exactly 10 digits
Message-Id: <1164722289.747483.230390@n67g2000cwd.googlegroups.com>
I am having an issue trying to match exactly 10 digits. I want to
append a '1' in front of 10 digit fax numbers. Numbers longer than 10
digits leave alone. I am using \d{10,10} match at least and at most 10
digits but it still appends a 1 to international numbers. I am missing
something but I am not sure what.
#strip out unneeded chars
$fax_num =~ s/[\s()-]//g;
#append 1 to 10 digit fax number
$fax_num =~ s/(\d{10,10})/1$1/;
------------------------------
Date: 28 Nov 2006 06:07:22 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: regex matching exactly 10 digits
Message-Id: <1164722842.339706.53070@l12g2000cwl.googlegroups.com>
jtbutler78@comcast.net wrote:
> I am having an issue trying to match exactly 10 digits. I want to
> append a '1' in front of 10 digit fax numbers. Numbers longer than 10
> digits leave alone. I am using \d{10,10} match at least and at most 10
Otherwise known as \d{10}
> digits but it still appends a 1 to international numbers. I am missing
> something but I am not sure what.
>
> #strip out unneeded chars
> $fax_num =~ s/[\s()-]//g;
>
> #append 1 to 10 digit fax number
> $fax_num =~ s/(\d{10,10})/1$1/;
You are missing the fact that a regexp doesn't care what *else* is in
the string. You are checking only to see if the string *contains* the
pattern. "At most" does not mean that the string cannot contain more
of that token. It means that this particular piece of the regexp will
not match more than that many. You need to explicitly check that
another digit neither precedes nor follows the ten that you've found:
s/(?<!\d)(\d{10})(?!\d)/1$1/;
Read more about look-ahead and look-behind assertions in:
perldoc perlre
perldoc perlreref
Paul Lalli
------------------------------
Date: 28 Nov 2006 06:17:54 -0800
From: "jtbutler78@comcast.net" <jtbutler78@comcast.net>
Subject: Re: regex matching exactly 10 digits
Message-Id: <1164723474.828631.139920@45g2000cws.googlegroups.com>
Thanks I am reading the backtracking documentation now.
Paul Lalli wrote:
> jtbutler78@comcast.net wrote:
> > I am having an issue trying to match exactly 10 digits. I want to
> > append a '1' in front of 10 digit fax numbers. Numbers longer than 10
> > digits leave alone. I am using \d{10,10} match at least and at most 10
>
> Otherwise known as \d{10}
>
> > digits but it still appends a 1 to international numbers. I am missing
> > something but I am not sure what.
> >
> > #strip out unneeded chars
> > $fax_num =~ s/[\s()-]//g;
> >
> > #append 1 to 10 digit fax number
> > $fax_num =~ s/(\d{10,10})/1$1/;
>
> You are missing the fact that a regexp doesn't care what *else* is in
> the string. You are checking only to see if the string *contains* the
> pattern. "At most" does not mean that the string cannot contain more
> of that token. It means that this particular piece of the regexp will
> not match more than that many. You need to explicitly check that
> another digit neither precedes nor follows the ten that you've found:
>
> s/(?<!\d)(\d{10})(?!\d)/1$1/;
>
> Read more about look-ahead and look-behind assertions in:
> perldoc perlre
> perldoc perlreref
>
> Paul Lalli
------------------------------
Date: 28 Nov 2006 07:16:09 -0800
From: "Mr P" <MisterPerl@gmail.com>
Subject: Re: regex matching exactly 10 digits
Message-Id: <1164726969.236351.44750@45g2000cws.googlegroups.com>
jtbutler78@comcast.net wrote:
> I am having an issue trying to match exactly 10 digits. I want to
> append a '1' in front of 10 digit fax numbers. Numbers longer than 10
> digits leave alone. I am using \d{10,10} match at least and at most 10
> digits but it still appends a 1 to international numbers. I am missing
> something but I am not sure what.
>
> #strip out unneeded chars
> $fax_num =~ s/[\s()-]//g;
>
> #append 1 to 10 digit fax number
> $fax_num =~ s/(\d{10,10})/1$1/;
perhaps
s|^\d{10}$|1$1|;
although not knowing your delimiters, or if there can be more than one
10-digit # per scalar, it's difficult to say with certainty.
Have a nice holiday
------------------------------
Date: Tue, 28 Nov 2006 15:29:53 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: regex matching exactly 10 digits
Message-Id: <456c55f2$0$8714$ed2619ec@ptn-nntp-reader02.plus.net>
Paul Lalli wrote:
>>#append 1 to 10 digit fax number
>>$fax_num =~ s/(\d{10,10})/1$1/;
>
>
> You are missing the fact that a regexp doesn't care what *else* is in
> the string. You are checking only to see if the string *contains* the
> pattern. "At most" does not mean that the string cannot contain more
> of that token. It means that this particular piece of the regexp will
> not match more than that many. You need to explicitly check that
> another digit neither precedes nor follows the ten that you've found:
Depending on the OP's data, the simpler
match
/^\d{10,10}$/
may serve.
BugBear
------------------------------
Date: Tue, 28 Nov 2006 15:36:17 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: regex matching exactly 10 digits
Message-Id: <RHYah.24557$1U5.8776@edtnps90>
jtbutler78@comcast.net wrote:
> I am having an issue trying to match exactly 10 digits. I want to
> append a '1' in front of 10 digit fax numbers. Numbers longer than 10
> digits leave alone. I am using \d{10,10} match at least and at most 10
> digits but it still appends a 1 to international numbers. I am missing
> something but I am not sure what.
>
> #strip out unneeded chars
> $fax_num =~ s/[\s()-]//g;
>
> #append 1 to 10 digit fax number
> $fax_num =~ s/(\d{10,10})/1$1/;
It looks like that instead of appending a '1' you really want to prepend a
'1'. You could do it like this:
$fax_num = "1$fax_num" if $fax_num =~ tr/0-9// == 10;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 28 Nov 2006 12:22:49 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Translating RAD-50 code
Message-Id: <1164712969.579944@proxy.dienste.wien.at>
Hi @ all,
I have files containing data encoded in RAD-50 format.
In this format, 3 characters (A-Z, 0-9, $, ., _, and blank
are stored in 2 bytes (so that each character is coded in
around 5 bits).
I have to read these files, process them and write out the
results again in RAD-50.
On the system, there is a shared library (under Linux, it
would be a .so, but it's VMS, so it's a .EXE), providing
routines to convert RAD-50 to ASCII and ASCII to
RAD-50.
Of course, I could write XS code containing two functions
to perform these conversions, place the XS code in a
module and load it using DynaLoader while use'ing it.
But I think this would be a perfect opportunity for an
IO-layer, so I (and others!) could simply write
open IN,'<:rad50',$input_file;
open OUT,'>:rad50',$output_file;
So my question is: is there documentation how to write
IO layers in XS? Some examples, guidelines?
MTIA for your answers, and kind greetings from Vienna
Ferry
--
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at
------------------------------
Date: Tue, 28 Nov 2006 12:26:56 +0100
From: Ric <antispam@randometry.com>
Subject: Re: Translating RAD-50 code
Message-Id: <ekh6kh$t69$1@online.de>
Isn't this suitable for you?
http://search.cpan.org/~wyant/Encode-RAD50-0.004/lib/Encode/RAD50.pm
Ferry Bolhar schrieb:
> Hi @ all,
>
> I have files containing data encoded in RAD-50 format.
> In this format, 3 characters (A-Z, 0-9, $, ., _, and blank
> are stored in 2 bytes (so that each character is coded in
> around 5 bits).
>
> I have to read these files, process them and write out the
> results again in RAD-50.
>
> On the system, there is a shared library (under Linux, it
> would be a .so, but it's VMS, so it's a .EXE), providing
> routines to convert RAD-50 to ASCII and ASCII to
> RAD-50.
>
> Of course, I could write XS code containing two functions
> to perform these conversions, place the XS code in a
> module and load it using DynaLoader while use'ing it.
>
> But I think this would be a perfect opportunity for an
> IO-layer, so I (and others!) could simply write
>
> open IN,'<:rad50',$input_file;
>
> open OUT,'>:rad50',$output_file;
>
> So my question is: is there documentation how to write
> IO layers in XS? Some examples, guidelines?
>
> MTIA for your answers, and kind greetings from Vienna
>
> Ferry
>
------------------------------
Date: Tue, 28 Nov 2006 12:35:41 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Translating RAD-50 code
Message-Id: <t1nt34-der.ln1@osiris.mauzo.dyndns.org>
Quoth "Ferry Bolhar" <bol@adv.magwien.gv.at>:
>
> I have files containing data encoded in RAD-50 format.
> In this format, 3 characters (A-Z, 0-9, $, ., _, and blank
> are stored in 2 bytes (so that each character is coded in
> around 5 bits).
>
> I have to read these files, process them and write out the
> results again in RAD-50.
>
> On the system, there is a shared library (under Linux, it
> would be a .so, but it's VMS, so it's a .EXE), providing
> routines to convert RAD-50 to ASCII and ASCII to
> RAD-50.
>
> Of course, I could write XS code containing two functions
> to perform these conversions, place the XS code in a
> module and load it using DynaLoader while use'ing it.
It hardly seems worth writing XS for such a simple task. Surely unpack
and a lookup table can handle it?
> But I think this would be a perfect opportunity for an
> IO-layer, so I (and others!) could simply write
>
> open IN,'<:rad50',$input_file;
>
> open OUT,'>:rad50',$output_file;
The interface for writing PerlIO layers in Perl is PerlIO::via, so if
you wanted to write the layer in Perl the interface would end up as
open my $IN, '<:via(rad50)', $input_file;
IMHO this is unnecessarily evil (the user should neither know nor care
whether a layer is implemented in Perl or C), but that's how it is.
> So my question is: is there documentation how to write
> IO layers in XS? Some examples, guidelines?
The documentation is in perliol (did you look?).
A good example of a simple translation layer is PerlIO::eol, on CPAN.
I'm sure you can find others by searching.
Ben
--
#!/bin/sh
quine="echo 'eval \$quine' >> \$0; echo quined"
eval $quine
# [benmorrow@tiscali.co.uk]
------------------------------
Date: 28 Nov 2006 05:43:08 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema
Message-Id: <1164721388.792331.305250@l39g2000cwd.googlegroups.com>
On Nov 28, 2:12 am, huntingseason...@gmail.com wrote:
> Both XML::LibXML::Schema and XML::Validator::Schema error when I
> attempt to validate, yet the XML and XSD files appear to be perfectly
> fine.
> Both fXML and XSD files are quite long, but I will post if necessary.
I can't really see how we can comment if you don't make them available
to us.
If you can't manage to reduce them to a minimal (but complete) test
case then rather than actually posting them it may be better to put
them somewhere public and post a link.
------------------------------
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 10014
****************************************