Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

array of references
I've been thinking about this and not sure how to approach this problem.
Say I want to create an array of 4 array references, thats easy since I
know that there will be 4 array references, how would I do this
dynamically? Say if one I only needed 2 references and another I need 10
array references, is there a way to do this in perl?

Thanks in advance.


Report this thread to moderator Post Follow-up to this message
Old Post
Scott Pham
10-25-04 08:56 PM


RE: array of references
Scott Pham wrote:
> I've been thinking about this and not sure how to approach this
> problem. Say I want to create an array of 4 array references, thats
> easy since I know that there will be 4 array references, how would I
> do this dynamically? Say if one I only needed 2 references and
> another I need 10 array references, is there a way to do this in
> perl?    =20

#!/usr/bin/perl -w
use warnings;
use strict;

my @array;
my $num_child_arrays =3D 10;

for (my $count =3D 0; $count < $num_child_arrays; $count++) {
my $array_ref =3D [ ];
push (@array,$array_ref);
}



Could probably be done in a shorter format as well...

push (@array,[]) for (1..$num_child_arrays);


For more info:

perldoc -f push


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Christian
10-26-04 01:55 AM


Re: array of references
push @array, [] while @array < 10;
also works.


"Ed Christian" <edc@corp.ptd.net> wrote...

push (@array,[]) for (1..$num_child_arrays);

For more info:

perldoc -f push



Report this thread to moderator Post Follow-up to this message
Old Post
Zeus Odin
10-26-04 01:55 AM


RE: array of references
Scott Pham wrote:
> I've been thinking about this and not sure how to approach this
> problem. Say I want to create an array of 4 array references, thats
> easy since I know that there will be 4 array references, how would I
> do this dynamically? Say if one I only needed 2 references and
> another I need 10 array references, is there a way to do this in perl?

It is not necessary to predeclare arrays in Perl. They are by nature dynamic
and you can expand and shrink them as needed. What is the specific problem
you're having?

Report this thread to moderator Post Follow-up to this message
Old Post
Bob Showalter
10-26-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:45 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.