Home
71.
What does operator precedence determine? How about associativity?

Operator precedence determines which parts of an expression are evaluated first given expressions that contain other expressions. Associativity determines the order in which operators that have the same precedence are evaluated.

72.
What is the difference between the following patterns?
/d/
/\d/
/\D/
/d\d/

The patterns are as follows:
-> /d/ matches the single character d.
-> /\d/ matches a single digit.
-> \/D/ matches a single nondigit character.
-> /d\d/ matches a d followed by a single digit.

73.
You have the pattern /\d\d\D/. Which of the following strings does this pattern match to?
'456'
'd55'
'55+'
'4aa'
'4b'

The pattern /\d\d\D/ matches two digits and one nondigit, in that order. None of the given strings match the pattern except for '55+'.

74.
What is a file handle? Why do you need one?

A file handle is used to read data from or write data to a source or a destination, be it a file, the keyboard, the screen, or some other device. File handles provide a common way for Perl to handle input and output with all those things.

75.
What does the chomp function do?

The chomp function removes the newline from the end of a string. If there is no newline on the end of the string, chomp does nothing.

76.
What's the difference between a hard link and a symbolic link? What happens if you remove the file that you've linked to with either one?

Hard links provide a way for a single file to have multiple filenames. Removing one instance of the filename—be it the original or the link—leaves all other hard links intact. The file is only actually removed when all the links to it are also removed. Symbolic links also provide a way for a single file to have multiple names, except that the original file is separate from the links. Removing the links has no effect on the file; removing the original file makes any existing links point to nothing.
Note that only Unix systems differentiate between hard and symbolic links, and some Unix systems don't even have symbolic links. Aliases on the Mac or shortcuts on Windows are analogous to symbolic links.

77.
What's the difference between 'pwd' and cwd()? Why would you want to use one over the other?

The 'pwd' command makes use of back quotes and the pwd command in Unix. While some versions of Perl work around this function on other systems, for a more portable version use the Cwd module and the cwd() function. Note: you’ll have to import Cwd (use Cwd) before you can use it.

78.
What is a file glob? Why are they useful?

A file glob is a way of getting a list of files that match a certain pattern. *.pl, for example, is a glob that returns all the files in a directory with a .pl extension. Globs are useful for grabbing and reading a set of files without having to open the file handle, read the list, and process only those files that match a pattern.

79.
What’s the difference between a file glob of <*> and the list of files you get with readdir()?

A file glob of <*> returns all the files in a directory, but it does not include hidden files, files that start with a ., or the . and .. directories. Directory handles return all these things.

80.
What are the differences between file handles and directory handles?

File handles are used to read and write the contents of files (or to the screen, or to a network connection, and so on). Directory handles are used to read lists of files from directories. Both file handles and directory handles use their own variables, and the names do not clash.