in reply to Re: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об‰ line 112.
in thread utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об‰ line 112.

I will gladly do!

Yes, scripts live in Russian alphabet directory, that is in /usr/local/bin -- all in UTF8.

I did place the binmode lines in the script (the one that actually gives me the error and the one from which it is called) but i still get error message as above (regarding the script path (not readable characters).

I have tried open operator for find command. And can not understand how to get files it has found: how to put it into array. -- For

open(my $find, "|-:utf8", "/usr/bin/find -type f >/dev/null") or die " +Can't run find: $!\n"; while( <$find> ){ push @array, $_; }

Does not put anything into array.

Thank you for your extended answer, graff.

  • Comment on Re^2: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об&#137; line 112.
  • Download Code

Replies are listed 'Best First'.
Re^3: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об&#137; line 112.
by hippo (Archbishop) on Nov 04, 2015 at 09:39 UTC
    "find /usr/local/bin -type f >/dev/null"

    Of course this will produce no data because you are directing the output to /dev/null. What happens if you remove the output direction and instead just use find /usr/local/bin -type f ?

      I will answer by example.

      open( $vrm, "|-:utf8", "/usr/bin/find $put -$tip $kriteriy" ) or die " +Can't run find: $!\n"; while( <$vrm> ){ push @svitok, $_; } print "ZNAK\n"; print "\n>$svitok[0]<\n"; exit;

      Gives me this:

      ZNAK Use of uninitialized value $svitok[0] in concatenation (.) or string a +t /usr/local/src/исп/бибс/об&#137; line 122. ./svitok1 ./svitok2 ./svitok3 ><

      So:

      1. >/dev/null only outputs not to terminal -- array remains the same -- and i want to output nothing to terminal.

      2. Array is not filled.

      3. Strange, but ZNAK mark is outputted *before* output of find though in the code it stands (executed) *after* find. Why?

      I think of qx operator -- is there a way that PERL will continue the operator execution -- regardless the encodings present in its output?

      Thank you for participation very much!

        Looking specifically at this snippet: Is the "open" statement the very first line of your script? (In other words, is the output that you showed based on running a script that contained exactly those 6 lines of code and nothing else?) Of course, I expect that you would have at least assigned values to $put, $tip and $kriteriy. (But maybe these values are not what they should be in order for "find" to work the way you expect?)

        In any case, I suspect that you didn't include the "binmode" statements that I recommended in my early reply -- or if you did, then your file names are not encoded the way you think they are.

        Some other points:

        • If you don't want any output to go to your terminal, then you should redirect STDOUT and STDERR to output files on the command line when you run your script.
        • The output you showed did not come from the code you posted here. The best way to get help is to post a minimal BUT COMPLETE script, together with the output created BY THAT PARTICULAR complete script.
        • There's nothing strange about "ZNAK" showing up first in the output, because that is the first thing to be printed by your code. The output of the "find" command is being treated as input to your script, which is read via the "$vrm" file handle.
        As for using the "qx" operator, that's certainly an option (instead of using the pipeline "open") - you just have to make sure that you Encode::decode the string returned by "qx", so that perl can treat it properly as utf8 data.
Re^3: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об&#137; line 112.
by graff (Chancellor) on Nov 05, 2015 at 04:48 UTC
    If you look at the code snippet I posted, you'll see that I did not redirect the output of "find" to /dev/null -- as pointed out in the other replies above, that's why your array remained empty.

    One other point: now that you're pushing entries into an array, you'll probably want to use chomp -- e.g. like this:

    open(my $find,"|-:utf8","find /usr/local/bin -type f") or die "find fa +iled: $!\n"; while( <$find> ){ chomp; push @array, $_; }
    or leave out the while loop and chomp the whole array, like this:
    open( my $find, ... ) # (same as above, without redirecting to "/dev/n +ull") my @array = <$find>; # reads all lines into array chomp @array; # strips linefeeds from all array elements
      Thank you, so i will do, but i have to fill array first.
        I guess you are having trouble understanding what I'm saying -- both in English and in Perl. In the last snippet that I presented above (three lines of code), the array gets filled in the second line. The array is also declared and initialized in that line, so after that line executes, you can be confident that the array contains all and only the output of the "find" command.

        So, try putting the "binmode" statements above those three lines, make sure that the content of the "find" command itself is correct, add a line or a loop after my three lines, to print stuff out from the array, and see what happens. If you still have trouble after that, POST THE COMPLETE SCRIPT THAT YOU RAN, together with enough output (and error/warning messages) from running THAT EXACT VERSION of the script -- then it will be clearer to us what is going on. So far, you have been making it hard for us.

Re^3: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об&#137; line 112.
by choroba (Cardinal) on Nov 04, 2015 at 09:46 UTC
    >/dev/null discards any output. What do you expect to obtain by reading it?
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I tried both: w/ and w/o the redirection -- result for array was the same, while terminal wasn't filled w/ garbage (to me).