On Tue, Apr 24, 2001 at 09:52:04AM -0700, Sandor W. Sklar wrote:
: Hi, folks ...
: 
: I'm generating a list of files (from a find subroutine) and putting 
: them in an array.  The list looks like ...
: 
: /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
: /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
: /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
: /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
: /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
: 
: (... a small sample)
: 
: and I'm trying to get just the "File-nnnn" part of each line; some 
: lines that I am matching against will have a trailing slash, with 
: additional path info that I'm not interested in; other lines will 
: have a period and a number following, which I am also not interested 
: in.
: 
: Perhaps the File::Basename module would do what I want, but I can't 
: get my mind around its documentation.  I thought of using split on 
: each line (splitting on the "/", and then looking each element of the 
: array returned), but that seems, well, stupid.  I'm sure that there 
: is some really simple magic here; I just don't see it.  Can someone 
: enlighten me please?

Well, if you're just interested in a fast, easy way of doing this,
where you always know that there will be 'File-' and then some
numbers, try:

#!/usr/local/bin/perl -w
use strict;
$|++;

while ( <DATA> ) {
  my( $part ) = /(File-\d+)/; # In list context ( forced by using
                              # parens with my() ), a match will
                              # return a list of matches.  In this
                              # case, one match.
  print "I like this $part\n";
}

__END__
/home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
/home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
/home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm


-- 
Casey West

Reply via email to