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

Hi monks

It is surely a stupid error I'm doing, but I can't let the following work if $TextID contains white spaces. I see the logic why it is not working, but I'm havng problems solving this interpolation issue. Thank you

open (FILE, "files/pdftotext $path_folder/$TextID - |"); $text = do { local($/); <FILE> }; close FILE;

pdftotext is a PDF to Text converter (.exe) and I want the content of the text read by this tool in my variable $text for further processing. It works perfectly if the file name cntained in $TextID contains no spaces

Replies are listed 'Best First'.
Re: interpolation OPEN white spaces
by Corion (Patriarch) on Jan 20, 2016 at 08:51 UTC

    The list form of open for reading from processes is not really supported by Windows. Personally, I use the string form with whitespace properly quoted for Windows:

    my $cmd = qq(files\\pdftotext "$path_folder/$TextID" |); my $pid = open (FILE, $cmd) or die "Couldn't spawn [$cmd]: $! / $?"; $text = do { local($/); <FILE> }; close FILE;
      Upgrade! List form of pipe open implemented for Win32.

      Moreover, the OP didn't use the list form of open. There were the quotes missing, though.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        Moreover, the OP didn't use the list form of open.
        He did, he edited the post later.

      Thank you! That is! It works perfectly, provided the "-" is used. I just correct it here for future reference.

      my $cmd = qq(files\\pdftotext "$path_folder/$TextID" - |); my $pid = open (FILE, $cmd) or die "Couldn't spawn [$cmd]: $! / $?"; $text = do { local($/); <FILE> }; close FILE;
Re: interpolation OPEN white spaces
by Anonymous Monk on Jan 20, 2016 at 09:19 UTC
Re: interpolation OPEN white spaces
by RonW (Parson) on Jan 21, 2016 at 18:55 UTC

    There is also IO::Pipe (a core module), which works on MS Windows for Perl versions 5.20.x and older. But same as the new implementation of the list form of open in Perl 5.22.0, the limitations of system LIST apply. (Which are that if the LIST has only one element or the first attempt to spawn fails, the Windows command shell (cmd.exe) will be invoked.)