1753523 Members
11453 Online
108795 Solutions
New Discussion

Re: perl script

 
SOLVED
Go to solution
kholikt
Super Advisor

perl script

I am modified someone perl script. This script is using the writeexcel module to produce a excel file.

I have the following line which is actually create a new worksheet and named it using the file name in the directory.
($sheetname)=($file=~m#.*\d-(.+)\.csv#);

List of file in the directory
12-05-ABC_XXX_Filesystem.csv 12-05-MSESE-ABC_xxxsg-x_ExchIS.csv
12-05-ABC_Ksex_FS_Sun_BD.csv 12-05-MSESE-ABC_xxxx_Exch_Fri_AC.csv 12-05-MSSQL-ABC_xxxsgsap_PRD2_Diff.csv
12-05-ABC_xxx_FS_Wed_BD.csv

However, excel worksheet name has some limitation on the length of the name it can use.

I would like to cut down "12-05-", "MSSQL-", "MSESE-" from the file name so that the name can be shorter to use for the excel spreadsheet.
abc
1 REPLY 1
Hein van den Heuvel
Honored Contributor
Solution

Re: perl script

The 12-05 is just an example of a date no?
Will the month field be zero-filled, blank filled, or short in January?

Before that assignment line you can use:

$file =~ s/\s?\d+-\d\d(-MSSQL-|-MSESE-|-)//;

This replaces a matching string in $file with nothing.

The match requires
\s? = 0 or 1 space (January)
\d+ = 1 or more digits
- = a dash
\d\d = two digits
(a|b|c) = a, b, or c where a=-MSSQL, b=-MSESE, c= a dash.

Enjoy,
Hein.