Perl在传递时不读取文件' +>>'

时间:2015-11-09 14:37:04

标签: perl

我正在尝试将文件的内容放入数组中以进行grepping,但由于某种原因,当我通过' +>>'时,它会失败。论点。但是,当我使用不同的参数打开两个单独的文件句柄到同一个文件时,它可以工作

这有效:

open( FILEHANDLE, '<', $file ) or $file_not_found = 1;
open( APPENDFH, '>>', $file );
my @file_list = <FILEHANDLE>;
print("This is my file list @file_list \n");

打印:

This is my file list 2015-11-06 11:17:57Example

这不是:

open( FILEHANDLE, '+>>', $file ) or $file_not_found = 1;
my @file_list = <FILEHANDLE>;
print("This is my file list @file_list \n");

打印:

This is my file list

2 个答案:

答案 0 :(得分:5)

+>>在最后打开文件。你需要回到开头阅读它:

seek FILEHANDLE, 0, 0;

但是您可以使用+<直接打开文件。

答案 1 :(得分:4)

+>>O_APPEND打开文件for append(seek($fh, 0, SEEK_SET)),将文件光标放在文件末尾。您可以使用+<移动文件指针,也可以使用G N U P L O T Version 5.0 patchlevel 1 last modified 2015-06-07 Copyright (C) 1986-1993, 1998, 2004, 2007-2015 Thomas Williams, Colin Kelley and many others gnuplot home: http://www.gnuplot.info faq, bugs, etc: type "help FAQ" immediate help: type "help" (plot window: hit 'h') Terminal type set to 'unknown' gnuplot> plot sin(x) WARNING: Plotting with an 'unknown' terminal. No output will be generated. Please select a terminal with 'set terminal'. gnuplot> set terminal Available terminal types: canvas HTML Canvas object cgm Computer Graphics Metafile context ConTeXt with MetaFun (for PDF documents) corel EPS format for CorelDRAW dumb ascii art for anything that prints text dxf dxf-file for AutoCad (default size 120x80) eepic EEPIC -- extended LaTeX picture environment emf Enhanced Metafile format emtex LaTeX picture environment with emTeX specials epslatex LaTeX picture environment using graphicx package fig FIG graphics language for XFIG graphics editor gif GIF images using libgd and TrueType fonts hpgl HP7475 and relatives [number of pens] [eject] jpeg JPEG images using libgd and TrueType fonts latex LaTeX picture environment lua Lua generic terminal driver mf Metafont plotting standard mp MetaPost plotting standard pcl5 HP Designjet 750C, HP Laserjet III/IV, etc. (many options) png PNG images using libgd and TrueType fonts postscript PostScript graphics, including EPSF embedded files (*.eps) pslatex LaTeX picture environment with PostScript \specials pstex plain TeX with PostScript \specials pstricks LaTeX picture environment with PSTricks macros qms QMS/QUIC Laser printer (also Talaris 1200 and others) svg W3C Scalable Vector Graphics tek40xx Tektronix 4010 and others; most TEK emulators tek410x Tektronix 4106, 4107, 4109 and 420X terminals texdraw LaTeX texdraw environment tgif TGIF X11 [mode] [x,y] [dashed] ["font" [fontsize]] tikz TeX TikZ graphics macros via the lua script driver tkcanvas Tk/Tcl canvas widget [perltk] [interactive] tpic TPIC -- LaTeX picture environment with tpic \specials unknown Unknown terminal type - not a plotting device vttek VT-like tek40xx terminal emulator xterm Xterm Tektronix 4014 Mode 打开文件。