473,230 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

adding ascii values in string

I'm coming back to Perl after a long absence. I am trying to add up the
ascii values of the characters in a string. Can anyone refresh my memory?

Thanks.
Jul 19 '05 #1
4 7382
On Mon, 15 Mar 2004 at 16:39 GMT, Neil W. wrote:
I'm coming back to Perl after a long absence. I am trying to add up the
ascii values of the characters in a string. Can anyone refresh my memory?

Thanks.

That would be (untested):

#!/usr/bin/perl
use strict;
use warnings;

my $chars = 'abcdef123';
my $ord_sum;

$ord_sum += ord $_ foreach split //, $chars;

print $ord_sum;

__END__

prints: 747
Jul 19 '05 #2
Neil W. wrote:
I'm coming back to Perl after a long absence. I am trying to add up the
ascii values of the characters in a string. Can anyone refresh my memory?


perldoc -f unpack

Note where it documents how to use the unpack() function to calculate
checksums, such as to emulate the System V 'sum' program.
-Joe
Jul 19 '05 #3
Thanks! Will test it out. - Neil

---------------------------------

"Roel van der Steen" <ro*******@st2x.net> wrote in message
news:sl**********************@localhost.localdomai n...
On Mon, 15 Mar 2004 at 16:39 GMT, Neil W. wrote:
I'm coming back to Perl after a long absence. I am trying to add up the
ascii values of the characters in a string. Can anyone refresh my memory?

Thanks.

That would be (untested):

#!/usr/bin/perl
use strict;
use warnings;

my $chars = 'abcdef123';
my $ord_sum;

$ord_sum += ord $_ foreach split //, $chars;

print $ord_sum;

__END__

prints: 747
Jul 19 '05 #4
Thanks for the tip. I'm doing a variation on a checksum. - Neil

-------------------------------

"Joe Smith" <Jo*******@inwap.com> wrote in message
news:5mp5c.16994$1p.303958@attbi_s54...
Neil W. wrote:
I'm coming back to Perl after a long absence. I am trying to add up the
ascii values of the characters in a string. Can anyone refresh my memory?


perldoc -f unpack

Note where it documents how to use the unpack() function to calculate
checksums, such as to emulate the System V 'sum' program.
-Joe
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mark | last post by:
My PHP script builds a table that is too wide to fit on the paper. Two of the columns contain strings that are more lengthy than data in the other columns. I can get the table to fit by letting...
5
by: b.stewart | last post by:
I have only been using C++ for a few afternoons and i still get confused at nearly every line i type so maybe someone here can help me. Im trying to write a small program that can change a...
1
by: Sagaert Johan | last post by:
Hi I am construncting a string containing some control chars (STX/ETX) I noticed that adding a byte with value 2 is the same as adding a character '2' ??? How can i solve this problem ?...
8
by: Nik Martin | last post by:
If I receive a message from the .net sockets class, it's a byte array. The original message is an ASCII string,like "70,70,70,70,70,0,0,0,0". The commas here represent individual bytes. The 70's...
1
by: Kermit Piper | last post by:
Hello, I have a function that lets me convert one character and throw an alert with the corresponding ASCII value, but what I am having trouble with is applying it to a text box. What I'm trying...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
6
by: ssetz | last post by:
Hello, For work, I need to write a password filter. The problem is that my C+ + experience is only some practice in school, 10 years ago. I now develop in C# which is completely different to me....
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.