感谢! 这种方法我有想过 但是 想知道 有没有 根据文件位置 s/$aims//的办法 或者其他办法 比如说 print一个空数据? 业余初学 望见谅
On 8月8日, 下午7时24分, Anthony WU <[email protected]> wrote: > 我把 seek 第二 及第三個參數寫反了,刪除是不能的,但你可以通過 先讀 > 0x00-0x8f 跳到0xb0再讀到EOF並把所取得的BYTES寫到新檔案 > > > > -------- Original Message -------- > Subject: [PerlChina] Re: 16进制文件操作 > From: perlw01f <[email protected]> > To: PerlChina Mongers 讨论组 <[email protected]> > Date: 8/8/2009 10:42 > > 谢谢 > > perldoc -f seek的结论貌似跟这个不一样 ? > > > seek FILEHANDLE,POSITION,WHENCE > > Sets FILEHANDLE's position, just like the "fseek" call of > > "stdio". FILEHANDLE may be an expression whose value gives > > the > > name of the filehandle. The values for WHENCE are 0 to set > > the > > new position *in bytes* to POSITION, 1 to set it to the > > current > > position plus POSITION, and 2 to set it to EOF plus POSITION > > (typically negative). For WHENCE you may use the constants > > "SEEK_SET", "SEEK_CUR", and "SEEK_END" (start of the file, > > current position, end of the file) from the Fcntl module. > > Returns 1 upon success, 0 otherwise. > > > Note the *in bytes*: even if the filehandle has been set to > > operate on characters (for example by using the ":utf8" open > > layer), tell() will return byte offsets, not character > > offsets > > (because implementing that would render seek() and tell() > > rather > > slow). > > > If you want to position file for "sysread" or "syswrite", > > don't > > use "seek"--buffering makes its effect on the file's system > > position unpredictable and non-portable. Use "sysseek" > > instead. > > > Due to the rules and rigors of ANSI C, on some systems you > > have > > to do a seek whenever you switch between reading and > > writing. > > Amongst other things, this may have the effect of calling > > stdio's clearerr(3). A WHENCE of 1 ("SEEK_CUR") is useful > > for > > not moving the file position: > > > seek(TEST,0,1); > > > This is also useful for applications emulating "tail -f". > > Once > > you hit EOF on your read, and then sleep for a while, you > > might > > have to stick in a seek() to reset things. The "seek" > > doesn't > > change the current position, but it *does* clear the end-of- > > file > > condition on the handle, so that the next "<FILE>" makes > > Perl > > try again to read something. We hope. > > > If that doesn't work (some IO implementations are > > particularly > > cantankerous), then you may need something more like this: > > > for (;;) { > > for ($curpos = tell(FILE); $_ = <FILE>; > > $curpos = tell(FILE)) { > > # search for some stuff and put it into files > > } > > sleep($for_a_while); > > seek(FILE, $curpos, 0); > > } > > > 另外,您的code 我尝试了一下 > > seek ($fp, 0, 0x80); > > print $fp "\x0"; > > 实际的效果是 00000000h这一行 第1和2字节变成了0 没有偏移? > > 我自己尝试 > > seek ($fp, 16*8, 0x00); > > print $fp "\x0"; > > 可以达到目的 > > > 另外 我想请教 如何删除掉一部分内容呢 比如 0x90-0xb0 > > 谢谢 > > On 8月8日, 上午12时48分, Anthony WU <[email protected]> wrote: > > >> 以你所說的操作大約是 > >> open (my $fp, '+<', 'x.dat'); > >> binmode ($fp); > >> seek ($fp, 0, 0x80); > >> print $fp "\x0"; > >> seek ($fp, 0, 0x82); > >> print $fp "\x0"; > >> seek ($fp, 0, 0x84); > >> print $fp "\x0"; > >> seek ($fp, 0, 0x86); > >> print $fp "\x8B"; > >> seek ($fp, 0, 0x87); > >> print $fp "\x8B"; > >> seek ($fp, 0, 0x88); > >> print $fp "\x0A"; > >> seek ($fp, 0, 0x89); > >> print $fp "\x0A"; > >> .... > >> .... > >> .... > >> close ($fp); > > >> -------- Original Message -------- > >> Subject: [PerlChina] Re: 16进制文件操作 > >> From: perlw01f <[email protected]> > >> To: PerlChina Mongers 讨论组 <[email protected]> > >> Date: 7/8/2009 21:16 > > >>> 都是在确定的位置 > > >>> 如 00000080h 这一栏 第1 3 5 字节换为0 78换为8B 9 10 换为0A 还有一些其他的 > > >>> On 8月7日, 下午9时04分, Anthony WU <[email protected]> wrote: > > >>>> 你的字節是定位修改的嗎?有什麼規律的? > > >>>> -------- Original Message -------- > >>>> Subject: [PerlChina] Re: 16进制文件操作 > >>>> From: perlw01f <[email protected]> > >>>> To: PerlChina Mongers 讨论组 <[email protected]> > >>>> Date: 7/8/2009 20:56 > > >>>>> 我有一个文件 x.dat,由x.rar.gz压缩而成 但是其中某些字节做了修改处理 现在的文件名是 a.dat > >>>>> 现在 我想逆行操作,即 > >>>>> 先将a.date rename成x.rar.gz 然后利用ue修改某些字节 之后才能解压缩成x.date > > >>>>> 由于文件数量较多 且ue 16进制 修改也不是很方便 > >>>>> 所以想 用 perl实现 > >>>>> 谢谢 > > >>>>> On 8月7日, 下午5时17分, cnhack TNT <[email protected]> wrote: > > >>>>>> 能举例说明你要做的事情么? > > >>>>>> 2009/8/7 perlw01f <[email protected]> > > >>>>>>> perl中 有没有类似ultredit中那种直接转换成16进制进行操作的方法或者module > > >>>>>>> unpack是不是太费事了 > > >>>> -- > >>>> Best Regards, > >>>> Anthony WU > > >> -- > >> Best Regards, > >> Anthony WU > > -- > Best Regards, > Anthony WU --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
