> The first one does weird stuff
Looks like -i only works with '<>', not with '<FILE>' (though I could
not find that documented).
> Can you tell me how to change the first one to make it work?
If you really need to do that, try 'open(STDIN,$filetobechanged)'
instead. Then, 'while(<>)' instead of 'while(<FILE>)' and 'print'
instead of 'print FILE'.
Side notes: always use strict :-)
Oh, and if you're just trying to remove \n's, try chomp instead of that
substitution :-) much, much faster :-)
And there are even easier ways, like this one :-)
#!/usr/bin/perl -wl0pi
Right, no code needed :-) The switches do it all :-) Give it a try :-)
HTH
jac
On Mon, 2004-05-10 at 05:22, Timothy Duke wrote:
> Hi,
>
> I have got two versions of a script to eliminate single line-feeds from
> a file. The first one does weird stuff - duplicating lines and messing
> the text file up. The second one works (I copied it from a Perl guide),
> but I don't understand why. I would much prefer the first one to work -
> Can you tell me how to change the first one to make it work?
>
> Also, I understand that the <> operator reads in one line at a time. If
> I wish to eliminate only triple line-feeds (\n\n\n) and leave double and
> single linefeeds, I presume <> won't work. Without reading in the whole
> file at once, how can I achieve this?
>
> I am using MacPerl.
>
> Thanks for any help!
>
> Tim
>
> ----------------------------------------------------
>
> Version #1 (works dreadfully....stuffs up the file)
>
> #! perl -w -i
> $filetobechanged = "iBook HD:Desktop Folder:tim.txt";
> open(FILE, "+< $filetobechanged") ;
> while (<FILE>) {
> s/\n//g;
> print FILE ;
> }
> close(FILE);
>
>
> Version #2 (works fine)
> $filetobechanged = "iBook HD:Desktop Folder:tim.txt";
> @ARGV = ($filetobechanged);
> $^I = ".bak";
> while (<>) {
> s/\n//g;;
> print;
> }
--
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>