Solved

decrement letters

Posted on 2014-09-16
5
92 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40327280
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
ID: 40327298
Or, it may serve your purposes to
  use Math::String;
or consider
  http://www.perlmonks.org/?node_id=93774
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40327443
$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
ID: 40330529
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
ID: 40330571
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…

738 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