Solved

decrement letters

Posted on 2014-09-16
5
88 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
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

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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 …

929 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

16 Experts available now in Live!

Get 1:1 Help Now