| 2357/4390 |
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:
| file: /techref/language/perl/anglebrackets.htm, 3KB, , updated: 2007/1/22 18:37, local time: 2008/7/4 20:06,
38.103.63.16:LOG IN
|
| ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/language/perl/anglebrackets.htm"> Perl Function "angle brackets"</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20080704 Apptech, Jinx, Xiaofan Chen, David VanHorn, Alan B. Pearce, Bob Axtell, William \Chops\ Westfield, Cedric Chang, Gerhard Fiedler, bean, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Larry Williams, David VanHorn, Bryan Whitehouse, Timothy Weber, David Challis. Peter Todd. on-going support is MOST appreciated! * Contributors: Neil Narwani, David Cary, Elemer AM Nyiry, Philip J Taylor, Gus Calabrese of Omegadogs.com, Gautama Venegas, Patrick B. Murphy, William Chops Westfield, Peter Todd, Leslie Ellis |
|
.