13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

APPENDIX ■ PERL TIPSPerl Syntax NotesHere are a few brief notes about a couple of the corners of Perl syntax that I often find myself havingto refer to the documentation for. Remember, however, the Perl maxim: there’s more than one way todo it!open with |To get command output, you can use open with a pipe, as shown in recipe 4-2:open FILEHANDLE, '-|', 'command';while () {# do stuff!}This will pipe the output from command into FILEHANDLE, which the while() loop then iterates overline by line. If you use '|-' instead, the output from FILEHANDLE is piped to command.?:This syntax, which basically provides an if-then-else shorthand for assignments, can be useful.If the value before ? evaluates as true, then the value after ? is used for assignment; otherwise, the valueafter : is used. So this statement:my $a = $ok ? $b : $c;is a shorthand for this:my $a;if ($ok) {$a = $b;} else {$a = $c;}Use this with caution; it can be a neat way of doing things, but if you find yourself scatteringparentheses everywhere and/or having to look at it more than once to understand it, go back to thelonger version.251Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!