I found this sub in another module (TextUnicode):

# Custom file save routine to handle unicode files sub SaveUTF { my ( $w, $filename ) = @_; $filename = $w->FileName unless defined $filename; my $dir = dirname($filename); my $perms = ( stat($dir) )[2] & 07777; unless ( $perms & 0200 ) { $perms = $perms | 0200; chmod $perms, $dir or $w->BackTrace("Can not write to directory $dir: $!\n") and return; } my ( $tempfh, $tempfilename ) = tempfile( DIR => $dir ); my $status; my $count = 0; my $index = '1.0'; my $progress; my $fileend = $w->index('end -1c'); my ($lines) = $fileend =~ /^(\d+)\./; my $unicode = ::currentfileisunicode(); # No BOM please #if ($unicode) { # my $bom = "\x{FEFF}"; # utf8::encode($bom); # print $tempfh $bom; #} while ( $w->compare( $index, '<', $fileend ) ) { my $end = $w->index("$index lineend +1c"); my $line = $w->get( $index, $end ); $line =~ s/[\t \xA0]+$//; #$line = ::eol_whitespace($line); $line =~ s/\cM\cJ|\cM|\cJ/\cM\cJ/g if (OS_Win); utf8::encode($line) if $unicode; $w->BackTrace("Cannot write to temp file:$!\n") and return unless print $tempfh $line; $index = $end; if ( ( $count++ % 1000 ) == 0 ) { $progress = $w->TextUndoFileProgress( Saving => $filename, $count, $count, $lines ); } } $progress->withdraw if defined $progress; close $tempfh; if ( -e $filename ) { chmod 0777, $filename; unlink $filename; } if ( rename( $tempfilename, $filename ) ) { #$w->ResetUndo; #serves no purpose to reset undo $w->FileName($filename); return 1; } else { my $msg = "Cannot save $filename:$!. Text is in the temporary +file $tempfilename."; $w->messageBox( -icon => 'warning', -title => 'Warning', -type => 'OK', -message => $msg.(OS_Win?" (Are you using Windows Explorer + Preview?)":""), ); $w->BackTrace($msg); return 0; } }
Regards, Wayne

In reply to Re^4: File permissions problem (updated) by wdhammond
in thread File permissions problem by wdhammond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.