Missing Python’s ‘in’ operator

April 22nd, 2002

I’m sitting here drawing a total blank. The plain white page of Nedit stares back at me, taunting.

How do I test for membership in a list using Perl? I think about the old writers trick, of just writing, even if you write “I do not know what to write” over and over. This does not work with coding. First its a syntax error. Second, Nedit will allow me to go on forever, filling page and page, I’ll never come to the end of the page, never reach that milestone, of having to stop, and turn the page, and examine how ridiculously my last 15 minutes were spent.

In Python I can ask: if ( target in list):
or I can speak about: for item in list:

In Perl…..I guess I say:
if ( grep { $target eq $_ } @list

Perl is my first language really, its what I reach for in the early hours of the morning, sleep deprivation setting in, and the problem just damn well needs to be solved, but ‘ewwww’, that grep trick is ugly, and not simply because its functional programming. So ugly in fact that my brain decided to spontaneiously forget it.

Tagged: Uncategorized , ,

Comments are closed.