Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-08-2008, 07:58 AM   #1
LQ Newbie
Registered: Jan 2008
Posts: 27

Rep: Reputation: 15
Question arithmetic on alphanumeric in PERL


Is it possible to do arithmetic on alphanumeric data?

Eg: say i get the input as 01F01,01F02 etc.

If i have to generate the numbers till "n", what should my datatype read to perform the operation.
And also let me know how to do it.

~ gaynut
Old 09-08-2008, 08:18 AM   #2
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
interpretted in what radix, hexidecimal? Yes, just prefix with "0x" when interpreting, and use printf to format as hex:
printf "%x\n", (0x2 * 0xf);
Old 09-08-2008, 10:09 AM   #3
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,979

Rep: Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441
Usually, what I prefer to do is to set up a regular-expression, which extracts the "useful" parts of the information while also being sure that the input actually does conform to the expected syntax.

Perl provides a full complement of "printf/scanf"-type formatting routines, and it's also pretty darned smart when it's "type-casting" information to-and-from a string. This is to be expected, since Perl is really a power-tool for manipulating strings.

As you explore your project, look first at CPAN. Open your mind to any possibility that you can find. No matter what you are setting out to do, CPAN has probably already done it. You will either find complete applications or modules that will give you a huge head-start...

Last edited by sundialsvcs; 09-08-2008 at 10:10 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Simple Arithmetic In Bash, Perl and Awk - More Porting LXer Syndicated Linux News 0 05-28-2008 09:41 AM
bash, for loop, and arithmetic rmount Programming 13 05-23-2007 02:27 AM
C fstat, st_uid and alphanumeric userID banan Programming 2 10-08-2006 07:17 PM
Bash arithmetic Blackout_08 Programming 2 06-08-2006 11:37 PM
arithmetic operators in Kylix3 (C++) herbie_52 Programming 2 05-23-2003 08:36 AM

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration