In a few circumstances, such as binding parameters to a database, you may need to do this, but on the whole, as everyone else has pointed out, Perl will do this for you.
If you are using this for one of those few cases, you can change them explicitly like this: @array = ('1','2','3'); @arrayNum = map { $_ + 0 } (@array); This maps every value in @array to its numeric equivalent because it is used in an addition operation. The values are pushed into @arrayNum for later use. This is a hack, so only use it if you need to. In most cases, just let Perl do it for you. -David On Tue, 14 Sep 2004 11:02:13 -0300, Shaw, Matthew <[EMAIL PROTECTED]> wrote: > Edward: > > What you have there is an array with only one scalar element (an array > reference containing 3 values). Note that $array[1] & $array[2] would be > undefined in your example. I think what you intended was to do: > > @array = ('1','2','3'); # An array containing three elements, '1', '2', > '3' > (Or more simply: @array = (1..3); ) > > With regards to switching between string & numeric values, perl will do > this automagically for you. You can just perform whatever math you want > as per normal. Consider the following: > > @array = ( '1', '2', '3'); > print $array[0] + 1; > > Output: 2 > > Hope this helps. > > Matt Shaw > http://www.thinktechnology.ca/ > > > -----Original Message----- > > From: Edward WIJAYA [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, September 14, 2004 10:12 PM > > To: [EMAIL PROTECTED] > > Subject: String to Numeric of an Array > > > > Hi, > > > > How can I change the value of this array: > > > > @array = ['1','2','3']; #which contain "string" numeric > > > > to > > > > @arrayNum = [1,2,3]; #as pure numeric > > > > Regards, > > Edward WIJAY > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>