Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

decrement letters

Posted on 2014-09-16
5
Medium Priority
?
95 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 84

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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

718 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