Operating System - Linux
1828366 Members
3065 Online
109976 Solutions
New Discussion

Perl processing issue Interesting name characters.

 
SOLVED
Go to solution
Steven E. Protter
Exalted Contributor

Perl processing issue Interesting name characters.

Got a little perl snippet.
------begin code snippet-----
foreach $L1 (A..z) {
foreach $L2 (A..z) {
$L = $L1.$L2 ;

-----end code snippet---------
#
#
# $L is the first two characters of someones name.
What happens after this is a ldapsearch for a list of names. Basically an ldap search requeset is built based on the first two letters of the last name.

Question at hand is what happens if someone's name has a non-standard character in it what happens?

Lets say the users last name is:
D'gostino?

I'm betting I know the answer to this one, which is that D'gostino up there never gets processed.

Bunny for confirmation of this.

If there is a quick modification of the first two lines of code that will include those with aprostrophe's in the name please re-write and post.

Bunny for this after I test the code and nothing else breaks.

This seems like a job for procura or A. Clay.

Regards,

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor
Solution

Re: Perl processing issue Interesting name characters.

Hi Steven:

Of course, the loop shown will never produce $L with a "non-standard" character such as an apostrophe. You could amend the isolated snippet to something covering a larger set like this:

foreach $L1 (A..Z) {
foreach $L2 (a..z, qw(')) {
$L = $L1.$L2 ;
}
}

This generates combinations that begin with an uppercase letter (only) and follow that with an uppercase, a lowercase, or an apostrophe, covering names like: "DeBusk", "D'gostino", "Protter", etc.

Regards!

...JRF...

Steven E. Protter
Exalted Contributor

Re: Perl processing issue Interesting name characters.

Correction: Or JRF.

Looks like you got both bunnies with one post.

I'll test it in the morning(Israel time).

Thanks for your help.

Bunnie@JRF

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
H.Merijn Brand (procura
Honored Contributor

Re: Perl processing issue Interesting name characters.

syntax error under use strict:

Global symbol "$L1" requires explicit package name at xx.pl line 6.
Global symbol "$L2" requires explicit package name at xx.pl line 7.
Global symbol "$L" requires explicit package name at xx.pl line 8.
Global symbol "$L1" requires explicit package name at xx.pl line 8.
Global symbol "$L2" requires explicit package name at xx.pl line 8.
Bareword "A" not allowed while "strict subs" in use at xx.pl line 6.
Bareword "z" not allowed while "strict subs" in use at xx.pl line 6.
Bareword "A" not allowed while "strict subs" in use at xx.pl line 7.
Bareword "z" not allowed while "strict subs" in use at xx.pl line 7.
Execution of xx.pl aborted due to compilation errors.

No lexicals, barewords and ranges that include characters that are not supposed to be included ('A' .. 'z' includes '[', '\', ']', '^', '_', and '`'), and it's not portable to EBCDIC

Now let's start with rewriting it to proper Perl:
--8<---
#!pro/bin/perl

use strict;
use warnings;

foreach my $L1 ('A' .. 'z') {
foreach my $L2 ('A' .. 'z') {
my $L = $L1.$L2;
}
}
-->8---

Code rewrite:

foreach my $l1 ('A' .. 'Z', 'a' .. 'z') {
foreach my $l2 (map { chr } 32 .. 127) {
my $L = "$l1$l2";
}
}

I do not have enough LDAP knowledge to verify the LDAP questions.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
LiPEnS
Valued Contributor

Re: Perl processing issue Interesting name characters.

Hi

foreach $L1 (A..z) {
foreach $L2 (32..126) {
$L = $L1.chr($L2) ;
}
}

Regards LiPEnS
Steven E. Protter
Exalted Contributor

Re: Perl processing issue Interesting name characters.

Not really and ldap question. Its an ancillary piece of information for the curious.

Merijn, I don't quite understand your post and it looks partially distorted by itrc.

I guess another good question is besides apostrophe's are there any other strange characters I have to look for?

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
H.Merijn Brand (procura
Honored Contributor

Re: Perl processing issue Interesting name characters.

foreach my $l1 ('A' .. 'Z', 'a' .. 'z') {
foreach my $l2 (map { chr } 32 .. 127) {
my $L = "$l1$l2";
}
}

JRF was a faster typer.

1. I think you should *ALWAYS* program/script strict-safe: use lexicals, use strict, use -w or warnings
2. The range bounds should be quoted
3. The range should be explicit: 'A'..'z' IS NOT the same as 'A'..'Z','a'..'z'
4. The inner foreach ranges from space (character 32 or 0x20) to DEL (character 127 or 0x7F)

$l1.$l2 is exaclty the same as $l1.$l2

As a side note, what do you do with diacriticals?

à (A-acute), à (A-ring), Š(l-stroke), ë (e-diaeresis), etc, etc

They usually fall outside of ASCII, so you will need to know how your LDAP source stores it in order to get it. Unicode (UTF-8, UTF-16, ...), iso-8859-??, iso-10646-1, ...
FWIW Names *starting* with a character outside of the range 'A'..'Z','a'..'z' also drop out of my stats, because HP does not have them in the index pages :)

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor

Re: Perl processing issue Interesting name characters.

Hi Steven & Merijn:

Merijn wrote that "JRF was a faster typer" and perhaps that's true, *BUT* Merijn's pointers really complete the lesson, as they always do.

*ALWAYS* using the 'strict' and 'warnings' pragmas saves everyone in the long run. Haste makes waste and discipline in code developement gives not only the code, but the maintainer too, a long career. :-))

Regards to you both!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Perl processing issue Interesting name characters.

Now I can hand out double bunnies to both.

Kewl.

ITRC. There is no better place.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: Perl processing issue Interesting name characters.

I'm closing for now. I've used JRF's code from his first post.

Even though he acknowledges it could be improved upon, its a production problem and the simple solution makes the production problem go away.

I will try and build a better solution that takes into account future strangeness in last name definition.

Aside,

JRF, A pleasure to work with you. Your Perl skills obviously exceed mine, but you gave me the confidence to test a solution and confirmed my problem definition.

I know life changes and people do to, but It is a pleasure to have you back and I learn from every post you make that I read.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com