CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Combining two arrays to for a md-array

 



jbs
Deleted

Jun 20, 2000, 9:23 AM

Post #1 of 4 (508 views)
Combining two arrays to for a md-array Can't Post

Is there a way to do the following??

@l=("Jack", "James", "Carl");
@j=("Josh", "Jim");
#make an array consisting of @l, and @j
#such that:

@jl=(["Jack", "James", "Carl"],
["Josh", "Jim", ""]

);

I need this to import some data into a main array... Some of lines will not be of equal length! Id appreciate any help!
-jbs


Kanji
User / Moderator

Jun 20, 2000, 9:43 AM

Post #2 of 4 (508 views)
Re: Combining two arrays to for a md-array [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

# Array of arrays ...
@jl = ( [ @j ], [ @l ] );
# $jl[0]->[1] would be "James"
# $jl[1]->[1] would be "Jim"

# Array ...
@jl = ( @j, @l );
# $jl[1] would be "James"
# $jl[3] would be "Jim"</pre><HR></BLOCKQUOTE>


jbs
Deleted

Jun 20, 2000, 4:07 PM

Post #3 of 4 (508 views)
Re: Combining two arrays to for a md-array [In reply to] Can't Post

Is there a way to do this using "unshift"?? There has got to be an easier way other than unreferencing..
-jbs


Kanji
User / Moderator

Jun 20, 2000, 6:15 PM

Post #4 of 4 (508 views)
Re: Combining two arrays to for a md-array [In reply to] Can't Post

If I read your original question right, my first example (array of arrays) would do
@jl = ( [ "Jack", "James", "Carl" ], [ "Josh", "Jim" ] );.

Sure you could unshift, but what's the point? All the following would be the same functionally.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

# assignment
@jl = ( [ @j ], [ @l ] );
# unshift ( lazy )
unshift( @jl, [ @j ], [ @l ] );
# unshift ( verbose )
unshift( @jl, [ @l ] );
unshift( @jl, [ @j ] );</pre><HR></BLOCKQUOTE>

Your afternote (about "importing") confused the intent, but which my second example (array) would do @jl = ( "Jack", "James", "Carl", "Josh", "Jim" );.

No dereferencing needed for this second one, but nor can you extract the original arrrays easily.

Unless you start using other structures (ie, a hashes), I don't see any other way for you to do this.

Perhaps if you explained exactly what you're trying to do I could answer the question you meant instead of the question(s) you asked.

[This message has been edited by Kanji (edited 06-20-2000).]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives