Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: -e not working Perl 5.008008

by GLJSD (Initiate)
on Feb 27, 2015 at 22:29 UTC ( [id://1118131]=note: print w/replies, xml ) Need Help??


in reply to Re: -e not working Perl 5.008008
in thread -e not working Perl 5.008008

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"; }

Replies are listed 'Best First'.
Re^3: -e not working Perl 5.008008
by kennethk (Abbot) on Feb 27, 2015 at 23:58 UTC
    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.

      Thanks to all for the feedback. I am just programming as a hobby - not a pro. I have saved these suggestions and will work on this in the coming week. Thanks again.

      Thanks for all the help. I just want to mention that I don't own the server. The site is being hosted by the company SiteGround (which I think is in the USA). The data file is also located on that same server. My Perl script is able to read the word "número" (from that data file) and store it into its variable $mes. Then, the Perl script prints that variable $mes to my browser and my browser displays the correct word. I tried this on my Win7 computer running Google Chrome, and also on my son's iPad using Safari. Perhaps, Perl stores n%C3%BAmero into that variable which browsers can resolve as you mentioned, but Perl is not able to resolve. The strange thing is that my local Perl (running through Apache) is able to resolve this. I'm fairly new to Perl, I didn't understand the ord test. I don't have access to a perl prompt (command prompt) if that's what you meant. I did add this code to my website, not sure if it's what you were hoping to see.

      for $i ( 0 .. 23 ) { $mfr=$info[$i]{'MFR'}; $mes=$info[$i]{'MES'}; my @array = split //,$mes; @array = map(ord, @array); my @chars = map(chr, @array); my @array2 = unpack("C*", $mes); my @chars2 = map(chr, @array2); $c="$dpmg/$mes.$epng"; if (-e $c) { $c2=$c; } else { $c2="$dpmg/_x2.png"; } $d="$dpmg/$mes.$epng"; print "<DIV>$mfr</DIV> <DIV>$mes</DIV> <DIV>$c</DIV> <IMG src='$c2'> <DIV>$d</DIV> <IMG src='$d'> <DIV>@array</DIV> <DIV>@chars</DIV> <DIV>@array2</DIV> <DIV>@chars2</DIV> <BR>\n"; }
        I note you stated you've resolved the issue in Re^4: -e not working Perl 5.008008. Let me know if you are still having trouble.

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

Re^3: -e not working Perl 5.008008
by Anonymous Monk on Feb 27, 2015 at 23:32 UTC
    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.
      Well that's weird cause in my browser I don't see exactly the three images for which Perl can't find the filenames.
      (cause it doesn't fall back to ISO-8859-1)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1118131]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found