- 论坛徽章:
- 1
|
使用open 和 IO::file ??
- IO::File.pm
- =============================
- sub new {
- my $type = shift;
- my $class = ref($type) || $type || "IO::File";
- @_ >;= 0 && @_ <= 3
- or croak "usage: new $class [FILENAME [,MODE [,PERMS]]]";
- my $fh = $class->;SUPER::new();
- if (@_) {
- $fh->;open(@_)
- or return undef;
- }
- $fh;
- }
- sub open {
- @_ >;= 2 && @_ <= 4 or croak 'usage: $fh->;open(FILENAME [,MODE [,PERMS]])';
- my ($fh, $file) = @_;
- if (@_ >; 2) {
- my ($mode, $perms) = @_[2, 3];
- if ($mode =~ /^\d+$/) {
- defined $perms or $perms = 0666;
- return sysopen($fh, $file, $mode, $perms);
- }
- if (! File::Spec->;file_name_is_absolute($file)) {
- $file = File::Spec->;catfile(File::Spec->;curdir(),$file);
- }
- $file = IO::Handle::_open_mode_string($mode) . " $file\0";
- }
- open($fh, $file);
- }
复制代码
看代碼會比較清楚...
IO::File->;new會call IO::File->;open 然後call open...
IO::File是比較OO的寫法....當然,如果我們不管OO..
直接調用open()會比較快... |
|