Skip to content
Snippets Groups Projects
Select Git revision
  • 3b160cbdbb386801c522cd8eca7067e19ff94631
  • master default protected
2 results

gg1.pm

Blame
  • gg1.pm 2.65 KiB
    # vim:ai
    
    =pod
    
    =head1 NAME
    
      package Util::gg1  --  simple utility functions
    
    =cut
    
    package Util::gg1;
    
    use strict;
    
    use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
    use Exporter;
    
    $VERSION= '0.10';
    @ISA= qw(Exporter);
    @EXPORT_OK= qw(attach sec2hms ts_iso ts1 fisher_yates_shuffle);
    %EXPORT_TAGS= ('MAIL' => [qw(attach)], 'TS' => [qw(sec2hms ts_iso ts1)], 'FYS' => [qw(fisher_yates_shuffle)]);
    
    use POSIX qw(strftime);
    
    =pod
    
    =head2 attach (*F, $boundary, $filename, $heading)
    
    print contents of $filename to filehandle *F as an attachment, using
    $boundary to delimit that attachment.  $heading is used in error messages.
    
    =cut
    
    sub attach
    {
      local *FO= shift;
      my $boundary= shift;
      my $fnm= shift;
      my $heading= shift;
    
      print FO "\n";
      local *FI;
      ## print " >>> attaching [$fnm]\n";
      if (open (FI, $fnm))
      { # don't write the full path name of the file in the disposition header
        my @fnm= split ('/', $fnm);
        my $f_nm= pop (@fnm);
    
        print FO <<EO_ATTACH;
    
    --$boundary
    Content-Type: text/plain; charset='iso-8859-1"
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment; filename="$f_nm"
    
    EO_ATTACH
    
        # print FO "$heading file '$fnm':\n";
        while (<FI>) { print FO $_; }
        close (FI);
      }
      else
      {
        print FO "can't read $heading file '$fnm'!\n";
      }
      print FO "\n";
    
    }
    
    =pod