470,604 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

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 7222
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Mark | last post: by
5 posts views Thread by b.stewart | last post: by
8 posts views Thread by Nik Martin | last post: by
1 post views Thread by Kermit Piper | last post: by
7 posts views Thread by Jeffrey Spoon | last post: by
4 posts views Thread by meendar | last post: by
9 posts views Thread by =?Utf-8?B?RGFu?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.