Perl code question!

I am trying to create a file of file names in a directory. Here is my script:


# $1: /devetl/ptqs/DFS2_Assr_03_02/

cd "$1"

/bin/ls FinalFile*.txt* > Out.fil
perl -i -ne 's/FinalFile/,FinalFile/g; print;' Out.fil
cat Out.fil | perl -e '@f=<STDIN>; $f[$#f] =~ s/(.*),(.*)/$1$2/; print @f;' > Out2.txt

#Remove the extra ^@ characters that appreas in the file
rm -f Out.fil
tr -d '\n' <Out2.txt > Out.fil
rm -f Out2.txt
cat Out.fil

The input parameter, $1, is the directory path.

The files in my directory are:

I would like them in this format:

The output I get from the script above is:

Note that the last comma separator is missing.

One major flaw in the script above is that, it uses $2 as the second
parameter eventhough only one parameter is passed in. This errors out if I
remove the $2 from the $1$2 which is strange!

Any help would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

perl -le 'print join",",<FinalFile*.txt*>' >Out.fil
soccerplayerAuthor Commented:
ozo, where does this line go in the script?
soccerplayerAuthor Commented:
Also, can you explain the line so that I can learn? Thanks.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

soccerplayerAuthor Commented:
ozo, two questions.
1)How come we are not using the passed in parameter, $1, which is the directory path, anywhere?
2)Can I replace "FinalFile" by a second parameter? That is, wherever "FinalFile"
appears, can I replace it with "$2"?

# $1: /devetl/ptqs/DFS2_Assr_03_02/

cd "$1"
perl -e "print join',',<$2*.txt*>"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
is a lis of filenames
perldoc -f glob
join ','
puts ',' between elements of a list
perldoc -f join
perldoc -f print
soccerplayerAuthor Commented:
Thank you very much for the solution. Worked like a charm!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

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.