Q&A

Q1:I'm having problems with the following program. No files are read in, even though they're in the directory!
opendir(DIRHANDLE, "/mydir") || die;
@files=<DIRHANDLE> ;
closedir(DIRHANDLE);
A1: Whoops! The problem is in the second line. DIRHANDLE is a directory handle, not a filehandle. You cannot read directory handles with the angle operators (<>). The correct way to read the directory is @files=readdir DIRHANDLE.
Q2:Why doesn't glob("*.*") match all the files in a directory?
A2: Because "*.*" matches only filenames with a dot in them. To match all the files in a directory, use glob("*"). The glob function's patterns are designed to be portable across many operating systems and thus do not behave the same as the *.* pattern in DOS.
Q3: ...

Get Sams Teach Yourself Perl in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.