Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.3.3 Examples of Interpolation (ASCII Octal Values)

With the exception of `\n', you should note that the interpolated sequences are simply shortcuts for actually ASCII characters that can be expressed in other ways. Specifically, you are permitted to use the actual ASCII codes (in octal or hexadecimal) to represent characters. To exemplify this, consider the following program:

#!/usr/bin/perl use strict; use warnings; print "A backslash: \134\n"; print "Tab follows:\11over here\n"; print "Ring! \7\n"; print "Please pay bkuhn\100ebb.org \04420.\n";

This program generates exactly the same output as the program we first discussed in this section. However, instead of using the so-called "shortcuts" for the ASCII values, we wrote each character in question using the octal value of that character. Comparing the two programs should provide some insight into the use of octal values in double-quoted strings.

Basically, you simply write `\XYZ', where XYZ is the octal number of the ASCII character desired. Note that you don't always need to write all three digits. Namely, notice that the double-quoted string, "Ring! \7\n", did not require all the digits. This is because in the string, the octal value is immediately followed by another `\', and thus Perl could figure out what we meant. This is one of the many cases where you see Perl trying to "do the right thing" when you do something that is technically not completely legal.

However, note that, in the last string, the three digits are required for the sequence ("\04420"), because the 20 immediately following the octal code could be easily confused with the octal value preceding it. The point, however, is that as long as you obey the rules for doing so, you can often add characters to your double-quoted strings by simply using the ASCII value.


 
 
  Published under the terms of the GNU General Public License Design by Interspire