in reply to Bash for loop variable pass equivalent in perl

In addition to the previous comments, using for var in `cat file` is usually wrong. The file will not only be split by newlines, but by other symbols (defined in shell variable IFS; spaces, newlines and tabs by default) too. If you need similar behaviour, you need perl -lpe 'join "\n",split/[\t ]/' file.
EDIT: fixed code
Sorry if my advice was wrong.

Replies are listed 'Best First'.
Re^2: Bash for loop variable pass equivalent in perl
by aaron_baugher (Curate) on Aug 10, 2012 at 18:06 UTC

    And to get perl's default line-by-line behavior in the shell, set IFS to a newline (The ctrl-V ctrl-J sequence inserts a raw newline into the command without ending it):

    $ IFS="^V^J "; for i in `cat file`; do echo aaa $i; done

    Aaron B.
    Available for small or large Perl jobs; see my home node.