2

Can someone help me get the correct regex for this string?

Total                       14,928  3,967

I am trying to remove that line using this, but no luck:

shift @lines if $lines[0] =~ /^Total/;

Its also the last line of the output file.

1 Answer 1

6

What you might consider instead is:

@lines = grep !/^Total/, @lines;

If it is always the last line:

splice @lines, -1, 1 if $lines[-1] =~ /^Total/;

-1 is the last element in the array.

Or, more simply, as ikegami pointed out:

pop @lines if $lines[-1] =~ /^Total/;
Sign up to request clarification or add additional context in comments.

3 Comments

perfect. thank you! i also was curious how to get the last element and you got that answered too. thanks again.
splice @lines, -1, 1 is long for splice @lines, -1 and for pop @lines
Timtowtdi: $#lines -- if $lines[-1] =~ /^Total/;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.