Reputation: 185
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 perl...so any help here will be great. I have searched few other places but couldn't find anything for this specific point.
Upvotes: 0
Views: 53
Reputation: 1665
You can print your files using the bellow way.Then you can use them.
Code:
my @dir = `ls ./abc/def/`;
foreach my $id (@dir)
{
chomp($id);
print "$id\n";
}
Hope this will help you.
Upvotes: 0
Reputation: 53498
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).
Upvotes: 3