Hello PerlMonks, I'm using File::Util to create directory trees in the event they don't exist and copy a file into the child directories. I create the $directory variable dynamically, but the module keeps telling me I'm passing illegal characters, and I'm just not seeing what I'm doing wrong. Here's the code:
BEGIN { use strict; use File::Next; use File::Util; use File::Copy; } my ($file_util) = File::Util->new(); move_files() sub move_files { open (FILE, "<ad_archive.rtf") or die "$!\n"; while (<FILE>) { next if ($_ !~ /\w/); my ($full_path) = ($_ =~ /\d*\s(.*)/); my ($par_dir, $file_name) = ($full_path =~ /.*\\(.*)\\(.*)/); my ($file_no_ext) = ($file_name =~ /(.*)\.pdf/); my ($first_five) = ($file_no_ext =~ /(\d{5}).*/); $first_five .= 'xxx'; if ($par_dir =~ $file_no_ext) { my $directory = "\\\\filervoca\\e\$\$\\activeads\\adwatchf +olders\\$first_five\\$file_no_ext"; #print "path: $full_path\npar_dir: $par_dir\nfile_name: $f +ile_name\nfirst_five: $first_five\ndirectory: $directory\n"; #print "dir doesn't exist, need to make it\n"; $file_util->make_dir($directory, '--if-not-exists') or die + "$!"; copy($full_path, "$directory\\$file_no_ext"."00.pdf") or d +ie (print "$!"); } sleep 10; } close FILE; }
Here's the error I get:
<b> PROCESS TERMINATED DUE TO ERRORS File::Util can't use this string for (weird character)the name of a di +rectory1/2. (same weird character)\\filervoca\e$$\activeads\adwatchf +olders\00232xxx\00232351(1/2) It contains illegal characters. Illegal characters are: \ (backslash) / (forward slash) : (colon) | (pipe) * (asterisk) ? (question mark) " (double quote) < (less than) > (greater than) \t (tab) \ck (vertical tabulator) \r (newline CR) \n (newline LF) Origin: This is a human error. Solution: A human must remove the illegal characters from this string. ARG _pak = File::Util ARG purpose = the name of a directory ARG string = \\filervoca\e$$\activeads\adwatchfolders\00232xxx\0023235 +1 1. File::Util::_throw -called at line(1322) of blib\lib\File\Util.pm --was called with args --was not called to evaluate anything 2. File::Util::make_dir - called at line (45) of findpdfs.pl --was called with args --was not called to evaluate anything 3. main::move_files -called at line (11) of findpdfs.pl --was called with args --was not called to evaluate anything </b>
Thank you in advance for your help.

In reply to finding odd characters in a string that I am creating in the script by donkeykong

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.