Good point. I meant that if the list is repeated in many places, any change to the list requires many code updates. It is easy to update some but forget the others.
Even better is to load the list from a file so that only the file is updated and never any code. Tom On Fri, Dec 27, 2013 at 9:49 AM, Derek Balling <dr...@megacity.org> wrote: > How is this solving the problem of "having to update code every time the list > of switch-inputs changes"? > > The array is still part of the source-code so if a new school is added, the > code still needs to be updated. > > D > > > On Dec 27, 2013, at 9:47 AM, Tom Limoncelli <t...@whatexit.org> wrote: > >> Sorry to beat a dead horse but... >> >> "switch" (or case or any variation) is not a great way to validate >> input. It means you need to update code every time the list changes. >> It is better to put all the valid input into an array and check >> against that. If all code refers to the array, all code will be >> updated any time the list changes. >> >> Here's how to check if something appears in a Perl array: >> http://stackoverflow.com/questions/720482/how-can-i-verify-that-a-value-is-present-in-an-array-list-in-perl >> >> Here's how I'd rewrite the code: >> >> print "$ARGV[0]\n"; #this prints the correct variable >> $code = $ARGV[0]; >> @schoolcodes = qw(rc bp ac ce ng jh hu fj lc lf md oh ar sh wc aw jc jp); >> >> # This requires Perl 5.10 >> #$school = 'ERROR'; >> #$school = $code if $code ~~ @schoolcodes; >> >> # This works on older Perl: >> if (grep{$_ eq $code} @schoolcodes) { >> $school = $code; >> } else { >> $school = 'ERROR'; >> } >> _______________________________________________ >> Tech mailing list >> Tech@lists.lopsa.org >> https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech >> This list provided by the League of Professional System Administrators >> http://lopsa.org/ > -- Email: t...@whatexit.org Work: tlimonce...@stackoverflow.com Skype: YesThatTom Blog: http://EverythingSysadmin.com _______________________________________________ Tech mailing list Tech@lists.lopsa.org https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech This list provided by the League of Professional System Administrators http://lopsa.org/