When you specify an empty import list, for example:
use MIME::Base64 ();
Import is not possible.
Change this line to:
use MIME::Base64;
The ()
parameter indicates that MIME :: Base64 does not export anything to your namespace. The default behavior (without partners) is to export encode_base64
and decode_base64
. You override a convenient default value. If you really do not want these functions to pollute the main
namespace, you could save the original line use MIME::Base64 ()
, and then fully qualify your subroutine call:
$encoded = MIME::Base64::encode_base64($base64_string);
But it is much simpler and probably satisfactory to simply allow default export list processing by removing the brackets from the use
string.
Refresh . You also do not read the file. This line:
$base64_string = IMAGE;
... should be updated as follows:
$raw_string = do{ local $/ = undef; <IMAGE>; }; $encoded = encode_base64( $raw_string );
This problem would be solved in more detail if you had use strict 'subs'
. The problem is that " IMAGE
" itself is just a gobe, and Perl considers it a subroutine call. Angle brackets " <>
" are the usual way to read from a file descriptor. The " local $/ = undef
" part is just a means of ensuring that you process the entire file, not just the first sequence, which looks like "\ n" in Perl.
Update2: And, as MOB points out, you need to either avoid backslashes in your path, or use slashes. Perl doesn't mind, even on Win32. Of course, since you are taking the wise step of using or die $!
on your open
, you already discovered this error.
source share