Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi
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
 
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
$array[1]+=7;
# now, the second element is 10.


'hope this helps...




keep the rudder amid ship and beware the odd typo
 
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!

eg:
@array;
$array[0] = "new value";
$array[1] = "another value";
$array[2] = "one more";
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top