Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: finding specific files

by turnstep (Parson)
on Feb 26, 2001 at 21:01 UTC ( [id://60893]=note: print w/replies, xml ) Need Help??


in reply to finding specific files

You can also use a regular expression. You were almost there with the code you had. Here's a slight rewrite:
my $mydir = 'Where/the/directory/is'; opendir (MYDIR, $mydir) or die "Could not opendir $mydir: $!\n"; my @numfiles = grep { /^\d{4}.*\.html$/} readdir MYDIR; closedir(MYDIR); print "<UL>\n"; for (@numfiles) { print qq! <LI><A HREF="$_">$_</A></LI>\n!; } print "</UL>\n";

Quick notes:

  • Always check the return of your opens and opendirs. There is no point in the script continuing if they fail.
  • The regular expression in this case matches exactly 4 digits "\d{4}" at the very start of the string "^" followed by anything ".*" and ending in 'dot-html' at the very end of the string "\.html$"
  • If your HTML has double quotes, you can make them without any problems by using an alternative quoting character ("!" in this case) with the qq operator. See the section entitled "Quote and Quote-like Operators" in perldoc perlop.
  • Using <LI> is a quick and easy way to create a nice formatted list - like this one! :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found