Ask a Question related to PERL Miscellaneous, Design and Development.
-
Francesco Moi #1
How to create an array from a string?
Hello.
I would like to create an array from a string. I tried with:
---------------------------
$string = "1 2 3";
@array1 = [1,2,3];
@array2 = split(/\s/, $string);
print $array1[0] . " - " . $array1[1] . " - " . $array1[2] . "\n";
print $array2[0] . " - " . $array2[1] . " - " . $array2[2] . "\n";
---------------------------
But I get:
----------------------------
ARRAY(0x1674e9c) - -
1 - 2 - 3
-----------------------------
I would like to generate an array of the same type of 'array1' from
'string'. Is it possible?
Thank you very much.
Francesco Moi Guest
-
Array String Property
Hi. I'm newer in asp.net. I doing a derived control of TextBox. well y using a property of array string. But when i use this property in design... -
Is there a way to replace characters in a string/array
I am trying to find a function similar to php's str_replace is there something that will allow me to replace a certain character in a variable? ... -
Cannot create an object of type 'System.String[]' from its representation 'String[] Array'
Hello, I am designing a .net custom control in VS.net 7.1 and my control exposes an array of strings which are supposed to be the items to show. To... -
string concatenation from array
I'm having a bit of difficulty getting a string to attach to itself from an array. Here is the bit of code I'm working on. $wresult = ""; ... -
[PHP] string concatenation from array
Analysis & Solutions <mailto:danielc@analysisandsolutions.com> on Tuesday, August 12, 2003 1:02 PM said: Don't forget the space: $wresult .=... -
Gunnar Hjalmarsson #2
Re: How to create an array from a string?
Francesco Moi wrote:
------------^-----^>
> @array1 = [1,2,3];
Hmm.. Don't you mean:
@array1 = (1,2,3);
--
Gunnar Hjalmarsson
Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
Gunnar Hjalmarsson Guest
-
Tad McClellan #3
Re: How to create an array from a string?
Francesco Moi <francescomoi@europe.com> wrote:
> I would like to create an array from a string.
That is a bad thing to want.
Luckily, that isn't really what you want.
You want to _populate_ an array from a string, not create an array.
Yes?
my @array1 = split /\s+/, "1 2 3";
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
David Oswald #4
Re: How to create an array from a string?
"Francesco Moi" <francescomoi@europe.com> wrote in message
news:5b829932.0308151533.18c7de64@posting.google.c om...There is more than one way to do it.....> Hello.
>
> I would like to create an array from a string. I tried with:
If you want to use some form of literal to enumerate the values assigned to
elements of an array, you can do any of the following:
The list method:
my @array = ( 1, 2, 3 );
The string method:
my @array = split /\s+/, "1 2 3";
The list constructor operator method:
my @array = ( 1 .. 3 );
The word method:
my @array = qw(1 2 3);
There are others that deal with looping and such. But these ought to be
enough.
David Oswald Guest
-
Gunnar Hjalmarsson #5
Re: How to create an array from a string?
Francesco Moi wrote:
$string = "1 2 3";> I need to create an _anonymous_ array (sorry, I din't mention it)
> to be included in @data, e.g.:
>
> @data = (['John','Peter','Sophie'],[1,2,3]);
@data = (['John','Peter','Sophie'], [split /\s/, $string]);
print "$data[0]->[0] - $data[0]->[1] - $data[0]->[2]\n";
print "$data[1]->[0] - $data[1]->[1] - $data[1]->[2]\n";
--
Gunnar Hjalmarsson
Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
Gunnar Hjalmarsson Guest
-
Tad McClellan #6
Re: How to create an array from a string?
Francesco Moi <francescomoi@europe.com> wrote:
> So I would like to create an anonymous array from a string.
[ split /\s+/, "1 2 3" ]
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest



Reply With Quote

