Your code is doing the following:
- Find all the elements of @lines that begin with AUID (plus some optional whitespace) and store them in @headings,
- take the first found element and do a split on ' ' (which has a special meaning as explained in its docs) and overwrite the contents of @headings with the result, and
- shift the first element off @headings and discard it.
There are two problems with the oneliner you showed:
- grep in scalar context (as it is in the code you showed) will return the number of matches, not one of the matches, and
- shift removes the first element from an array and returns the element it removed, not the list minus the first element.
<update2> Eily's suggestion is nicest IMO:
my (undef, @headings) = split ' ', first {/^\s*AUID/} @lines;
</update2>
You can pack it in a single line, here is one way, but it's kind of ugly. This uses (...)[0] to return the first return value of grep and splice to return the list without its first element:
my @headings = splice @{[
split ' ', (grep /^\s*AUID/, @lines)[0] ]}, 1;
Although I might recommend using first from List::Util to avoid the wasteful grepping of the entire array:
my @headings = splice @{[ split ' ', first {/^\s*AUID/} @lines ]}, 1;
I still don't think this is very pretty because of the @{[]} trick I have to use to get splice to be happy. This one, using map and a regex, I like better:
my @headings = map {/(?!^\s*AUID)\s(\S+)/g} first {/^\s*AUID/} @lines;
Update: map isn't really needed:
my @headings = (first {/^\s*AUID/} @lines)=~/(?!^\s*AUID)\s(\S+)/g;
|