Brad Gilbert <b2gills <at> gmail.com> writes: >>Is it possible to find whether an array contains a given string? >Actually, all you would have to do is make sure that the elements of >the array are strings. > > perl -E '@a = ("1"); say "1 x" ~~ @a' Thanks. In my original code the array is of strings so I could use this. But when I dropped into the command line to test behaviour with some one-liners, I reflexively picked (1, 2, 3) as my example array. This is a slightly unperlish distinction; usually in Perl it doesn't matter whether a scalar holds the number 42 or the string '42' - you can use either of them in arithmetic or string operations with the same semantics and no warnings. This is a contrast to languages like Python where you have a visible difference between numeric and string objects. Smart matching might be the first everyday case where the difference between numbers and strings becomes obvious to the ordinary Perl programmer. -- Ed Avis <eda@waniasset.com>Thread Previous | Thread Next