Pregunta

What could be wrong here?

I am trying to display the content of an existing file:

perl -MFile::Slurp -e 'print File::Slurp->read_file("/tmp/001.jpg", { binmode => ":raw" } ) if -e "/tmp/001.jpg"; '

and I get the error:

read_file 'File::Slurp' - sysopen: No such file or directory

The file exists, the print gets executed only if -e "/tmp/001.jpg"

¿Fue útil?

Solución

Call the function via File::Slurp::read_file instead of File::Slurp->read_file. In the latter case Perl's object system comes into play, and the first argument passed to read_file will be the thing before the -> -- meaning its first argument will be the string "File::Slurp" instead of the file name you actually want to read.

That's also why you call new on the packages you want to create a new instance from.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top