develooper Front page | perl.beginners | Postings from February 2002

RE: convert array to integer

Thread Previous | Thread Next
From:
John Edwards
Date:
February 22, 2002 04:11
Subject:
RE: convert array to integer
Message ID:
2FB59B145095D511A7C90050BAC349F317328B@MAIL
You want to take a sum of all the array elements??

You don't need to convert the array to an interger. Perl handles this
internally. For instance, if you want to treat a text string as a number, or
a number as a text string, perl allows it.

This does what you are after

use strict;
my @array = qw(5 6 7 8);
my $total;
foreach (@array) {
	$total .= $_;
}

$total += 2;

print $total;

HTH

John

-----Original Message-----
From: kitti [mailto:kittij@ttt.co.th]
Sent: 22 February 2002 11:47
To: beginners@perl.org
Subject: convert array to integer


how to convert array to integer

$array[0]=5
$array[1]=6
$array[2]=7
$array[3]=8

change to integer 5678 for calculate 5678+2=5680

thanks,


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About