Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 2. Idiomatic Perl > Item 17. Know common shorthand and syntax quirks - Pg. 60

60 Chapter 2 Idiomatic Perl Item 17. Know common shorthand and syntax quirks. Perl is a "human" language in that it has a context-dependent syntax. You can take advantage of this by omitting things that the interpreter can assume--default arguments, $_ , optional punctuation, and so on. Perl fig- ures out from the context what you really mean (usually). Perl is also a very high level language with an extremely rich and diverse syntax, but sometimes the various syntactical features don't fit together as well as they might. In some cases, you may have to help Perl along by resorting to a syntactical gimmick of one kind or another. Along these lines, here are some suggestions, and some things to watch out for. Swap values with list assignments Perl doesn't have a special operator to swap values in two variables, but you can always use a list assignment to the same effect. Perl evaluates the righthand side before it does the assignment: ( $b, $a ) = ( $a, $b ); # swap $a and $b