#!/usr/bin/perl -w # File: UTFtobase64.pl use strict; use warnings; use MIME::Base64; my $ldif_input_fn = 'personal-utf-final.ldif'; my $ldif_output_fn = 'personal-final.ldif'; open (INFILE, $ldif_input_fn) or die "Error opening ".$ldif_input_fn.".\n"; binmode INFILE; my $content = ''; &read_file(\$ldif_input_fn, \$content); ## FIXME: what if the contents is on more than 1 lines # ? previous conversion '\n' -> '%%EOL%%' -> '\n' #$content =~ s/(\w+)(: *)([^\n]*)\n\n/$1.":".$2.encode_base64($3,'')."\n"/ges; ## take the smaller string ... #$content =~ s/(\w+)(: *)(.*?)\n\n/$1.":".$2.encode_base64($3,'')."\n"/ges; ## take the bigger string ... $content =~ s/(\w+)(: *)(.*)\n\n/$1.":".$2.encode_base64($3,'')."\n"/ges; &write_file(\('>'.$ldif_output_fn), \$content); exit(0); # reads a file sub read_file { my ($fn_ptr, $text_ptr) = @_; open (INFILE, $$fn_ptr) or die "Error opening ".$$fn_ptr.".\n"; binmode INFILE; ## read the whole text and convert windows linebreaks(\r\n) to unix ## linebreaks(\n) while (my $line = ) { $line =~ s!\r\n!\n!gs; $$text_ptr .= $line; } close INFILE; return; } # writes a file sub write_file { my ($fn_ptr, $text_ptr) = @_; open (OUTFILE, $$fn_ptr) or die "Error opening ".$$fn_ptr.".\n"; binmode OUTFILE; print OUTFILE $$text_ptr; close OUTFILE; return; }