Hello,

my script, written at the bottom of this post, works, if I read a text file, which I have created before with this script:
my $out = './data/IDs_created.txt'; open (OUT, ">>$out"); print "Enter ID: \n"; while (<>) { print OUT "$_"; } close OUT;

But the script doesn't work, if I use a text file instead, which I parsed from an excel csv file with this script:

use warnings; use Text::CSV; use Encode; $file = './data/IDS.csv'; #Default #Parsing CSV my $csv = Text::CSV ->new ({binary =>1, eol => $/}); open (CSV, '<:encoding(utf8)', $file) or die "Cannot open $file: $!\n" +; open (OUT, '>:encoding(utf8)', './data/IDs_created.txt') or die "Kann +Datei nicht öffnen: $!\n"; while (my $line = <CSV>) { chomp $line; if ($csv->parse($line)) { my @fields = $csv->fields (); chomp (@fields); print OUT "@fields\n"; } else { warn "Line could not be parsed: $line\n"; } } print "CSV parsed and saved as text file: IDs_created.txt!"; close CSV; close OUT;

And here is the main script: it searches and copies files from one directory into another:

#!/usr/bin/perl # #Script allows to search and copy files #Thanks to Anonymous Monk #Works only with PERL created text file!!! # #tested: --ok! use strict; use warnings; use autodie; use File::Find::Rule; use File::Slurp; use File::Basename; use File::Copy; my $startdir = shift or die Usage(); my $dirTarget = '/cygdrive/d/tmp/'; my $fnames = join '|', map quotemeta, read_file('./data/IDs_created.tx +t' , qw/ chomp 1 /); my @fnames = find( file => name => qr{$fnames}, in => $startdir ); copy ($_, $dirTarget.basename ("$_")) for (@fnames);

Anonymous monk pointed out, that it might be a problem with encoding. But after hours of reading and unsuccessfully trying, I would appreciate any help on this question.

better


In reply to Read text file - Encoding problem? by better

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.