Solved

Perl 5's glob() function

Posted on 1997-11-20
2
3,715 Views
Last Modified: 2006-11-17

I have just finished writing a script on my test machine making use of Perl 5's functionality and specifically, the GLOB function.

However, our production machine does not have Perl 5, but Perl 4 and therefore the code dependent upon the output of GLOB will not work.

Basically, the script itself will not work.

Is there an equivalent function to GLOB for Perl 4?  Or perhaps some code I could use to match this:

>
>@WorkingFiles = glob("$WorkingDir/$FileExt");
>
>open(LOG, '>>$LogFile');
>foreach $FileName (@WorkingFiles)

>

I'm working with files and filenames so the output of my script is dependent upon the data GLOB returns. :*(

It is very important that I am able to specify the files returned to me by wildcards (thus the usefulness of GLOB in this situation).

PLEASE ASSIST!!

JaTHaN
<o_/


0
Comment
Question by:jathan
  • 2
2 Comments
 

Accepted Solution

by:
kistler earned 70 total points
ID: 1208815
@files = <$a/*>;
is the same as
@files = <$a/*>;
expect, that in the latter case "." and ".." may
show up as well.
But for perl4 <*> should work. If there is any problem,
you still have the "readdir" function.
0
 

Expert Comment

by:kistler
ID: 1208816
I have tried another way around using the readdir like so:

opendir(WORKDIR, "$WorkingDir");

local(@WorkingFiles) = readdir(WORKDIR);
closedir(WORKDIR);

foreach $FileName (@WorkinDir) { ... }

The only problem with this approach is I have no way of specifying the extensions I want to work with.  Specifically, this script is table-driven and pulls the values for the strings $WorkingDir and $FileExt from said table.  

It is intended to perform a user-specified action (i.e, move, compress, delete) on files of extensions matching $FileExt in the directory $WorkingDir.  Does this help?

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now