That example you point to appears to be a complete script, but is not.. you have to devise a way to get your desired attachment into
$file, and also devise a way to attach more than one file...
About
$file = $^X; it appears the author just picked a random file to assign to
$file for this particular example, so why not pick the perl executable itself, and hey why not use one of the builtin shorthands instead of typing "/usr/bin/perl".. Trés Geeky, non?
So to follow on the rest of this block:
open (F, $file) or die "Cannot read $file: $!";
binmode F; undef $/;
$mail{body} = encode_base64(<F>);
close F;
- Open $file for reading, with handle F.
- Treat it as a binary file (we know it probably wil not contain line ending characters), intending the attachment to be encoded as one input stream.
- Remove the normal assignment of the input record separator $/ (usually newline), this input won't need it. IMO that should be done within a sub, since it's never reset when the operation there finishes..
-The hash %mail already exists, assign new element "body" to contain the base64 encoded stream of $file.
There are a few Perl modules usable to create file attachments .. I keep recommending
Mail::SendEasy because it is so simple and cool.. no dependencies, it takes about 3 minutes to learn what it does and be up and running...
-Harold