CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [Laurent_R] last occurance: Edit Log



hwnd
User

Jun 11, 2013, 9:45 AM


Views: 11413
Re: [Laurent_R] last occurance

So you just need the numbers from the last occurence of PM? Or the whole PM .. .xml line?


Quote
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.


Code
__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.


Code
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.


Code
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)


Edit Log:
Post edited by hwnd (User) on Jun 11, 2013, 9:51 AM
Post edited by hwnd (User) on Jun 11, 2013, 4:24 PM
Post edited by hwnd (User) on Jun 11, 2013, 5:14 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives