The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove an element from an array in PERL chriss_58 Shell Programming and Scripting 3 06-06-2008 05:08 AM
Structure element accessing issue... Praveen_218 High Level Programming 4 04-18-2008 11:25 AM
A final question! Compare character with each array element rorey_breaker Shell Programming and Scripting 1 09-28-2007 09:26 AM
array type has incomplete element type jaganadh High Level Programming 1 07-24-2007 03:54 AM
Perl delete an element from array ahtat99 Shell Programming and Scripting 6 01-18-2007 09:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2005
afadaghi afadaghi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 10
Cool accessing my first element of array

Hello everyonel,
I have an array set like so
num=4
read name
arr[$num]=name
I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr[1]} it will show the last element of the array that I populated last. I do not know how to reset the pointer so when I say ${arr[1]} it will show me the very first element.


Appreciate your help.
  #2 (permalink)  
Old 09-29-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
You must have errors in your code. ${arr[1]} will retrieve whatever was stored in arr[1]. However, arr[0] would be the first element.
  #3 (permalink)  
Old 09-29-2005
afadaghi afadaghi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 10
I am storing anything in ${arr[0]}. I'll start with 1 throughout.
  #4 (permalink)  
Old 09-29-2005
afadaghi afadaghi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 10
Perderabo
I just changed my code and am starting from element Zero but when I go back to access them it will list last one first like so: if I have 4 elements from 0 through 3 when I try to access them it will list as 3 1 2 0 even when I say ${arr[0]}
  #5 (permalink)  
Old 09-29-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
You must have a bug in your code. Arrays work fine for me.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0