while (<>) { @words = split /\W+/; $words += @words; } print "lines -> $.\nwords -> $words\n"; #### -e commandline may be used to enter one line of program. #### As with all standard commands, a single-character switch may be clustered with the following switch, if any. #!/usr/bin/perl -spi.orig # same as -s -p -i.orig #### -n causes Perl to assume the following loop around your program [...] LINE: while (<>) { ... # your program goes here } #### LINE: while (<>) { $w += split /\W+/; END { print"$w $.\n" } } #### #!/usr/bin/perl -n # counts words and lines in a file @words = split /\W+/; $words = @words; END { print "lines -> $.\nwords -> $words\n"; } #### #!/usr/bin/perl -w use strict; #### my $line; while (<>) { $line++; unless ( $line % 100 ) { print "commit;\n"; } print; } #### #!/usr/bin/perl -wp use strict; #Adding a commit each 100 lines unless ( $. % 100 ) { print "commit;\n"; } #### -p causes Perl to assume the following loop around your program [...] LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; } #### -i[extension] specifies that files processed by the "<>" construct are to be edited in-place. It does this by renaming the input file, opening [...] #### #!/usr/bin/perl -wlp use strict; # trims lines to 80 columns substr($_, 80) = ""; #### -l[octnum] enables automatic line-ending processing. #### #!/usr/bin/perl -wp use strict; # trims lines to 80 columns chomp; $\ = $/; substr($_, 80) = "" #### #!/usr/bin/perl -wpi use strict; $/ = ""; while(<>) { chomp; print "$_\n"; } #### -a turns on autosplit mode when used with a -n or -p. An implicit split command to the @F array is done as the first thing inside the implicit while loop produced by the -n or -p. perl -ane 'print pop(@F), "\n";' is equivalent to while (<>) { @F = split(' '); print pop(@F), "\n"; } #### @F The array @F contains the fields of each line read in when autosplit mode is turned on. [...] #### #!/usr/bin/perl -wane use strict # study commands (input is .bash_history) $commands{shift(@F)}++; END { for (keys %commands) { print "$_ -> $commands{$_}\n" } } #### #!/usr/bin/perl -w use strict; my @a = (1, 2, 3, 4, 5); print "@a"; #### #!/usr/bin/perl -w use strict; my @a = (1, 2, 3, 4, 5); $" = "|"; print "@a"; #### #!/usr/bin/perl -w use strict; my @a = (1, 2, 3, 4, 5); print @a; #### #!/usr/bin/perl -w use strict; my @a = (1, 2, 3, 4, 5); $, = "-"; print @a; #### perl -MExtUtils::Installed -le ' print for ExtUtils::Installed->new()->modules' #### perl - le 'use ExtUtils::Installed; print for ExtUtils::Installed->new()->modules'