in reply to Doesn't work in Cygwin

First thing I'd check if it worked with ActiveState but not Cygwin, was the 'chomp'.

Check so it isn't confused about 1 or 2 chars end-of-lines. (See what you have after the chomp, either one char to little or an extra \n.)

(It is a potential mess. You can configure Cygwin for how it should treat eol:s. Also, if you wrote the data file in Unix and copied over the file in bin format, you'd get a single \n.)

Update:
Should add some code that do reading w/out extra chars in Cygwin, as bart did. This works for me in fixing up mixed files (I use an old version of Ultraedit that mixes line endings! Don't use Win much).

while(<$fh>) { chop; chop if /\015$/; print UT $_; print UT "\012"; } close $fh;

Replies are listed 'Best First'.
Re^2: Doesn't work in Cygwin
by bart (Canon) on Nov 16, 2005 at 12:28 UTC
    To the OP: I agree with berntB, the opinionated way Cygwin deals with line endings could really mess things up. If chomp doesn't work, you can always call
    tr/\r\n//d
    to completely get rid of LF and CR characters.

    Furthermore, you check for duplicates with

    if ($list_to_match =~ /$randomized_entry/)
    which is an extremely poor ways to handle this kind of things. It won't match if unexpectedly $randomized_entry contains meta characters, it's prone to crashes if it doesn't actually look like a valid regexp, and it'll give you false positives when for example $randomized_entry contains "foo", and $list_to_match contains "if music be the food of love".
      Do you have a suggestion how you would handle the matching procedure here? The randomized lists consist of a particular type of string (a reference ID) and these same kinds of strings are in the list to match array elements.
      The latter case you describe cannot happen with these, but I guess some meta-characters might conceivably be able to feature in the reference IDs.

      Would you suggest using \Q?

        It depends on what you really want. If you just want to test for equality, I'd use eq. If you want to test if a string is a substring of another string, I'd use index. I'd only use regular expressions only as a very last resort, when indeed you need more power in functionality than offered by the above, such as wildcarding (in which case, use "." instead of "?" and ".*" instead of "*").

        Yes, in the latter case, quotemeta could have its uses.