Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

using finddepth with part of directory name

by jsons (Initiate)
on Oct 19, 2007 at 19:32 UTC ( [id://646056]=perlquestion: print w/replies, xml ) Need Help??

jsons has asked for the wisdom of the Perl Monks concerning the following question:

I need to update a perl program that prints a hyperlink to an autocad drawing. The link will be based on a truck number that the user enters into an html page. That page then posts their entries to this perl script.

This page (cadsearch.cgi) uses another perl page (find_dir_all.pl) that returns a directory to search based on the truck number.

The issue that I am having is that I know only the first part of the directory to search due to inconsistent file naming habits. The first part of the directory will be returned to this program.

I need to be able to search for a directory that matches the first part of the directory name.

Example:
Joe User searches for truck number 12345.

I know that the directory will be something like:

BID.12345 Wanna B. Company
or
Quote.12345 Gonna Geta Truck

I know everything up to the end of the number and it will be a unique directory, but I will not know what the customer name added to the end will be.

How can I perform a search on a directory by using only the first part of the directory name? Below is the code that I must update, trimmed down for this posting:
#!/usr/bin/perl ##!/opt/gnu/bin/perl #/usr/local/bin/apache/cgi-bin/cadsearch.cgi #push(@INC,"/cgi-bin"); require "cgi-lib.pl"; use File::Find; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Socket; &ReadParse(*input); $truck=$input{"truckno"}; #ex: 12345 $searchtype=$input{"searchtype"}; #ex: bid $dir=`/filesystem/scripts/find_dir_all.pl $truck $searchtype`; @dir=("$dir/$truck"); $file=$input{"filename"}; #set variable for new dwg convert web app $dwgpdf="http://webserver/dwgbpdf/"; #variable for hyperlink $hlink # finddepth function to locate directory for ($i=0;$i<=$#dir;$i++){ finddepth(\&dwgWanted,$dir[$i]); } # wanted sub to locate files sub dwgWanted{ $hlink="$File::Find::name" if (/^$file.*$ext2.*/ ); print $hlink }

Replies are listed 'Best First'.
Re: using finddepth with part of directory name
by andyford (Curate) on Oct 19, 2007 at 20:14 UTC

    Have you looked at File::Glob? It allows you to select files based on shell wildcards. I think it would be your simplest solution.

    non-Perl: Andy Ford

      I will look into using File::Glob, thank you. I am very new to Perl, and I really appreciate the guidance.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found