Small adjustment to array

F

Francois

I have an array ( @array ) which i want to change to a list of values like
this:

my $data = ["0", "", "", "3", "", "", "6", "", "", "9", "", "", "12"];

(The numbers are the values in the array)
The length of the array is dynamic... so it could be (0,3,6,9,12) but also
(2,4,6,8,10,12,14,16)

What is the easiest way to do this?
 
G

Gunnar Hjalmarsson

Francois said:
I have an array ...

So, you started in two CGI groups, then you posted the same question
to alt.perl, and now here. Others in this group may be interested in
knowing about the message below:

-------- Original Message --------
Subject: Re: Small adjustment to array
Date: Wed, 27 Aug 2003 10:49:50 +0200
From: Gunnar Hjalmarsson <[email protected]>
Newsgroups:
alt.perl,comp.infosystems.www.authoring.cgi,de.comp.lang.perl.cgi
Followup-To: alt.perl
References: <[email protected]>

Francois wrote (to alt.perl):
I have an array ...

You posted the same question to two CGI groups, and you have already
received some replies there. What you did is called multiposting, and
is considered bad manner on Usenet.

On the other hand, since your question has nothing to do with CGI,
alt.perl is a more appropriate group.
... ( @array ) which i want to change to a list of values like
this:

my $data = ["0", "", "", "3", "", "", "6", "", "", "9", "", "", "12"];

(The numbers are the values in the array)
The length of the array is dynamic... so it could be (0,3,6,9,12)
but also (2,4,6,8,10,12,14,16)

What is the easiest way to do this?

Didn't you learn _anything_ from the discussion in the CGI groups,
such as explaining more clearly what it is you want??
 
F

Francois

Thanks for giving a normal answer! I appreciate that much.
I'm going to try this...

Anno Siegel said:
I have an array ( @array ) which i want to change to a list of values like
this:

my $data = ["0", "", "", "3", "", "", "6", "", "", "9", "", "", "12"];

(The numbers are the values in the array)
The length of the array is dynamic... so it could be (0,3,6,9,12) but also
(2,4,6,8,10,12,14,16)

What is the easiest way to do this?

my $data = [ map { ( $_, '', '') } @array];

This will have two emtpty strings after the last element too.

Anno
 
J

Jürgen Exner

Francois said:
I have an array ( @array ) which i want to change to a list of values
[...]

You may want to contact a namesake of yours who posted exactly the same
question in alt.perl.
Probably he got some advice already.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top