resetting an array

Thread Solved

Join Date: Jan 2007
Posts: 1,762
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Solved Threads: 85
Moderator
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

resetting an array

 
0
  #1
Dec 9th, 2008
Hi,

I am looping through some files, gathering information into an array during that loop. The array grows with the loop counter and at every point might be longer or shorter (more or less members in it)

so in order to reuse the array I need to drop all values in it, and I can't seem to find an easy way to do so (to loop through the array using its length and putting NULL into every position is a bit too much)

Example:
Shell Scripting Syntax (Toggle Plain Text)
  1. i=1
  2. for tree in `ls -A /tmp/imagetrees/*.tree`
  3. do
  4. for line in `cat $tree`
  5. do
  6. array[$i]=$line
  7. let i=$i+1
  8.  
  9. done
  10. echo ${array[*]} >
  11. i=1
  12. # need to reset array to NULL here, before reusing in the next loop
  13. done

.tree file looks like this:
# cat /tmp/imagetrees/base33111.tree
base33111
base3311
base331
base33
base3
# cat /tmp/imagetrees/base33.tree
base33
base3
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: resetting an array

 
0
  #2
Dec 9th, 2008
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1,762
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Solved Threads: 85
Moderator
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

Re: resetting an array

 
0
  #3
Dec 9th, 2008
thanks, found the unset function. can't believe I forgot about it
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC