php -R '$count++' -E 'print "$count\n";' < somefile
will print the number of lines in ‘somefile’ (not that I would actually do this).
I’m looking to emulate the -E switch in a perl command.
perl -ne '$count++' -???? 'print "$count\n"' somefile
Is it possible?
You can use an
END { ... }block to add code that should be executed after the loop:You can also easily put it in its own
-eargument, if you want it more separated:See also:
perlmod–BEGIN,UNITCHECK,CHECK,INITandENDat perldoc.perl.org.