[32294] in Perl-Users-Digest
Perl-Users Digest, Issue: 3561 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 8 11:09:30 2011
Date: Thu, 8 Dec 2011 08:09: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 Thu, 8 Dec 2011 Volume: 11 Number: 3561
Today's topics:
Re: IO::Socket::INET hostname restrictions? <ben@morrow.me.uk>
Re: IO::Socket::INET hostname restrictions? <ben@morrow.me.uk>
iterating through a hash map <fajfusio@wp.pl>
Re: iterating through a hash map <news@lawshouse.org>
Re: iterating through a hash map <ben@morrow.me.uk>
Re: iterating through a hash map <fajfusio@wp.pl>
Re: iterating through a hash map <ken@swiss-soccer.net>
Re: iterating through a hash map <rweikusat@mssgmbh.com>
Re: iterating through a hash map <ken@swiss-soccer.net>
Re: iterating through a hash map <ben@morrow.me.uk>
Re: iterating through a hash map <fajfusio@wp.pl>
Re: Problem configuring OS/2 for installing CPAN packag <dave.r.yeo@gmail.com>
Re: Problem configuring OS/2 for installing CPAN packag <nospam-abuse@ilyaz.org>
Re: Problem configuring OS/2 for installing CPAN packag <ben@morrow.me.uk>
Re: Problem configuring OS/2 for installing CPAN packag <dave.r.yeo@gmail.com>
Re: Problem configuring OS/2 for installing CPAN packag <dave.r.yeo@gmail.com>
Re: simple xml - change tag name <fajfusio@wp.pl>
ways to check for octets outside of the safe ASCII rang <oneingray@gmail.com>
Re: ways to check for octets outside of the safe ASCII <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Dec 2011 09:56:56 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IO::Socket::INET hostname restrictions?
Message-Id: <dfGdndQWk9hVEULTnZ2dnUVZ7rqdnZ2d@bt.com>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> In <Nf-dnZw65uvr7kDTnZ2dnUVZ8tydnZ2d@bt.com>, on 12/05/2011
> at 07:44 PM, Ben Morrow <ben@morrow.me.uk> said:
>
> >That ->new call gives me exactly the same result as you: EINVAL from
> >connect().
>
> Does it have the same faulty logic for multihome?
Yes. MultiHomed just makes ->new call ->connect on all the addresses in
DNS until one succeeds, so for a host with only a single address (or for
one where all addresses will refuse the connection) it makes no
difference.
I think your best way forward is either to drop Timeout and use alarm()
instead, or to just accept that that error is what you get when a
connection is refused. Assuming your kernel is behaving the same as
mine, I don't think you can get that error when you ought to have got a
successful connection, nor for situations like a hostname that doesn't
resolve.
I do intend to report this as a bug in IO::Socket, when I get round to
it.
Ben
------------------------------
Date: Wed, 7 Dec 2011 23:54:09 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IO::Socket::INET hostname restrictions?
Message-Id: <1ua5r8-ac2.ln1@anubis.morrow.me.uk>
Quoth Ben Morrow <ben@morrow.me.uk>:
>
> I do intend to report this as a bug in IO::Socket, when I get round to
> it.
If and when you get gcc working, would you be able to test this patch?
You would need to download and unpack the IO-1.25 tarball from CPAN,
apply the patch, and verify that it both passes 'make test' and gives a
more sensible error in the situation we've been discussing.
If you don't want to install the patched version you can use 'perl
-Mblib' from within the build directory to test the built-but-not-
installed modules. If you do want to install it, it should be perfectly
safe to install with 'make install': it will simply overwrite the IO::*
modules which came with your perl with newer versions.
Ben
diff -ur IO-1.25/lib/IO/Socket.pm IO/lib/IO/Socket.pm
--- IO-1.25/lib/IO/Socket.pm 2009-05-14 00:47:42.000000000 +0100
+++ IO/lib/IO/Socket.pm 2011-12-07 16:35:52.859688028 +0000
@@ -122,12 +122,12 @@
$err = $! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
$@ = "connect: timeout";
}
- elsif (!connect($sock,$addr) &&
- not ($!{EISCONN} || ($! == 10022 && $^O eq 'MSWin32'))
- ) {
- # Some systems refuse to re-connect() to
- # an already open socket and set errno to EISCONN.
- # Windows sets errno to WSAEINVAL (10022)
+ elsif (!getpeername($sock)) {
+ if ($!{ENOTCONN}) {
+ # this read will fail, but will give us the error
+ # from connect(2) in $!
+ sysread $sock, my $tmp, 1;
+ }
$err = $!;
$@ = "connect: $!";
}
------------------------------
Date: Wed, 7 Dec 2011 03:25:38 -0800 (PST)
From: Krzysztof Poc <fajfusio@wp.pl>
Subject: iterating through a hash map
Message-Id: <60ae7ca3-22e5-49dd-b264-767671e1beee@q11g2000vbq.googlegroups.com>
ello
I would like to operate on a "child" elements in following XML
document.
Note that "children" tag may not be present. I may access the specific
child
element as follows (I use XML::TreePP):
$tree->{singers}->{album}->[0]->{children}->{child}->[0]
My question is how can I do my task in a loop. I tried to combine both
"foreach" and "exists" functions but I failed.
Great thanks for help.
<singers>
<album>
<surname> John </surname>
<age> 25 </age>
<children>
<child> Alex </child>
<child> Ares </child>
</children>
<dog> small </dog>
</album>
<album>
<surname> Adam </surname>
<age> 33 </age>
<children>
<child> Anita </child>
<child> Marta </child>
</children>
<dog> medium </dog>
</album>
<album>
<surname> Lan </surname>
<age> 3 </age>
<dog> noDog </dog>
</album>
</singers>
------------------------------
Date: Wed, 07 Dec 2011 13:21:14 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: iterating through a hash map
Message-Id: <69CdnfQIUNbX9ULTnZ2dnUVZ8qGdnZ2d@giganews.com>
On 07/12/11 11:25, Krzysztof Poc wrote:
> My question is how can I do my task in a loop. I tried to combine both
> "foreach" and "exists" functions but I failed.
Krzysztof, be assured that it _can_ be done in a loop. Please show us
what you've coded already and we'll show you where you've gone wrong.
Standing orders for this forum include "code first, then ask questions".
(And also "post a minimal example if you possibly can").
--
Henry Law Manchester, England
------------------------------
Date: Wed, 07 Dec 2011 07:51:30 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: iterating through a hash map
Message-Id: <8sadnWoVPsz_8kLTnZ2dnUVZ7qKdnZ2d@bt.com>
Quoth Krzysztof Poc <fajfusio@wp.pl>:
> ello
>
> I would like to operate on a "child" elements in following XML
> document.
> Note that "children" tag may not be present. I may access the specific
> child
> element as follows (I use XML::TreePP):
I realise you may not want to learn yet another module, but this is a
perfect job for XPath. If I were doing something like this I would
probably use XML::LibXML, which has good XPath support.
That said...
> $tree->{singers}->{album}->[0]->{children}->{child}->[0]
While putting all the ->s in is useful when you are learning, you will
find that with deeply nested structures like this that leaving them out
makes a huge difference to the legibility. In an expression like that
you can leave out all but the first:
$tree->{singers}{album}[0]{children}{child}[0]
(the first is obviously necessary so Perl knows you're talking about a
hashref in $tree rather than an element of the hash %tree).
> My question is how can I do my task in a loop. I tried to combine both
> "foreach" and "exists" functions but I failed.
Here's a hint:
for my $album ( @{ $tree->{singers}{album} } ) {
...
}
The @{...} syntax is probably what you were missing. (Yes, we all know
it's ugly.) Start by (re-)reading the 'Using References' section of
perlreftut.
Ben
------------------------------
Date: Wed, 7 Dec 2011 05:49:10 -0800 (PST)
From: Krzysztof Poc <fajfusio@wp.pl>
Subject: Re: iterating through a hash map
Message-Id: <018f868c-02d3-4379-a7ae-fd7ff031af10@i8g2000vbh.googlegroups.com>
On Dec 7, 2:21=A0pm, Henry Law <n...@lawshouse.org> wrote:
> On 07/12/11 11:25, Krzysztof Poc wrote:
>
> > My question is how can I do my task in a loop. I tried to combine both
> > "foreach" and "exists" functions but I failed.
>
> Krzysztof, be assured that it _can_ be done in a loop. =A0Please show us
> what you've coded already and we'll show you where you've gone wrong.
>
> Standing orders for this forum include "code first, then ask questions".
> (And also "post a minimal example if you possibly can").
>
> --
>
> Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England
Great thanks for feedback.
I've simplified the schama of an XML file. Now there may be only one
child sub element
inside children. I've attached the entire document at the end.
I wrote the following perl script:
#! /usr/bin/perl
use XML::TreePP;
use Tie::IxHash;
$tpp =3D XML::TreePP->new();
$tree =3D $tpp->parsefile( "file.xml" );
if ( exists $tree->{singers}->{album}->{children} ) {
foreach $elem ( $tree->{singers}->{album}->{children} ) {
$elem -> {child} =3D "noChild";
}
}
<singers>
<album>
<surname> John </surname>
<age> 25 </age>
<children>
<child> Ares </child>
</children>
<dog> small </dog>
</album>
<album>
<surname> Adam </surname>
<age> 33 </age>
<children>
<child> Marta </child>
</children>
<dog> medium </dog>
</album>
<album>
<surname> Lan </surname>
<age> 3 </age>
<dog> noDog </dog>
</album>
</singers>
------------------------------
Date: Wed, 7 Dec 2011 12:15:20 -0500
From: Ken Butler <ken@swiss-soccer.net>
Subject: Re: iterating through a hash map
Message-Id: <alpine.DEB.2.00.1112071207170.22245@ken-laptop>
On Wed, 7 Dec 2011, Ben Morrow wrote:
> $tree->{singers}{album}[0]{children}{child}[0]
>
> (the first is obviously necessary so Perl knows you're talking about a
> hashref in $tree rather than an element of the hash %tree).
>
>> My question is how can I do my task in a loop. I tried to combine both
>> "foreach" and "exists" functions but I failed.
>
> Here's a hint:
>
> for my $album ( @{ $tree->{singers}{album} } ) {
> ...
> }
>
> The @{...} syntax is probably what you were missing. (Yes, we all know
> it's ugly.) Start by (re-)reading the 'Using References' section of
> perlreftut.
This I don't understand. I thought the @{} turned a hash (ref) into an
array, whose elements are alternately key, value, key, value,... so that
iterating through the array would *not* simply pull out just the keys.
My code for the above would say something like
for my $album (keys %{$tree->{singers}{album}})
{
...
}
Does that do the same thing as de-reffing the hash ref into an array? If
so, why? (Time to go read perlreftut again, I think.)
Cheers,
Ken.
------------------------------
Date: Wed, 07 Dec 2011 17:32:30 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: iterating through a hash map
Message-Id: <87aa7470ep.fsf@sapphire.mobileactivedefense.com>
Ken Butler <ken@swiss-soccer.net> writes:
> On Wed, 7 Dec 2011, Ben Morrow wrote:
>
>> $tree->{singers}{album}[0]{children}{child}[0]
>>
>> (the first is obviously necessary so Perl knows you're talking about a
>> hashref in $tree rather than an element of the hash %tree).
>>
>>> My question is how can I do my task in a loop. I tried to combine both
>>> "foreach" and "exists" functions but I failed.
>>
>> Here's a hint:
>>
>> for my $album ( @{ $tree->{singers}{album} } ) {
>> ...
>> }
>>
>> The @{...} syntax is probably what you were missing. (Yes, we all know
>> it's ugly.) Start by (re-)reading the 'Using References' section of
>> perlreftut.
>
> This I don't understand. I thought the @{} turned a hash (ref) into an
> array, whose elements are alternately key, value, key, value,... so
> that iterating through the array would *not* simply pull out just the
> keys.
But $tree->{singers}{album} isn't a hash reference its an array
reference. At least, your attempt at subscripting it strongly suggests
this.
------------------------------
Date: Wed, 7 Dec 2011 12:43:21 -0500
From: Ken Butler <ken@swiss-soccer.net>
Subject: Re: iterating through a hash map
Message-Id: <alpine.DEB.2.00.1112071242280.22245@ken-laptop>
On Wed, 7 Dec 2011, Rainer Weikusat wrote:
> Ken Butler <ken@swiss-soccer.net> writes:
>> On Wed, 7 Dec 2011, Ben Morrow wrote:
>>
>>> $tree->{singers}{album}[0]{children}{child}[0]
>>>
>>> (the first is obviously necessary so Perl knows you're talking about a
>>> hashref in $tree rather than an element of the hash %tree).
>>>
>>>> My question is how can I do my task in a loop. I tried to combine both
>>>> "foreach" and "exists" functions but I failed.
>>>
>>> Here's a hint:
>>>
>>> for my $album ( @{ $tree->{singers}{album} } ) {
>>> ...
>>> }
>>>
>>> The @{...} syntax is probably what you were missing. (Yes, we all know
>>> it's ugly.) Start by (re-)reading the 'Using References' section of
>>> perlreftut.
>>
>> This I don't understand. I thought the @{} turned a hash (ref) into an
>> array, whose elements are alternately key, value, key, value,... so
>> that iterating through the array would *not* simply pull out just the
>> keys.
>
> But $tree->{singers}{album} isn't a hash reference its an array
> reference. At least, your attempt at subscripting it strongly suggests
> this.
OK, missed that, thanks.
------------------------------
Date: Wed, 07 Dec 2011 16:10:17 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: iterating through a hash map
Message-Id: <yM-dncS5rI3UeULTnZ2dnUVZ7qudnZ2d@bt.com>
Quoth Ken Butler <ken@swiss-soccer.net>:
>
>
> On Wed, 7 Dec 2011, Ben Morrow wrote:
>
> > $tree->{singers}{album}[0]{children}{child}[0]
> >
> > (the first is obviously necessary so Perl knows you're talking about a
> > hashref in $tree rather than an element of the hash %tree).
> >
> >> My question is how can I do my task in a loop. I tried to combine both
> >> "foreach" and "exists" functions but I failed.
> >
> > Here's a hint:
> >
> > for my $album ( @{ $tree->{singers}{album} } ) {
> > ...
> > }
> >
> > The @{...} syntax is probably what you were missing. (Yes, we all know
> > it's ugly.) Start by (re-)reading the 'Using References' section of
> > perlreftut.
>
> This I don't understand. I thought the @{} turned a hash (ref) into an
> array, whose elements are alternately key, value, key, value,... so that
> iterating through the array would *not* simply pull out just the keys.
No, that's %{} in list context. @{} (in list context) turns an arrayref
into a list.
> My code for the above would say something like
>
> for my $album (keys %{$tree->{singers}{album}})
Did you try this? I would expect a 'Not a HASH reference' error, which
would have given you some idea of what was wrong.
Ben
------------------------------
Date: Thu, 8 Dec 2011 04:31:19 -0800 (PST)
From: Krzysztof Poc <fajfusio@wp.pl>
Subject: Re: iterating through a hash map
Message-Id: <e015f679-5dd6-44c7-8d42-2658ac22bc74@u5g2000vbd.googlegroups.com>
On Dec 7, 11:10=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Ken Butler <k...@swiss-soccer.net>:
>
>
>
>
>
> > On Wed, 7 Dec 2011, Ben Morrow wrote:
>
> > > =A0 =A0$tree->{singers}{album}[0]{children}{child}[0]
>
> > > (the first is obviously necessary so Perl knows you're talking about =
a
> > > hashref in $tree rather than an element of the hash %tree).
>
> > >> My question is how can I do my task in a loop. I tried to combine bo=
th
> > >> "foreach" and "exists" functions but I failed.
>
> > > Here's a hint:
>
> > > =A0 =A0for my $album ( @{ $tree->{singers}{album} } ) {
> > > =A0 =A0 =A0 =A0...
> > > =A0 =A0}
>
> > > The @{...} syntax is probably what you were missing. (Yes, we all kno=
w
> > > it's ugly.) Start by (re-)reading the 'Using References' section of
> > > perlreftut.
>
> > This I don't understand. I thought the @{} turned a hash (ref) into an
> > array, whose elements are alternately key, value, key, value,... so tha=
t
> > iterating through the array would *not* simply pull out just the keys.
>
> No, that's %{} in list context. @{} (in list context) turns an arrayref
> into a list.
>
> > My code for the above would say something like
>
> > for my $album (keys %{$tree->{singers}{album}})
>
> Did you try this? I would expect a 'Not a HASH reference' error, which
> would have given you some idea of what was wrong.
>
> Ben
Great thanks for help to all of you. Finally Ben Marrow's hint works
for me.
------------------------------
Date: Tue, 06 Dec 2011 18:41:31 -0800
From: Dave Yeo <dave.r.yeo@gmail.com>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <4eded25c$0$9704$c3e8da3$1cbc7475@news.astraweb.com>
Shmuel (Seymour J.) Metz wrote:
> Paul's emx or the one that came with my system?
How is GCC setup on your system? Entries in config.sys?
Dave
------------------------------
Date: Wed, 7 Dec 2011 21:43:23 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <slrnjdvnfr.aft.nospam-abuse@panda.math.berkeley.edu>
On 2011-12-07, Ben Morrow <ben@morrow.me.uk> wrote:
>> One should use / in perl on OS/2.
>
> Is there some strong reason for that, or is it just to avoid doubling
> backslashes in Perl strings?
system() uses pdksh for which \ is special.
>> Yes, it allows it - but one should quote it (same as on Win* - / is
>> cmd's word separator).
>
> Interesting. I never knew that...
Actually, (though it is not documented) I think that it is qr((?=/))
which is a word separator; checking... No, it is only for the FIRST
word; go figure. Anyway, the OS does not care about / vs \; the shell
does not care as far as they are inside quotes...
>> cmd.exe has nothing to do with perl on os/2.
>
> Does perl on OS/2 not use cmd for single-arg system?
I won't use cmd PERIOD (unless explicitly run by user, or implicitly
by pdksh - to execute .cmd etc files).
> If I were to run
> something like
>
> system "dir >nul";
>
> what would be performing the redirection?
The shell (=pdksh) - if it can find GNU's dir.exe.
Ilya
------------------------------
Date: Wed, 07 Dec 2011 16:02:09 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <-cmdnezLAPj8f0LTnZ2dnUVZ8madnZ2d@bt.com>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2011-12-07, Ben Morrow <ben@morrow.me.uk> wrote:
> >> One should use / in perl on OS/2.
> >
> > Is there some strong reason for that, or is it just to avoid doubling
> > backslashes in Perl strings?
>
> system() uses pdksh for which \ is special.
Oh, I see. That changes *everything*.
Shmuel: all paths in Config_heavy.pl should use *forward* slashes.
Ben
------------------------------
Date: Wed, 07 Dec 2011 23:36:27 -0800
From: Dave Yeo <dave.r.yeo@gmail.com>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <4ee068fd$0$9701$c3e8da3$1cbc7475@news.astraweb.com>
Shmuel (Seymour J.) Metz wrote:
> In<4eded25c$0$9704$c3e8da3$1cbc7475@news.astraweb.com>, on 12/06/2011
> at 06:41 PM, Dave Yeo<dave.r.yeo@gmail.com> said:
>
>> >How is GCC setup on your system? Entries in config.sys?
> Currently none. At the moment the only C compilation that I want to do
> is for Net::DNS.
>
> To clarify some of my other posts, Q: is my system and U: is Paul's
> build environment, each of which has gcc.
So how are you setting up the environment?
Dave
------------------------------
Date: Thu, 08 Dec 2011 07:40:34 -0800
From: Dave Yeo <dave.r.yeo@gmail.com>
Subject: Re: Problem configuring OS/2 for installing CPAN packages
Message-Id: <4ee0daa1$0$9670$c3e8da3$1cbc7475@news.astraweb.com>
Shmuel (Seymour J.) Metz wrote:
> In<4ee068fd$0$9701$c3e8da3$1cbc7475@news.astraweb.com>, on 12/07/2011
> at 11:36 PM, Dave Yeo<dave.r.yeo@gmail.com> said:
>
>> So how are you setting up the environment?
>
> I'd been relying on README.OS2 and the web page[1] for his build, both
> of which are sketchy. As an example, U:\usr\lib has a dozen *.dll
> files, but there's nothing about including it in LIBPATH. Maybe
> they're needed and maybe they're irrelevant; it's a guessing game.
IIRC the only one needed is libc063.dll (or libc064.dll if you've
updated) which just needs to be in LIBPATH but see below.
>
> Do I need to run a configuration script other than makeomflibs?
You need to set up the environment for GCC. I'm not sure how Pauls build
environment is setup but it seems to refer to gcc335.cmd. Open a cmd
prompt, run gcc335, then try to build the CPAN package in that cmd
prompt. Start out with gcc --version to see if gcc is even kinda working.
The environment needs PATH, C_INCLUDE_FLAGS, CPLUS_INCLUDE_FLAGS, and
LIBRARY_PATH setup correctly for the version of GCC you are using.
>
> One other piece is that the CPAN builds require that the working
> directory be the directory into which I untarred the package, rather
> than u:\.
>
> [1]<http://os2ports.smedley.info/index.php?page=build-environment>
>
Dave
------------------------------
Date: Wed, 7 Dec 2011 02:49:33 -0800 (PST)
From: Krzysztof Poc <fajfusio@wp.pl>
Subject: Re: simple xml - change tag name
Message-Id: <a0945b41-2d4f-4266-925d-4bb3fa7c2a52@n10g2000vbg.googlegroups.com>
On Dec 6, 3:42=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Henry Law <n...@lawshouse.org>:
>
>
>
> > On 06/12/11 11:24, Krzysztof Poc wrote:
>
> > > Thanks for help. It works. Unfortunately the output XML does not
> > > resemble the
> > > input XML. The format differs a lot. I used "AttrIndent =3D> =A01" an=
d it
> > > still differs a
> > > lot. Can I force Simple::XML to produce exactly the same text format
> > > for output
>
> > One significant point about XML is that its textual format doesn't
> > matter, at least not in every respect. =A0For example:
>
> > <sometag foo=3D"bar" bar=3D"blatz">
> > =A0 =A0<anothertag/>
> > </sometag>
>
> > is in XML terms exactly equivalent to
>
> > <sometag bar=3D"blatz" foo=3D"bar"><anothertag></anothertag></sometag>
>
> No it isn't. Whitespace within an element is part of the character data
> for that element (after newline normalisation).
>
> > So your exact-equivalence of the text format (a) doesn't really make
> > sense, as far as you've explained it; and (b) isn't really the domain o=
f
> > an XML parser.
>
> Preserving <foo/> vs. <foo></foo> is not the job of a XML parser.
> Passing all the character data, including whitespace, is.
>
> In practice, many applications of XML don't care about whitespace, and
> XML::Simple was written for them. But a decent general-purpose XML
> parser ought to preserve it.
>
> Ben
Thanks for help. I started using XML:TreePP module and it makes most
of the
things to me.
------------------------------
Date: Thu, 08 Dec 2011 11:15:35 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: ways to check for octets outside of the safe ASCII range?
Message-Id: <861usfhf6g.fsf@gray.siamics.net>
I wonder, what's the (time-)efficient way to an octet string,
for "ASCII safety"?
The string is a POSIX filename, and POSIX is known to allow for
arbitrary octet sequences (except those with ASCII NUL codes)
for filenames. The tool I'm developing would store such
filenames in an encoding-agnostic way (i. e., as BLOB's), unless
it's certain that those are "safe ASCII."
The check I've used in [1] is like:
## count the "unsafe" octets (outside of the [32, 126] range)
my $unsafe
= grep { $_ < 32 || $_ > 126 } (unpack ("C*", $filename));
but I'm curious if there's a way better than unpacking the octet
sequence into a vector (Perl list)?
TIA.
[1] news:86liqogt8g.fsf@gray.siamics.net
http://groups.google.com/group/alt.sources/msg/0ae6c64f26aea630
--
FSF associate member #7257
------------------------------
Date: Thu, 08 Dec 2011 14:52:12 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: ways to check for octets outside of the safe ASCII range?
Message-Id: <874nxbt8tf.fsf@sapphire.mobileactivedefense.com>
Ivan Shmakov <oneingray@gmail.com> writes:
> I wonder, what's the (time-)efficient way to an octet string,
> for "ASCII safety"?
>
> The string is a POSIX filename, and POSIX is known to allow for
> arbitrary octet sequences (except those with ASCII NUL codes)
> for filenames. The tool I'm developing would store such
> filenames in an encoding-agnostic way (i. e., as BLOB's), unless
> it's certain that those are "safe ASCII."
>
> The check I've used in [1] is like:
>
> ## count the "unsafe" octets (outside of the [32, 126] range)
> my $unsafe
> = grep { $_ < 32 || $_ > 126 } (unpack ("C*", $filename));
>
> but I'm curious if there's a way better than unpacking the octet
> sequence into a vector (Perl list)?
Assuming that ASCII is taken for granted, an obvious other idea would
be
$filename =~ /[\x0-\x20\x7f-\xff]/
This will probably also need a 'use bytes'.
------------------------------
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 3561
***************************************