develooper Front page | perl.perl5.porters | Postings from November 2009

Re: [perl #67838] lvalue substr keeping lexical alive

Thread Previous | Thread Next
Kevin Ryde
November 17, 2009 06:04
Re: [perl #67838] lvalue substr keeping lexical alive
Message ID:
use strict;
use warnings;
use File::Map;

# the mmap magic on $str is held,
# no munmap until program exit

# create /tmp/foo.tmp
open my $fh, '+>', '/tmp/foo.tmp' or die;
print $fh ("Z" x 512) or die;
close $fh or die;

sub foo {
  my $str;

  open my $fh, '+<', '/tmp/foo.tmp' or die;
  File::Map::map_handle ($str, $fh, '+>', 0, 512);
  close $fh or die;

  substr($str,0,1) = 'o';

print "foo() runs ...\n";

print "\"fuser /tmp/foo.tmp\" says ...\n";
system 'fuser /tmp/foo.tmp';

print "end\n";
exit 0;

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About