in reply to IO::File handle and printf

Try without a space:

printf($fh <<"__EOFOO__", $stuff, $morestuff); ^^

Replies are listed 'Best First'.
Re^2: IO::File handle and printf
by rakzer (Novice) on Nov 03, 2010 at 13:57 UTC
    I tried this:
    #!/usr/bin/perl use IO::File; $stuff="0.4312342134234234"; $morestuff="0.2432134234342342"; $fh=IO::File->new(">/tmp/foo2.txt"); $fh=sprintf($fh <<"__EOFOO__", $stuff, $morestuff); Some stuff: %.4f Some more stuff %.4f __EOFOO__
    But I get:
    Missing comma after first argument to sprintf function at test.pl line + 12, near "$morestuff)" (Might be a runaway multi-line << string starting on line 9) Execution of test.pl aborted due to compilation errors.
      sprintf doesn't take a file handle as first argument.

      PS, I think you wanted to avoid having to detour over sprintf... ;-)

      The sprintf can't work, sorry, that slipped in. What I meant to show was:
      $fh=IO::File->new(">/tmp/foo2.txt"); printf($fh <<"__EOFOO__", $stuff, $morestuff); Some stuff: %.4f Some more stuff %.4f __EOFOO__
      As someone else pointed out, {} arround $fh will work.
        Works fine in 5.10 and 5.12. Maybe your version misinterprets << as a shift operator in that situation?
        What I meant to show was: ...
        And what is the problem with that?

        Works fine here, with various versions of Perl.