The problem arises because you quote AND escape (\). Choose one or the other.

Secondly, the ~ character has meaning within the shell. Perl, I guess, sees ~ as part of the filename and does not expand it to mean home-dir as the unix shell would. So avoid using linux shell shortcuts in a Perl expression.

This sort of quoting should work but notice that I removed the tilde, you need to find a way to substitute it with a Perl equivalent, perhaps $ENV{HOME}? :

my $BibleFullNames = $ENV{HOME}."/Aoo/01-Writer/Other/UMC\~\~\ Change +water/\[01\]\ Team\ Leader-\ Worship\ Service/Bible\ Books,\ Full\ Na +mes.txt"; if (!(-e $BibleFullNames)) { Log2die("**Fatal err, can't find Bible names file (\"$BibleFullNames +\")"); }

EDIT: you may find this useful: Re^3: quoting/escaping file names, it mentions String::ShellQuote which will do all the dirty work for you.

EDIT2: the more I think about it the more I am convinced that you SHOULD use a module for escaping your filenames (String::ShellQuote works only for Bourne shell, I would search for the equivalent of DBI's quote()), and also use a module to handle the path separator (/ or \\ or // or whatever). Then your Perl script will be portable and work in the 2 OS without need to further change this or that. For example, here is how I construct paths in a portable way: use File::Spec; my $path = File::Spec->catfile('a', 'b', 'c');.

EDIT3(24h+): the difference between $x = "\ "; $y = '\ '; is that $x will contain a space. Whereas $y will contain a backslash followed by a space. Perl single quotes do not interpolate their contents, unlike the double quotes (escaped characters and also variables). In $y, the backslash is kept in the string and is passed on to anyone who consumes it, shell included. So, if you want to pass a filename to the shell for processing, as in for example system("ls $file") then $file should contain literal backslashes to meta-escape any space in there, as in $y. That or system("ls '$file'") (notice the single quotes) when $file is somwething like $x and it does not contain any backslashes. If you do -e $file then $file should be something like $x. Because if there is a backslash character in $file which does not serve to escape any following character then perl interprets it as part of the filename. So there are some queer characters which in the 70's were marginalised and discriminated against but now have rightly claimed equal treatment being part of the ASCII-kind and all. Still, old software demands that these characters are escaped. Escaping takes place in many levels simply because one program passes on parameters to another, a single backslash is lost from one passing to the next. So Perl passes on parameter to the shell (e.g. via a system ls)? Then make sure that parameter includes backslashes as means to escape funny characters. Does that system calls yet another command which calls another command? Then you may have to escape twice. And so on. I am definetely not the expert in escaping though and I may have missed some crucial points.

bw, bliako


In reply to Re: Ubuntu File Names with spaces and special characters by bliako
in thread Ubuntu File Names with spaces and special characters by EigenFunctions

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.