```{index} single: protect; File::Map function ``` ```{index} single: File::Map::protect; Perl function ``` # protect Change the read/write/execute protection of a mapped region. ## Synopsis ```perl protect $map, '<'; # read-only protect $map, '+<'; # read/write protect $map, PROT_READ; # constants also work ``` ## Arguments - `$lvalue` — a currently mapped scalar. - `$mode` — either a string in the same format as `open` (`'<'`, `'+<'`, `'>'`, `'+>'`), or a bitmask built from the `PROT_*` constants. If the new protection includes write permission the scalar becomes writable; otherwise it is marked read-only and direct assignment raises an exception. ## Examples Load a file read/write, patch it, then lock it down: ```perl map_file my $map, 'data.bin', '+<'; substr $map, 0, 4, "HEAD"; sync $map; protect $map, '<'; # prevent further writes ``` ## Edge cases - Protecting an unmapped scalar raises an exception. - Protecting an empty mapping updates the scalar's read-only flag but performs no kernel call. ## Differences from upstream Fully compatible with upstream `File::Map` 0.71. ## See also - `sys_map` — set protection when creating the mapping. - `advise` — hint access patterns rather than enforce permissions.