Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

perl -ni.bak -e 's/\s+//g;' names
why doesn't this change/modify the file names? when I use the -p switch instead of -n it shows up fine but when I cat names nothing :(

Replies are listed 'Best First'.
Re: perl on the commandline
by blakem (Monsignor) on Aug 21, 2001 at 23:02 UTC
    Have you read about the difference between -n and -p at perlrun? If you're still confused after reading the explanation there, come back and I'll walk you through it.

    -Blake

Re: perl on the commandline
by Cine (Friar) on Aug 21, 2001 at 23:11 UTC
    The -p prints $_ after each line, while -n do not. So the two versions are almost the same (they will do the same):
    perl -i.bak -ne 's/\s+//g;print' names perl -i.bak -pe 's/\s+//g;' names


    T I M T O W T D I
      the file doesnt get modified. I want perl to strip the white space from the file but it doesn't do it. beware im am in windows terminal

        You are using single quotes, under windows you have to type the following: perl -pi.bak -e "s/\s+//g" names

        -- Hofmator