Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to increment eacl element in a list ?
eg: incrlist {1 2 3}
=>2 3 4

Answers were Sorted based on User's Feedback



how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / yatanti

set incrlist { 1 2 3 }

foreach element $incrlist {
set new_element [ expr $element + 1 ]
lappend new_incrlist $new_element
}
puts $new_incrlist

Is This Answer Correct ?    18 Yes 3 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / gagik sukiasyan

set list {1 2 3}
regsub -all {(\d+)} $list "\[expr \\1 + 1\]" new_list
set result [eval concat "" $new_list]

Is This Answer Correct ?    9 Yes 2 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / rangasa

set listItems {15 2 35}

for {set i 0} {$i < [llength $listItems]} {incr i} {
set newVal [expr [lindex $listItems $i] + 1]
set listItems [lreplace $listItems $i $i $newVal]
}
puts "The newly framed list is $listItems"

Is This Answer Correct ?    4 Yes 0 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / thirumurugan

set list1 {1 2 3}
foreach ele $list {
incr ele
lappend list2 $ele
}
puts $list2

Is This Answer Correct ?    4 Yes 2 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / ritu gupta

set l {1 2 3}
set i 0
foreach e $l {
lset l $i [ expr $e + 1]
incr i
}

Is This Answer Correct ?    2 Yes 1 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / ch.venkatesh

set list {1 2 3}
for {set i 0} {$i < [llength $list]} {incr i} {
set x [lindex $list $i]
set y [expr $x+1]
puts "$y"
}

Is This Answer Correct ?    1 Yes 0 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / mayank

// it works like incrlist 5 6 7 =>> 6 7 8
proc incrlist args {
set s 0
foreach s $args {
incr s 1
puts $s
}
}

//for list
proc incrlist list {
set s 0
foreach s $list {
incr s 1
puts $s
}
}

Is This Answer Correct ?    5 Yes 5 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / jiandoer

set lstr [list 10 20 30]
unset rlstr
foreach item $lstr {
if {[info exists rlstr]} {
lappend rlstr [incr item]
} else {
set rlstr [incr item]
}
}
puts "input list: $lstr"
puts "result list: $rlstr"

Is This Answer Correct ?    0 Yes 0 No

how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4..

Answer / meganathan

set a {10 11 12}
set b 0
foreach c $a {
set c [expr $c+1]
lset a $b $c
incr b
}
puts $a

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Tcl Interview Questions

if i give in numbers output should be in characters example : set a 23 o/p twentythree

1 Answers   Alcatel,


Problems with utf-8 between Mac and PC

1 Answers  


How to get the next ip for given ip ex: 10.10.10.1 -> 10.10.10.2 ex: 10.10.10.255 -> 10.10.11.0

5 Answers   Cisco, HCL,


{Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter "a"in the given list? if yes how?

3 Answers   Cisco, HCL,


how to write a startup script in winrunner

0 Answers   Power Grid, Pyxis,


Hi all, Is there any certification exams available for TCL and Perl. If so please let me know, my mailid is vpbharathi@gmail.com. Thanks in advance, Bharathi.P

1 Answers  


How do you find the length of a string without using string length command in TCL??

6 Answers   Hexaware,


How TCL works

1 Answers   Cisco,


Write a proc to increment the ip by the given no. of times. The incremented IPs should be a valid one. Ex: proc <name> {ip no_of_incrments} { body }

2 Answers  


1.What are the different ways to initialize a variable. How to differentiate global and local variables, explain it through a simple tcl program. 2.Create a list of week days and print the first and last character of each day using foreach command 3.Can you write a small program to verify the given input is file or directory.Before checking, just ensure that the file/dir exists or not in the given path. If the given input is a file, findout the size and verify that the file has all read ,write and execute permission.

3 Answers   ATTO, HCL,


how to remote log in to a system A to system B ,execute commands in it and collect the log in system A from B using TCL script??  

1 Answers   Global Edge, Sandvine,


write a program to the given ip is valid private address or not(192.168.1.1)?

4 Answers   HCL,


Categories