How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Anirban Adhikary
Hi List I need to find the index positions of many elements. For a single occurrence there are many ways to find it. But in my case the element which I am searching for has multiple occurrence. The following is the array from where I have to find the indexes of a specific element say bspwrt.

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Kent Fredric
On 17 June 2015 at 04:46, Vincent Lequertier s...@riseup.net wrote: #!/usr/bin/perl use strict; use warnings; open my $fh, '', 'text'; my @words = split ' ', $fh; my @matchs; while (my ($index, $elem) = each @words) { if ($elem eq 'bspwrt') { push @matchs, $index++;

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Vincent Lequertier
Hi Anirban, Assuming you have a file named text.txt containing your data, this code should do the trick : #!/usr/bin/perl use strict; use warnings; open my $fh, '', 'text'; my @words = split ' ', $fh; my @matchs; while (my ($index, $elem) = each @words) { if ($elem eq 'bspwrt') {

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Paul Johnson
On Wed, Jun 17, 2015 at 07:01:06AM +1200, Kent Fredric wrote: On 17 June 2015 at 04:46, Vincent Lequertier s...@riseup.net wrote: #!/usr/bin/perl use strict; use warnings; open my $fh, '', 'text'; my @words = split ' ', $fh; my @matchs; while (my ($index, $elem) = each @words) {