Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!apple!fernwood!uupsi!sunic!news.funet.fi!funic!santra!blob.hut.fi!gson From: gson@blob.hut.fi (Andreas Gustafsson) Newsgroups: comp.lang.perl Subject: Problem with -i option and <> in array context Message-ID: <1991May11.091442.11389@santra.uucp> Date: 11 May 91 09:14:42 GMT Sender: news@santra.uucp (Cnews - USENET news system) Reply-To: gson@niksula.hut.fi (Andreas Gustafsson) Organization: Helsinki University of Technology, Finland Lines: 37 I am trying to munge some mailbox files in-place by using Perl with the -i option. The file is accessed in a somewhat random fashion, so I want to read the whole file into an array using @array=<>. It turns out that this doesn't work very well with the -i option. Consider the following program: #!/p/bin/perl -i.bak @lines=<>; for(@lines) { s/^/X /; } $;="\n"; print @lines; When running the above program with a text file "foo" as an argument, it correctly prepends "X " to each line in the file but instead of modifying the file in-place it prints the modified file on standard output, leaving an em does work as expected: The following program, which does not use <> in an array context, #!/p/bin/perl -i.bak while(<>) { s/^/X /; print; } Versions 3.0pl37 and 4.003 both behave this way. The man page says that with -i, "files processed by the <> construct are to be edited in-place", not "files processed by the _scalar_ <> construct ...". Is this a bug in Perl, a bug in the man page, or am I just doing something wrong? perl -i -e '@_=<>; print "Just another Perl hacker,\n";' /dev/null -- Andreas Gustafsson Internet: gson@niksula.hut.fi Voice: +358 0 563 5592