in reply to -i switch behaviour

You seem to be confusing the list of files with the filecontents.

-i replaces the files given as @ARGV inplace, and <> is an iterator over the contents of each of these files. If @ARGV is empty, STDIN is used to supply the contents, not to supply the list of filename(s). So your -e code is applied to the list of files itself, not to the contents of these files. And it can't then use the result to do an update, since there actually is no file that that the list is the contest of.

That's of course the case in general. There is no reason to think STDIN is associated with a file (in your case it's a pipe), so a rewrite of that "file" makes no sense. And that's also what makes xargs so nice. It allows you to convert an inputstream to a list of arguments.

Replies are listed 'Best First'.
Re^2: -i switch behaviour
by fireartist (Chaplain) on Jun 18, 2004 at 14:01 UTC
    Yeah, I know I'm confused!
    If @ARGV is empty, STDIN is used to supply the contents, not to supply the list of filename(s)
    That's a good explanation!
    I think where I went wrong was initially experimenting with the -n and -p switches in the form
    find ... | perl -ne 'do something'
    and then when I added -i I though it would automatically edit the files the same way
    find ... | perl -nie 'do something'
    and I didn't know why I was having to use
    find ... | xargs perl -nie 'do something'
    to get my desired results.
    Thanks for your help.