Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Regex Question

by LouM (Initiate)
on Mar 10, 2008 at 15:54 UTC ( #673260=perlquestion: print w/replies, xml ) Need Help??
LouM has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am new to Perl and am in need of help with the following problem:

I have a config file that looks like this:

# Feed Name
# action=ecrypt OR decrypt
# input_file # input file to be encrypted or decrypted
# output_file # output file to be encrypted or decrypted


I already have the code to read the cfg file but I am not sure how to parse the file names, read the directories and generate the output file name.
For example:

/home/qsi/tmp/SLSInterestExtract.*.*.*.pgp is actually
SLSInterestExtract.080308.0459.txt.pgp in the directory.

I need to generate:

Thanks for your help!!!

Replies are listed 'Best First'.
Re: Regex Question
by moritz (Cardinal) on Mar 10, 2008 at 16:01 UTC
      Thanks moritz. I have the Config::INI::Simple part covered but woiuld appreciate more help on the glob piece.

      I looked at some examples but still not sure how to code it.
        It's not that hard:
        my @matched_files = glob $pattern;

        glob expands shell "patterns" like a star * to all files, '..' to the parent directory, ~ to the home directory and so on.

Re: Regex Question
by nefigah (Monk) on Mar 10, 2008 at 16:10 UTC
    I would look at File::Basename!

    I'm a peripheral visionary... I can see into the future, but just way off to the side.
      Thanks nefigah. That worked. Now, how do I read the directory for that file pattern within the script?

      Is there a link that explains all of the File:: functions?
        Well, I'm pretty new too, so not sure if this is the best way, but I would use the glob function as was recommended earlier, something like this:
        use File::Basename; my $dir = dirname($path); $dir .= '/*'; # Note: if the result of dirname already has the slash, +you only need to add the * while (glob $dir) { # this will loop through files in that directory, putting each filen +ame in $_ }
        You can check out perldoc -f glob at the command line or!

        I'm a peripheral visionary... I can see into the future, but just way off to the side.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://673260]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2018-07-19 06:17 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (403 votes). Check out past polls.