Perl Question

I was given the attached Perl code to do the following:

1. I have a folder with file names that are codes like 006500000aBcDe.
2. I have a file called Attachments.csv that has a column of codes that will match the file names and a column of meaningful file names such as "proposal for XYZ Corp.doc".

The Perl program is supposed to match the codes and rename the files to have the meaningful file names instead of the codes.  It seemed to work as all the file names got changed and the amount of files in the folder did not change.

However, as I am now doing something else with the renamed files I am finding that some of them somehow did not get renamed properly.  That is, for example, the file was supposed to be changed from the code to "proposal for XYZ Corp, Inc." but it didn't.  It got changed to SOMETHING because the file with the original code name is not there and I didn't lose any files.

So far, it seems like it only happened for files that had a comma in the file name.  I need someone to look at this Perl program and tell me if it would malfunction if the file name had a comma.

Who is Participating?
ozoConnect With a Mentor Commented:
simplest fix is to change
  ($id,$name) = split ',', $line;
  ($id,$name) = split ',', $line,2;
that program would change the name of
1145--Dyno LLC - SafeData
moore315Author Commented:
That works - as long as the file name doesn't have more than one comma.  Fortunately for me, none of the file names have more than one comma so I'm good.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.