Solved

decrement letters

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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