-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code: incorporate do_io.pl in FileIO.pm
- Loading branch information
Showing
11 changed files
with
36 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
package DivinumOfficium::FileIO; | ||
use strict; | ||
use warnings; | ||
use utf8; | ||
|
||
# Temporary measure: if we got here, the parent directory is on the library | ||
# search path, so this will work. | ||
BEGIN { | ||
|
||
package DivinumOfficium::FileIO; | ||
require "DivinumOfficium/do_io.pl"; | ||
} | ||
|
||
# Text-based IO for Divinum Officium Project. | ||
# | ||
BEGIN { | ||
require Exporter; | ||
our $VERSION = 1.00; | ||
our @ISA = qw(Exporter); | ||
our @EXPORT_OK = qw(do_read do_write); | ||
} | ||
|
||
# do_read(filename) | ||
# | ||
# Read a data file, assumed to be text, and return array of its lines. | ||
# Returns () if nothing can be read. | ||
sub do_read($) { | ||
my $file = shift; | ||
|
||
if (open(INP, '<:encoding(UTF-8)', $file)) { | ||
local $/; # Slurp | ||
local ($_) = <INP>; | ||
close INP; | ||
s/^\x{FEFF}//; | ||
split(/\r?\n/); | ||
} else { | ||
(); | ||
} | ||
} | ||
|
||
# do_write | ||
# Now we're in charge. Write in utf-8, never mind. | ||
sub do_write($@) { | ||
my $file = shift; | ||
|
||
if (open(OUT, ">:encoding(utf-8)", $file)) { | ||
print OUT for @_; | ||
close OUT; | ||
return 1; | ||
} | ||
} | ||
1; | ||
1; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters