freelanceprogrammers.org Forum Index » Perl
Array creation
Joined: 02 Sep 2004
Posts: 4
Array creation
Hi people,
I am newbie to perl..i have a doubt...
I want to create some 20 arrays using a `for` loop
something like @A1 @A2 @A3....@... this
possible..??
i wrote a code like this for it...
for($i=1;$i++;$i<=20)
{
@A[$i]=`blahblah`;
}
but i was pretty sure it was wrong..(tried executing
it and got an error...)
can this be achieved...?
TIA
Rgds
Harish
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Joined: 24 Jun 2005
Posts: 3
Array creation
didn`t clear with your requirement ,
in loop u can create n number of Arrays but u want to only creation of arrays or
also want to store values in that array while creationg the array. if yes then
how u are going to store.
email your requirement clearly !!
cheers
Harish S <harish85_bt@...> wrote:
Hi people,
I am newbie to perl..i have a doubt...
I want to create some 20 arrays using a `for` loop
something like @A1 @A2 @A3....@... this
possible..??
i wrote a code like this for it...
for($i=1;$i++;$i<=20)
{
@A[$i]=`blahblah`;
}
but i was pretty sure it was wrong..(tried executing
it and got an error...)
can this be achieved...?
TIA
Rgds
Harish
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------
YAHOO! GROUPS LINKS
Visit your group "perl_official" on the web.
To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
[Non-text portions of this message have been removed]
Joined: 02 Sep 2004
Posts: 4
Array creation
To Ravish..
Thanks for the concern....
i want to create arrays as well as store values in
them...by splitting a variable....using `split`.
Rgds
Harish
--- Ravish Kumar <kumarabish@...> wrote:
> didn`t clear with your requirement ,
> in loop u can create n number of Arrays but u want
> to only creation of arrays or also want to store
> values in that array while creationg the array. if
> yes then how u are going to store.
> email your requirement clearly !!
> cheers
>
> Harish S <harish85_bt@...> wrote:
> Hi people,
> I am newbie to perl..i have a doubt...
> I want to create some 20 arrays using a `for` loop
> something like @A1 @A2 @A3....@... this
> possible..??
> i wrote a code like this for it...
>
> for($i=1;$i++;$i<=20)
> {
> @A[$i]=`blahblah`;
> }
>
> but i was pretty sure it was wrong..(tried executing
> it and got an error...)
>
> can this be achieved...?
>
> TIA
> Rgds
> Harish
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>
>
>
>
> ---------------------------------
> YAHOO! GROUPS LINKS
>
>
> Visit your group "perl_official" on the web.
>
> To unsubscribe from this group, send an email
> to:
> perl_official-unsubscribe@yahoogroups.com
>
> Your use of Yahoo! Groups is subject to the
> Yahoo! Terms of Service.
>
>
> ---------------------------------
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>
> [Non-text portions of this message have been
> removed]
>
>
HARISH.S
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
Joined: 01 May 2004
Posts: 7
Array creation
Harish S wrote:
> Hi people,
> I am newbie to perl..i have a doubt...
> I want to create some 20 arrays using a `for` loop
> something like @A1 @A2 @A3....@... this
> possible..??
> i wrote a code like this for it...
>
> for($i=1;$i++;$i<=20)
> {
> @A[$i]=`blahblah`;
> }
>
> but i was pretty sure it was wrong..(tried executing
> it and got an error...)
>
> can this be achieved...?
>
> TIA
> Rgds
> Harish
>
Let me start with the error you got. I assume you`re using a
standard Perl 5 installation. In this case, assigning a value to an
element of an array, which you tried to do, should be done like this:
$A[$i] = `blahblah`;
If you want to assign values to a 20-element array, do it like this:
foreach $i (0 .. 19) {
$A[$i] = `blahblah`;
}
And if you really want to create 20 arrays in a loop (i strongly
advice you not to do this), this is how it`s done (strict must not
be on):
foreach $i (1 .. 20) {
${`A`.$i}[0] = `blahblah`;
}
With that, you`ll have the arrays @A1, @A2, @A3, ..., @A20 with the
value of their first elements as `blahblah.` However, unless it`s
absolutely necessary, please don`t do this.
You could prolly use double arrays instead.
--
eman
http://www.bloodpet.tk/ || http://www.bloodpet.dsl.ph/
gpg --keyserver pgp.mit.edu --recv-keys 4C683E4C
Registered Linux User #287022
+63(2)455-3222
Books just wanna be FREE! See what I mean at:
http://bookcrossing.com/friend/bloodpet
[Non-text portions of this message have been removed]
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







