Hi Monks!
I am trying to do something I don't even know if it will be possible, but maybe someone here have
an alternative or a better solution for it. I have directories with pdf files and the name
of this control txt file has to be the name of one of these files from these directories. I need
to first open these directories, extract the name from the first file found, replace the extension
.pdf to .txt. The problem I have is how to create this control txt file name after going inside of the directories.
Here is the code I hope I made myself clear:
#!/usr/bin/perl -w
use strict;
use File::Basename;
use File::Slurp qw(read_dir);
my $control_file;
my @acc_files;
my ($path, $name);
my @acc_dir = qw( accountdir_a accountdir_b);
for my $acc (@acc_dir) {
push @acc_files, grep { -f } read_dir( $acc, prefix => 1 );
}
open XFILE, ">'$control_file'" or die $!;
foreach my $account(@acc_dir) {
chomp($account);
if($account =~/(.*?)\/([^\/]+)$/) {
$path=$1; $name=$2;
}
# name of the control file here:::
($control_file = $name) =~ s/(\.)([^.]+$)/$1txt/;
# creating log file:::
print XFILE "$name\n";
}
close (XFILE);
Thanks for looking!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.