![]() Under most circumstances, when a \ is in a single-quoted string, it is simply a backslash, representing itself, as most other characters do. When we see a \ character in a single-quoted string, we must carefully consider what will happen. Since we have used the \ character to do something special with the ' character, we must now worry about the special cases for the backslash character itself. ![]() (C programmers are already probably used to this idea.) However, just keep in mind the rules and you will probably get used to them quickly. It can be difficult at first to become accustomed to the idea that two characters in the input to Perl actually produce only one character in the string itself. We have in this example a string with seven characters exactly. 'xxx\'xxx' # xxx, a single-quote character, and then xxx To see what is meant by this, try this simple program: If single quote marks were used, the actual variable name would have been printed because nearly all special characters that might be interpreted differently are taken at face value when using single quotes. When the results were printed, the value of the variable was placed in the printed line, not the name of the variable. In the previous examples, you may have noticed that variable names were included inside the strings with double quotes. Single quotes can be thought of as literal strings. Using double or single quote marks in Perl each has a special meaning. We have already used one type in the simple programming examples, using double quote marks. String literals can be represented in primarily three ways in Perl. Later, we will learn how to assign these string literals to variables in the Scalar Variables section. However, for now, we will simply consider the different types of string literals that one can make in Perl. We will find this useful when we want to store string literals in variables. This can be contrasted with storing a string in a variable.Īny string literal can be used as an expression. To the fact that these are used when you want to type a string directly to Perl. ![]() To begin our discussion of strings in Perl, we will consider how to work with string literals in Perl. For now, we will begin our consideration of strings by considering how to insert literal strings into a Perl program. We will discuss special characters more later on. In addition, a string can contain special whitespace formatting characters like newline, tab, and the bell character. Strings can be of any length and can contain any characters, numbers, punctuation, special characters (like ! #, and %), and even characters in natural languages besides English. In fact, you could consider the text of this entire book as one string. 4.1 Interpolation in double-quoted stringsĪny sequence of characters put together as one unit, is a string.3 Brief digression from strings alone: The print function.2.3 Examples of invalid single-quoted strings.2.1 Special characters in single-quoted strings.Its original documentation was written by Chip Salzenberg. #AUTHORįile::Compare was written by Nick Ing-Simmons. Is basically equivalent to compare_text($file1, $file2, sub ) #RETURNįile::Compare::compare and its sibling functions return 0 if the files are equal, 1 if the files are unequal, or -1 if an error was encountered. For example: compare_text($file1, $file2) compare_text() accepts an optional third argument: This must be a CODE reference to a line comparison function, which returns 0 when both lines are considered equal. It stops as soon as a difference is detected. It is exported from File::Compare only by request.įile::Compare::compare_text does a line by line comparison of the two files. It is exported from File::Compare by default.įile::Compare::cmp is a synonym for File::Compare::compare. The File::Compare::compare function compares the contents of two sources, each of which can be a file or a file handle. File::Compare - Compare files or filehandles #SYNOPSIS use File::Compare
0 Comments
Leave a Reply. |