में पढ़ने और लिखने (संलग्न नहीं) के लिए फ़ाइल खोलें मानक पर्ल पुस्तकालयों के साथ फ़ाइल खोलने और इसे संपादित करने के लिए कोई तरीका है, इसे बंद किए बिना इसे फिर से खोलें? मुझे पता है कि कैसे करना है फ़ाइल को बंद करने वाली स्ट्रिंग में फ़ाइल को पढ़ने के लिए फ़ाइल को फिर से लिखना; या पढ़ें और फिर फ़ाइल के अंत में संलग्न करें।पर्ल
निम्नलिखित में वर्तमान में काम करता है; मैं इसे खोल सकते हैं और इसे दो बार बंद करने के लिए, एक बार के बजाय है:
#!/usr/bin/perl
use warnings; use strict;
use utf8; binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8");
use IO::File; use Cwd; my $owd = getcwd()."/"; # OriginalWorkingDirectory
use Text::Tabs qw(expand unexpand);
$Text::Tabs::tabstop = 4; #sets the number of spaces in a tab
opendir (DIR, $owd) || die "$!";
my @files = grep {/(.*)\.(c|cpp|h|java)/} readdir DIR;
foreach my $x (@files){
my $str;
my $fh = new IO::File("+<".$owd.$x);
if (defined $fh){
while (<$fh>){ $str .= $_; }
$str =~ s/(|\t)+\n/\n/mgos;#removes trailing spaces or tabs
$str = expand($str);#convert tabs to spaces
$str =~ s/\/\/(.*?)\n/\/\*$1\*\/\n/mgos;#make all comments multi-line.
#print $fh $str;#this just appends to the file
close $fh;
}
$fh = new IO::File(" >".$owd.$x);
if (defined $fh){
print $fh $str; #this just appends to the file
undef $str; undef $fh; # automatically closes the file
}
}
1k + विचार और केवल 1 अपवॉट। । । – GlassGhost
2 अपवॉट्स अब: $ 0 I32 :-) – GLES