jdamae
jdamae

Reputation: 3909

help with regex in perl

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.

Upvotes: 2

Views: 93

Answers (1)

TLP
TLP

Reputation: 67900

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/;

Upvotes: 6

Related Questions