Re: convert array to integer
Shaun Fryer wrote: > > Try this little baby. Why? > @array = (5, 6, 7, 8); > $integer = print(@array); > chop($integer); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: convert array to integer
Try this little baby. @array = (5, 6, 7, 8); $integer = print(@array); chop($integer); === Shaun Fryer === London Webmasters http://LWEB.NET PH: 519-858-9660 FX: 519-858-9024 === -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: convert array to integer
This may not be a better way, but another way is: my(@array) = (5, 6, 7, 8); my($integer) = sprintf("%1d%1d%1d%1d", @array[0], @array[1], @array[2], @array[3]); -_-Aaron -Original Message- From: Jon Molin [mailto:[EMAIL PROTECTED]] Sent: Friday, February 22, 2002 4:06 AM To: kitti Cc: [EMAIL PROTECTED] Subject: Re: convert array to integer kitti wrote: > > how to convert array to integer > > $array[0]=5 > $array[1]=6 > $array[2]=7 > $array[3]=8 > one way to do it is: my @array = (5, 6, 7, 8); my $some_val; $some_val .= $_ for (@array); another is: my @array = (5, 6, 7, 8); my $some_val = "@array"; $some_val =~ s/[^\d]//g; a third is my @array = (5, 6, 7, 8); my $some_val = 0; my $i = 1; for (reverse @array) { $some_val += $i * $_; $i *= 10; } a fourth, is problay both better, quicker, more efficent and shorter but i leave that to someone else :) /Jon > change to integer 5678 for calculate 5678+2=5680 > > thanks, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: convert array to integer
Kitti wrote: > > 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 $ perl -le' @array = qw(5 6 7 8); print 5678 + 2; print join( "", @array ) + 2; ' 5680 5680 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: convert array to integer
$num=$num-0; You don't need to do this in Perl. There is no distinction between an integer and a string. It's just a scalar. This is something you would have to do in Javascript though. John -Original Message- From: walter valenti [mailto:[EMAIL PROTECTED]] Sent: 22 February 2002 12:12 To: kitti Cc: [EMAIL PROTECTED] Subject: Re: convert array to integer kitti wrote: >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, > In not much elegant... foreach(@array){ $num.=$_; } $num=$num-0; Walter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --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. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: convert array to integer
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:[EMAIL PROTECTED]] Sent: 22 February 2002 11:47 To: [EMAIL PROTECTED] 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. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: convert array to integer
kitti wrote: >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, > In not much elegant... foreach(@array){ $num.=$_; } $num=$num-0; Walter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: convert array to integer
kitti wrote: > > how to convert array to integer > > $array[0]=5 > $array[1]=6 > $array[2]=7 > $array[3]=8 > one way to do it is: my @array = (5, 6, 7, 8); my $some_val; $some_val .= $_ for (@array); another is: my @array = (5, 6, 7, 8); my $some_val = "@array"; $some_val =~ s/[^\d]//g; a third is my @array = (5, 6, 7, 8); my $some_val = 0; my $i = 1; for (reverse @array) { $some_val += $i * $_; $i *= 10; } a fourth, is problay both better, quicker, more efficent and shorter but i leave that to someone else :) /Jon > change to integer 5678 for calculate 5678+2=5680 > > thanks, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]