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

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

Thread Previous | Thread Next
From:
Kevin Ryde
Date:
November 17, 2009 06:04
Subject:
Re: [perl #67838] lvalue substr keeping lexical alive
Message ID:
878we641yu.fsf@blah.blah
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";
foo();

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

print "end\n";
exit 0;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About