
hwnd
User
Jun 11, 2013, 9:45 AM
Post #3 of 4
(22152 views)
|
Re: [Laurent_R] last occurance
[In reply to]
|
Can't Post
|
|
So you just need the numbers from the last occurence of PM? Or the whole PM .. .xml line?
I have to find last PM(/d+)*.xml in a file Seeing how you said find last occurrence in a file, I'm assuming these are lines in a file. So therefore here are a few examples, not clear exactly if you are just wanting the digits from the last occurrence or the whole line.
__DATA__ ggdt 2365 237 PM23jhfy&%_kkf.xml wknw f wef ^& 8* uy y w9 8y ivhodio wroio wroi icvo PM12_uryt&^%_uieg.xml uet. If you want last occurrence of digits, you could do this.
open my $fh, '<', 'file.txt' or die "failed: $!"; my ($str) = map { $_ =~ /.*(?:PM)(\d+)/ } reverse <$fh>; close $fh; print $str; __OUTPUT__ 12 If you want the whole line including .xml you could do this.
open my $fh, '<', 'file.txt' or die "failed: $!"; my ($str) = map { $_ =~ /.*(PM.*\.xml)/; } reverse <$fh>; close $fh; print $str; __OUTPUT__ PM12_uryt&^%_uieg.xml
(This post was edited by hwnd on Jun 11, 2013, 5:14 PM)
|