See also:
Samples
$old = $file; $new = "$file.bak"; $bak = "$file.orig"; open(OLD, "< $old") or die "can't open $old: $!"; binmode OLD; open(NEW, "> $new") or die "can't open $new: $!"; binmode NEW; $mydata = ""; while (<OLD>) { $mydata .= $_; } #now you can do stuff to $mydata; #be sure to use s on the end of any regexps so that it will work across "lines" #and use g on the end to replace all occurances #e.g. s/old text/new text/sg (print NEW $mydata) or die "can't write to $new: $!"; close(OLD); close(NEW; rename($old, $bak) rename($new, $old)
errr... no. no. no. see perlfaq6.html i'm having trouble matching over more than one line. what's wrong which basically says that if you put in
undef $/;
you will read in the entire thing in one shot rather than line by line and binmode shouldn't matter then. Also, you can set $/ to an ORDINAL number and it will read only that number of bytes.
See: