- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Microsoft
- >
- Perl doesn't glob filename wildcards?
Operating System - Microsoft
1820884
Members
3643
Online
109628
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2010 11:44 AM
тАО04-29-2010 11:44 AM
Hello, Perl gurus!
I'm running ActivePerl's Perl 5.10.1 on a Windows (Vista) platform. I'm trying to write a simple script to read and process multiple text files. I can pass a enumerated list of file names, but wildcards don't work.
Here's my program reduced to the essentials (read specified files, print last line):
----- myprog.pl -----
while (<>) {
$line = $_ if ($_ ne '');
}
print $line;
-----
> perl myprog.pl test1.txt test2.txt test3.txt
prints the last line of test3.txt.
> perl myprog.pl test*.txt
fails: Can't open test*.txt: Invalid argument at myprog.pl line 1.
Question: Isn't filename globbing tied to the diamond input operator?
Question: Is there a way to have the diamond operator handle the filename glob?
Note: While I am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company
I'm running ActivePerl's Perl 5.10.1 on a Windows (Vista) platform. I'm trying to write a simple script to read and process multiple text files. I can pass a enumerated list of file names, but wildcards don't work.
Here's my program reduced to the essentials (read specified files, print last line):
----- myprog.pl -----
while (<>) {
$line = $_ if ($_ ne '');
}
print $line;
-----
> perl myprog.pl test1.txt test2.txt test3.txt
prints the last line of test3.txt.
> perl myprog.pl test*.txt
fails: Can't open test*.txt: Invalid argument at myprog.pl line 1.
Question: Isn't filename globbing tied to the diamond input operator?
Question: Is there a way to have the diamond operator handle the filename glob?
Note: While I am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company
Solved! Go to Solution.
- Tags:
- Perl
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-30-2010 01:37 AM
тАО04-30-2010 01:37 AM
Solution
It's a Windows thing, I'm afraid. Perl comes from a UNIX background, where filename globbing is done by the shell before passing the resulting list of filenames to the program. Windows doesn't do filename globbing in the shell - each program is expected to handle the arguments as given, and do any wildcard handling itself.
Take a look at the Perl "glob" function for how to do this.
Take a look at the Perl "glob" function for how to do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-30-2010 07:28 AM
тАО04-30-2010 07:28 AM
Re: Perl doesn't glob filename wildcards?
Thanks, Andrew.
After some study of the "glob" function, for the simple case of just filenames and name-globs passed as arguments, the use of 'glob' reduces to the following:
----- myprog.pl -----
@ARGV = <@ARGV>;
# then the rest of the program:
while (<>) {
$line = $_ if ($_ ne '');
}
print $line;
-----
Note: While I am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company
After some study of the "glob" function, for the simple case of just filenames and name-globs passed as arguments, the use of 'glob' reduces to the following:
----- myprog.pl -----
@ARGV = <@ARGV>;
# then the rest of the program:
while (<>) {
$line = $_ if ($_ ne '');
}
print $line;
-----
Note: While I am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP