in reply to Re: Search element of array in another array
in thread Search element of array in another array

Thanks Anonymous Monk pointing to Data::Dumper. I checked both arrays

The result show clearly, that the structure of the elements is different. An example:

print Dumper @allwords;

...

$VAR9 = 'hat

';

...

print Dumper @cleanwords;

...

$VAR6 = 'hat';

...

I selected the word which should match. In @allwords the single quotation mark appears in a new line. Maybe it's caused by newline? and I should chomp the elements?

I chomped it like this:

chomp (@allwords);

Result:

';AR9 = 'hat

The single quotation mark of the predecessing word appears in the sam line.

Replies are listed 'Best First'.
Re^3: Search element of array in another array
by Anonymous Monk on Mar 26, 2015 at 20:21 UTC

    Please mark updates to your nodes, see here for why.

    I chomped it like this: ... ';AR9 = 'hat ... The single quotation mark of the predecessing word appears in the sam line.

    I'd guess the file is terminated by CRLF and your input record separator $/ is a plain LF. One approach to fix this is to set $/ = "\r\n"; before reading the file and the chomp. If you were using a regular open, you could use the :crlf I/O layer: open my $handle, '<:crlf', 'filename.txt' or die $!; (see PerlIO).

      ... and File::Slurp::Tiny should allow you to do this: read_lines("filename", chomp=>1, binmode=>":crlf")

      All correct!!!

      I put your line into my script and: TATA!!!! It works

      Hours

      and hours

      and hours....

      I love being a scripting amateur. ;-)

      Thanks anonymous monk, you safed my evening! :-))

Re^3: Search element of array in another array
by Anonymous Monk on Mar 26, 2015 at 20:13 UTC
    Maybe it's caused by newline? and I should chomp the elements?

    Yes and yes! :-)

    As mentioned below, try setting $Data::Dumper::Useqq=1; before calling Dumper.