Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

SLS
action=decrypt
input_file=/home/qsi/tmp/SLSInterestExtract.*.*.*.pgp
output_file=/home/qsi/tmp/SLSInterestExtract.*.*.csv

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:
SLSInterestExtract.080308.0459.csv

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 perldoc.org!


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-10-19 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (255 votes). Check out past polls.

    Notices?