in reply to find a specific word
... find position [i.e., index] specific word like "DATA LIST" in an array , but ... it can have spaces before or after ... [emphasis added]
Another approach. Searches for the words separated by one or more of any whitespace character; this could easily be refined to a single space. Be sure you understand List::MoreUtils::indexes and regexes before you turn in your homework.
>perl -wMstrict -le "use List::MoreUtils qw(indexes); ;; my @ra = ( 'DATA', 'LIST', 'DATALIST', 'FOO', ' DATALIST ', 'data list', 'DATA LIST', ' DATA LIST ' ); ;; my $search = qr{ DATA \s+ LIST }xms; ;; my @indices = indexes { $_ =~ $search } @ra; print qq{at index $_ found '$ra[$_]'} for @indices; " at index 6 found 'DATA LIST' at index 7 found ' DATA LIST '
|
|---|