Tech Forums

removing an element from an array

User Rating:  / 0
PoorBest 

How you will remove an element from an array that matches a certain crieteria. that is say I have a 10 names in an array. Some of them may contain a # character say 5th and 7th elemetns. How do I remove only these two elements and after that my array size should be 8. Please sens the sol. ASAP


Regards,
Raghu

 

Hello Raghu,
I am sorry, just now only I checked your mail. Anyway regarding your question, it is very easy in Perl.
Use the grep command in perl. It works like a filter.
I will give you a small example.
@a = (123, adf, 1, 345, r);
@b = grep { /1/ } @a;
$x = join(”\n”, @b);
print “$x\n”;

OUTPUT
123
1

So virtually you can give any condition there.
Similar to this is map command.
Both are very powerful features in PERL,

Try man perlfunc, you will get all the details.

Thanks
Regards
S.Anand

 

In TCL there is a solution by lremove [ lsearch $element $array ] ] $array

in perl also we can do in this as @a = ($a[0..3],$a[5..6])

=============================
Krishna Challa

Site Login