Flanking Knight
Flanking Knight

Reputation: 19

perl: How to trim a certail part of a string?

I have this value stored in a string

"-rw-rw-r--  1 xyz test   3.7K Mar 25 14:59 abcd.txt".

And i just want to trim the "abcd.txt" part from the string into another.

NB - rest of the part is not constant.

Upvotes: 0

Views: 59

Answers (2)

mpapec
mpapec

Reputation: 50647

my ($trimmed) = $string =~ /(\S+)$/;

although you might be better with using ie. glob("*txt") rather than fiddling with external ls.

perldoc -f glob

Upvotes: 2

Pradeep
Pradeep

Reputation: 3153

($filename) = $string =~ /\d\s(.+?)$/

Upvotes: 0

Related Questions