Solved

decrement letters

Posted on 2014-09-16
5
87 Views
Last Modified: 2014-12-23
Hi

I can increment letters but need to decrement the letters

increment is      $A = "A"; $A++;          then  $A = B

I tried to use      $A = "B"; $A++;        but should be $A = A   but it did not work.

Any ideas.

Thanks
0
Comment
Question by:mikeysmailbox1
  • 3
5 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
perldoc perlop
...
   Auto-increment and Auto-decrement
...
      The auto-increment operator has a little extra builtin magic to it.  
...
      The auto-decrement operator is not magical.



Can you use instead something like
  reverse "A" ... "B"
?
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Or, it may serve your purposes to
  use Math::String;
or consider
  http://www.perlmonks.org/?node_id=93774
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
$A = "B"; $A++;        but should be $A = A
No, it should be 'C' since you used '++' again instead of '--'.

Never mind... '--' doesn't work.
0
 
LVL 3

Expert Comment

by:Mark Olsen
Comment Utility
Convert the character to it's ASCII number value via the "ord" function, decrement it, then back to a character via the "chr" function:

my $var = "B";

$var = chr(ord($var) - 1);

print "$var\n";

Open in new window

0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
my $var = "Z";

$var++;

$var = chr(ord($var) - 1);   # is not the the opposite of auto increment;

print "$var\n";

# but it may meet your needs depending on what you would want to use magical auto-decrement for.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

11 Experts available now in Live!

Get 1:1 Help Now