GLJSD has asked for the wisdom of the Perl Monks concerning the following question:

My Perl script works fine on my local win7 computer using Apache24 Perl 5.016003 when using the -e file exists operator to test the existence of a regular filename such as "cero.png" and accented filename such as "número.png". However, when I upload that Perl script to my SiteGround host server running Perl 5.008008, the same script will work for a regular filename such as "cero.png", but not for any accented filename such as "número.png". Any suggestions. Here's part of that code, testing if a filename with a png file extention exists in my directory. $c="$dimg/$esp.$epng"; if (-e $c) { ...

Replies are listed 'Best First'.
Re: -e not working Perl 5.008008
by kennethk (Abbot) on Feb 27, 2015 at 20:10 UTC
    Are you sure that you've got stringwise equivalence on the name? Given that you are looking at non-ASCII characters, it's quite possible you've got encoding issues. Where do you get $esp? What happens when you run the following on your two platforms?
    perl -le 'print join q{-}, map ord,split q{} for <*mero.png>'

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      The data is retrieved from a tab-separated text file. You can visit the results at this address: http://www.1604.ca/cgi-bin/spanish.pl

      You'll notice that if I check for the existence of the image file, Perl does not see it. But the image is in fact there by looking at the next column where I don't check for its existence.

      Here's more of my code:
      for $i ( 0 .. 23 ) { $tit=$info[$i]{'TIT'}; $mfr=$info[$i]{'MFR'}; $mes=$info[$i]{'MES'}; $c="$dpmg/$mes.$epng"; if (-e $c) { $c2="<IMG src='$c'>"; } else { $c2="<IMG src='$dimg/_x2.png'>"; } $d="$dpmg/$mes.$epng"; $d2="<IMG src='$d'>"; $e="$dpud/$mes.$eaud"; if (-e $e) { $e="$daud/$mes.$eaud"; $e2="<IMG src=\"$dimg/_v1.png\" onclick=\"au.src='$e'; au.play() +;\" >"; } else { $e2="<IMG src='$dimg/_v0.png'>"; } print "<DIV>$tit</DIV> <DIV>$mfr</DIV> <DIV>$mes</DIV> <DIV cla +ss='fn'>$c</DIV> $c2 <DIV class='fn'>$d</DIV> $d2 $e2 <BR>\n"; }
        There's a couple of areas where you could be bit by encodings in this chain -- percent-encoding, HTML_entities, and Linux/Windows issues. That you are also rolling a web server into the mix does not simplify the issue. Did you perform the ord test I described before? The working accented link is resolved by the browser as
        http://www.1604.ca/espanol/images/n%C3%BAmero.png
        which means you're using UTF codepoint U+00FA, or 250. This is possibly subject to some major high-bit code page malarkey. What happens when you run
        perl -le 'print -e sprintf "n%smero.png", chr 250'
        in the target directory? Usually, this sort of problem comes down to figuring out where you've forgotten to encode/decode a string. My copy of perl 5.8.9 handles this just fine.

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        But the image is in fact there by looking at the next column where I don't check for its existence.
        Well that's weird cause in my browser I don't see exactly the three images for which Perl can't find the filenames. Anyway, $info[$i]{'MES'} (or whatever) contains Latin-1 strings. Which your OS can't find, presumably because the real filenames are in UTF-8. OTOH, Windows can, because of some legacy codepage nonsense or some such.
Re: -e not working Perl 5.008008
by Anonymous Monk on Feb 27, 2015 at 20:06 UTC
    Any suggestions.
    Yes, check filename's encoding.

    Or post more code. It's impossible to say anything meaningful when all we have is just  $c="$dimg/$esp.$epng"; if (-e $c) { ...

Re: -e not working Perl 5.008008
by Anonymous Monk on Feb 28, 2015 at 00:30 UTC

      The Perl script works fine when I am running it on my home computer running Win7 and Apache for Perl. I enter http://localhost/cgi-bin/spanish.pl for the URL in my browser and it works.

      The problem occurs however, when I upload the Perl script to a web server (hosted by the company SiteGround). I enter http://www.1604.ca/cgi-bin/spanish.pl for the URL. Could it be that their operating system is missing something? I can't imagine they're running Windows.