Dear PerlMonks,

How can I perform a search on a directory by using only the first part of the directory name?

I am trying to learn this language with a course through a 'toss him into the fire and let him swim' mentality.
I have some experience in VB programming, and have been tasked with updating an existing perl program. I am having a hard time getting around the learning curve.

In my first posting for help it was suggested that I try using globbing to use wildcards. I tried to implement the following:

use File::Glob qw(:globally :nocase); for ($input{"searchtype"} { if (/bid/ | /quot/ | /ezd/) { @dir = bsd_glob("$dir*"); } else { @dir = $dir }


without success... I get the following errors in the error log:

(2)No such file or directory: exec of /var/apache/cgi-bin/cadsearch.cgi failed

client xx.xx.xxx.xx Premature end of script headers: /var/apache/cgi-bin/cadsearch.cgi

More details and code follow.

Any guidance with examples are greatly appreciated.

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. Below is the code that I must update, trimmed down for this posting:
Here is the code that I need to update:
#!/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 }
This is the change that I made:
#Set the default values to be changed by proe/excel/etc $ext=dwg; $ext2=DWG; $truck=$input{"truckno"}; $searchtype=$input{"searchtype"}; $dir=`/depot/systems/scripts/find_dir_all.pl $truck $searchtype`; # use globbing to locate directory based on searchtype and truck numbe +r for ($input{"searchtype"} { if (/bid/ | /quot/ | /ezd/) { @dir = bsd_glob("$dir*"); } else { @dir = $dir } }
This is the perl script called to get the root directory (find_dir_all.pl):
#!/opt/gnu/bin/perl ##!/usr/bin/perl package FindDrw; use Cwd; #This program finds the correct subdirectory for a truck number $truck=$ARGV[0]; $searchtype=$ARGV[1]; #search for sales orders if ($searchtype='so'){ if ($truck >= 900000 ) { $dir = '/directory_tree/so/900000'; } elseif (300000 <= $truck & $truck < 400000) { $dir = '/directory_tree/so/300000/$truck'; } elseif ... } #search for bids elseif ($searchtype='bid'){ if ($truck < 01000){ $dir = '/directory_tree/bids/bid.00900/bid.$truck'; } elseif (01000 <= $truck & $truck < 02000) { $dir = '/directory_tree/bids/bid.01000/bid.$truck'; } elseif ... } #search for quotes elseif ($searchtype='qot'){ if (3000 <= $truck & $truck < 4000) { $dir = '/directory_tree/quotes/quote.3000/Quote.$truck'; } elseif (4000 <= $truck & $truck < 5000) { $dir = '/directory_tree/quotes/quote.4000/Quote.$truck'; } elseif ... } print "$dir";

In reply to Searching for directory with partial name by jsons

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.