Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: grep question

by monarch (Priest)
on Nov 17, 2005 at 05:31 UTC ( #509294=note: print w/replies, xml ) Need Help??


in reply to grep question

If you had an array of file names, and did the following:
my @grepped = grep /\d{8}\.txt$/ @filenames;
..then your array @grepped would contain the entry 'file1_system_051117123050.txt' if this filename was in the @filenames array.

However, if you want to capture text from a string, then you want a regular expression match:

if ( $filename =~ m/(\d{4})\d{4}.txt$/ ) { print( $1 . "\n" ); }
..if $filename contained 'file1_system_051117123050.txt' then you would have '1712' printed out as that was the four digits captured within parenthesis (curly brackets) in the regular expression match.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://509294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2023-01-30 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?