NAME

Tie::Slurp - tie a scalar to a named file

SYNOPSIS

use Tie::Slurp;
tie my $template => Tie::Slurp::ReadOnly => 'template';
tie my $output   => Tie::Slurp => 'output';
($output = $template) =~ s/\[(\w+)\]/$data{$1}/g;

DESCRIPTION

Tie::Slurp associates a scalar with a named file. Read the scalar, the file is read. Write to the scalar, the file gets clobbered. Flock is used for collision avoidance.

Tie::Slurp::ReadOnly works the same as Tie::Slurp, except that STORE croaks.

CAVEAT

Though Tie::Slurp does flock, it still has a 'race condition' problem in many cases. When you do something to the STOREed data, the tied file opens and locks first to FETCH, and closes here once. Then the FETCHed data gets changed, and the file opens and locks again to STORE them. So, if someone access the file while you are changing your data, something unwanted may happen. Tie::Slurp is useful, but don't use it under severe conditions.

AUTHOR

David Nicol, <davidnico@cpan.org>

CO-MAINTAINER

Kenichi Ishigaki, <ishigaki@cpan.org>

SEE ALSO

File::Slurp

Abigail's comparison of slurping idioms on p5p, October 2003

perlopentut

LICENSE

GPL/AL