Solved

alphanumeric - finding one less!

Posted on 2002-05-08
4
163 Views
Last Modified: 2010-03-05
Hi

I need some help to chamge the end character in a string of letters to the character or number which is one less based on alphanumeric characters and maintaining case

example string 1 - " /YEZ/NOZ1/B2FREE/fixed "
example string 2 - " /YEZ/NOZ1/B2FRE3/fixed "

I want to become

example string 1 - " /YEZ/NOZ1/B2FRED/fixed "
example string 2 - " /YEZ/NOZ1/B2FRE2/fixed "

I have tried using "$string =~ s/$end/$end -1/"

but it doesn't work becase it is not a number and sometimes it finishes with "a letter/fixed" sometimes "a number/fixed"

"fixed" is the known string which is always constant...
"/APHANUM/APHANUM/APHANUM/" is the dynamic bit and it is always the character before "/fixed" that I need to be one less...

Can anyone tell me how to do it?

thanks

Jilly  
0
Comment
Question by:jillybabe
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
holli earned 100 total points
ID: 6996554
this is one way:

$b="/YEZ/NOZ1/B2FREE/fixed";
$a="/YEZ/NOZ1/B2FRE3/fixed";

$a=~s|(.{1})/fixed|chr(ord($1)-1).'/fixed'|e;
$b=~s|(.{1})/fixed|chr(ord($1)-1).'/fixed'|e;

print "$a\$b";


regards,

holli
0
 
LVL 1

Expert Comment

by:japhyRPI
ID: 6998068
What should "BAA" decrease to?  "AZZ"?  And how about "FR0"?  That's a zero, so should it be "FQ9"?  We need more assistance with these boundary cases.  It's far easier to INCREMENT than to decrement.
0
 

Author Comment

by:jillybabe
ID: 6998242
Great that did it !

Thanks holli and you too japhyRPI

Jilly
0
 
LVL 1

Expert Comment

by:japhyRPI
ID: 6998715
Jilly, I'm just warning you that the current response turns "BAA" into "BA@", "FR0" into "FR/", and "STa" into "ST`".  To overcome these situations, you're going to need a slightly different regex.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delete query using perl dbi 3 96
pattern matching in perl 2 101
Ned Perl Snippet to Read Files in Directory 5 62
perl: Cleaning meta tags using RegEX 12 64
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now