Operating System - HP-UX
1827376 Members
4107 Online
109963 Solutions
New Discussion

perl script to locate files

 
SOLVED
Go to solution
kholikt
Super Advisor

perl script to locate files

I am writing some perl script to create omniback report in excel format.

I have put my delimited file inside one of the directory. I will loop through all the file with *csv extension. For each new file I will create a new worksheet inside the workbook excel file.

currently I am having problem as the $files always said no such file ...
abc
6 REPLIES 6
kholikt
Super Advisor

Re: perl script to locate files

I think I have found out the problem. The write excel module cannot create worksheet with the / character.

Is there anyway in perl that I can filter the name
/omrpt/abc/12-03-bac_hpsgqa_QAS.csv

to become bac_hpsgqa_qas
abc
Mark Grant
Honored Contributor

Re: perl script to locate files

I think your problem might be a missing "s"

foreach my $file (@files) {
open (TABFILE, $files) or die "$files: $!";

$file should be $files
Never preceed any demonstration with anything more predictive than "watch this"
kholikt
Super Advisor

Re: perl script to locate files

ya u are right I have fixed that already.
abc
Mark Grant
Honored Contributor
Solution

Re: perl script to locate files

Your other problem might be solved with this

#!/usr/bin/perl

$DATA="/omrpt/abc/12-03-bac_hpsgqa_QAS.csv";

($RESULT)=($DATA=~m#.*/(.+)\.csv#);
print "result $RESULT\n";
Never preceed any demonstration with anything more predictive than "watch this"
kholikt
Super Advisor

Re: perl script to locate files

Hi,

The code that you suggest work very well. Thank for your help.

Just wondering is it possible to remove the number as well

12-03- can it be removed as well.
abc
Mark Grant
Honored Contributor

Re: perl script to locate files

assuming that the number part always ends in a number and then a "-" as in 12-03- then

#!/usr/bin/perl

$DATA="/omrpt/abc/12-03-bac_hpsgqa_QAS.csv";

($RESULT)=($DATA=~m#.*\d-(.+)\.csv#);
print "result $RESULT\n";
Never preceed any demonstration with anything more predictive than "watch this"