Solved

alphanumeric - finding one less!

Posted on 2002-05-08
4
173 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl script help 12 104
Check only file date not subfolder date before getting folder path 3 76
PERL variable conundrum 9 91
Parse csv file and generate graphs in HTML in bash 8 186
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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