
- Forum
- Programming Talk
- Perl
- Perl Array :S
Perl Array :S
This is a discussion on Perl Array :S within the Perl forums, part of the Programming Talk category; I have an array which muliple values in it and what I wanted to do is add the 5th element ...
-
Perl Array :S
I have an array which muliple values in it and what I wanted to do is add the 5th element of the array to a new array which only stores unique values.
I would normally do this in shell scripting but wanted to learn some Perl so any suggestions would be much appreciated,
Thanks,
-
Please post one example to help you out .
I have an array which muliple values in it and what I wanted to do is add the 5th element of the array to a new array which only stores unique values.
I would normally do this in shell scripting but wanted to learn some Perl so any suggestions would be much appreciated,
Thanks,
-
08-04-2011, 01:04 AM #3
- Join Date
- Aug 2011
- Answers
- 8
Hi,
Your question is not clear to me. If you need to make any change in middle of array, you can use "splice".
Post your shell script here, so that I can give you proper perl solution.
Thanks,
Suresh
-
Hi,
Please check out your answer. I hope your looking for this.
@arr=(2,3,5,2,7,4,9,3,7,8,4,3,1);
@new_arr=();
$i=0;
foreach(@arr)
{
$cValue=$_;
if ($i=4)
{
if (grep(/^$cValue$/, @new_arr) == 0)
{
push(@new_arr,$_);
}
$i=0;
}
}
print @arr;
print "\n";
print @new_arr;
-
Sponsored Ads

Reply With Quote






