Krishna P Krishna P - 3 months ago 4x
Perl Question

Perl : Picking a varying filename with a specific extension from a specific folder

Problem: I have a specific folder in which i have only one file with a specific extension. This file is generated one and the name always varies...

I want to assign it to a variable and then pass to subroutine in perl
i tried as follows

my $file = "./abc/def/*.xml";
and also tried using one field on which i have control

my $file = "./abc/def/._${username}_..xml";

but i print the file name.... it says *.xml or ._name_..xml instead of the actual filename ...

Can someone tell me how to solve my problem.
I am new to any help here will be great.
I have searched few other places but couldn't find anything for this specific point.


You want glob:

my $file = glob './abc/def/*.xml';

Or perhaps:

my @files = glob './abc/def/*.xml';

Not sure why you're having problems with the $username part though. It should expand that var. (although, I don't know why you have _ either side).