Perl Style: Switch with for via && and ||

  • Be careful that the RHS of && is always true.

       $dir = 'http://www.wins.uva.nl/~mes/jargon';
       for ($ENV{HTTP_USER_AGENT}) {
           $page  =    /Mac/            && 'm/Macintrash.html'
                    || /Win(dows )?NT/  && 'e/evilandrude.html'
                    || /Win|MSIE|WebTV/ && 'm/MicroslothWindows.html'
                    || /Linux/          && 'l/Linux.html'
                    || /HP-UX/          && 'h/HP-SUX.html'
                    || /SunOS/          && 's/ScumOS.html'
                    ||                     'a/AppendixB.html';
       }
    

Forward to Switch Using for and do{} Even More Creatively
Back to Switch by Using do{} Creatively
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.

Tags

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub