It comes from shell glob expansion behaviour. That is what the shell does to the command line before it passes it on to the program. So if you have just listed some arguments, it will pass along those arguments. If you have listed some arguments with wildcards, it will expand those wildcards into a file list. And so on.
It even has some features to make it easy to write things like this:
(Fans of Perl golf sometimes find find the treatment of {} very useful.) This is very convenient in an interactive command-line environment. Shell scripters were also used to using this, and Perl just borrowed the same because Larry was trying to leverage existing knowledge.cp some-long-filename{,.bak}
That said, if you don't come to Perl with this background, Perl's glob behaviour is very surprising. And can lead to lots of subtle bugs. Plus when I'm in defensive mode I don't trust programs that will do different (and surprising!) things depending on whether the file I'm looking for is there.
So it's a feature. But surprises and can lead to bugs.
Which is why in "real code" I tend to use opendir and readdir directly (possibly hidden behind a function).
PS If you want behaviour closer to Ruby's, just grep for files:
perl -e 'print grep -f, <x.>'
In reply to Re: Perl's glob behaviour
by tilly
in thread Perl's glob behaviour
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |