Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

$count+=7 But in @array[0] ??

$count+=7 But in @array[0] ??

$count+=7 But in @array[0] ??

I´m new 2 Perl and I want to know how I
can increase an array from
@array[0] to @array[2] to @array[4] ond so on

It is simple with $count+=2 but how do I do it in some array

Thanks for your help

RE: $count+=7 But in @array[0] ??

Hello visitor,
welcome and I don't understand the question....  

Are you trying to simply increase the number of elements in the list?  If so,

push @array,1; # will add an element with the value of 1 to the end of the @array.

Or, are you wanting to increase the value of one element in an @array?  If so,....
@array = ('1','3','5','7','9');
# the second element is 3
# now, the second element is 10.

'hope this helps...

 keep the rudder amid ship and beware the odd typo

RE: $count+=7 But in @array[0] ??

Perl dynamically allocates space for arrays, so you don't have to worry about declaring the size like you would in C, for instance.  It acts more like a stack or a queue, which is why the push/pop functions are provided like goBoating suggested.  Simply assign a value to the new index and it will automatically create it for you.  This is one of the reasons I love Perl so much!

$array[0] = "new value";
$array[1] = "another value";
$array[2] = "one more";

Tom Anderson
CEO, Order amid Chaos, Inc.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close