Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Using IF and OR, I'm sure there is a better way

by Fletch (Bishop)
on Dec 15, 2005 at 01:23 UTC ( [id://516825] : note . print w/replies, xml ) Need Help??


in reply to Using IF and OR, I'm sure there is a better way

You might also consider populating a hash and using exists to check for a match.

use YAML (); $items = YAML::Load( <<EOT ); a: 1 b: 1 c: 1 EOT if( exists $items->{ $variable } ) { # . . . }

Replies are listed 'Best First'.
Re^2: Using IF and OR, I'm sure there is a better way
by mrborisguy (Hermit) on Dec 15, 2005 at 02:41 UTC

    Is that really how you populate your hashes?

    $items = { a => 1, b => 2, c => 3, }; if ( exists $items->{ $variable } ) { # . . . }

        -Bryan

      Depends. If the list were relatively static I probably would keep it inline in the source like you've shown. If it were more dynamic or dependent on something outside the script I'd leave it external with a quick change from YAML::Load to YAML::LoadFile (granted I'd probably use a YAML sequence rather than a hash, but the idea is the same). It also could move to the bottom of the file after an __END__ marker and remain with the script but be more segregated from the flow of code.