Tie::ScalarFile -
use Tie::ScalarFile; my $string; tie ($string, "Tie::ScalarFile", "file.txt"); $string = <<".EOF."; blah blah blah... .EOF. #file.txt now contains "blah blah blah...". print $string; #prints "blah blah blah...". print count; #prints "1".
Tie::ScalarFile is a perl module for associating scalars with files. You can then add to the scalar, and the file will be written to. You can read the value, and the file will be read from.
counts the number of currently tied scalars, and returns it. for example:
tie (my $string, "Tie::ScalarFile", "file.txt"); tie (my $string2, "Tie::ScalarFile", "file2.txt"); print count; #prints "2".
here is a real-life example:
#!/usr/local/bin/perl -w use Tie::ScalarFile; my $contents; tie ($contents, "Tie::ScalarFile", "test.txt"); while (<>) { #while there's stdin... $contents = $_; #...write the input to the test.txt file... print $contents; #...and then read it in and print it. } print "There are " . count . "tied scalars."; #print the number of tied scalars.
count
Tie::Scalar, Tie::File
Linc Nightcat, <nightcat@crocker.com>
Copyright (C) 2005 by <nightcat>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Tie::ScalarFile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::ScalarFile
CPAN shell
perl -MCPAN -e shell install Tie::ScalarFile
For more information on module installation, please visit the detailed CPAN module installation guide.