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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPENDIX ■ PERL TIPSSWITCH StatementsThere’s no official switch statement in Perl because there are several ways of doing the same thingalready. One neat way is to use the fact that a labeled BLOCK is basically a loop that runs exactly once.So, you can use a snippet that looks like this:SWITCH: {}if (/^A/) { $value = "A"; last SWITCH; }if (/^B/) { $value = "B"; last SWITCH; }if (/^C/) { $value = "C"; last SWITCH; }$value = "";■ Note There’s now a Switch extension to Perl that you can access with use Switch; at the start of your script,but it can be a little slow.252Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!