The "qw" quoting operator provides a short-cut for placing quotations marks around each space-delimited token (and putting commas between them as well). So what I've shown above will cause @array to contain 40 elements, with each element being a single letter.@array = qw/P H A G E P H A G E P Q K R E P H A G E P W S Q E P H A G +E P R D L E P H A G E/;
By contrast, your @array = "P H A G E ..."; approach causes @array to contain only one element, which is a string of 79 characters (40 letters separated by 39 spaces).
So if your "previous step of the program" (whatever that may be) is really producing an array of 40 elements with one letter per element, maybe the following would do what you want:
my $start = 0; my $end = 4; while ( $end <= $#array ) { my $string = join( "", @array[$start..$end]; if ( $string eq 'PHAGE' ) { print "$string found in elements $start .. $end\n"; } $start += 5; $end += 5; }
In reply to Re: a clearer query for how do i splice an array
by graff
in thread how to splice an array?
by heidi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |