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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace an element from a list

Status
Not open for further replies.

mune77

Programmer
Oct 15, 2009
6
GB
I got a list,
frq 1 1 1 1 1 2 2 3 ...,
I need to to change the 3rd ELEMENT which is 1, to 5.
I know the "lreplace" command wouldn't work for this as it doen't take the index of the list.

Is there a command to do this job?
if not, the possibility might be deleting the 3rd element and appending the new value.
Is there a command to delete a value from a list if the index is given?

Thanks in advance!
 
Hi

mune77 said:
I know the "lreplace" command wouldn't work for this as it doen't take the index of the list.
Are you sure ?
Code:
[b]set[/b] frq [teal][[/teal][b]list[/b] a b c d e f[teal]][/teal]

[b]puts[/b] [navy]$frq[/navy]

[b]set[/b] frq [teal][[/teal][b]lreplace[/b] [navy]$frq[/navy] [purple]2[/purple] [purple]2[/purple] x[teal]][/teal]

[b]puts[/b] [navy]$frq[/navy]

[b]lset[/b] frq [purple]2[/purple] y

[b]puts[/b] [navy]$frq[/navy]
Code:
a b c d e f
a b x d e f
a b y d e f
I would say [tt]lreplace[/tt] does it. But [tt]lset[/tt] looks like a more appropriate solution.

Feherke.
 
damn!!
you are a genius!
thanks feherke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top