- or download this
while (<>) {
@words = split /\W+/;
$words += @words;
}
print "lines -> $.\nwords -> $words\n";
- or download this
-e commandline
may be used to enter one line of program.
- or download this
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
- or download this
-n causes Perl to assume the following loop around
your program [...]
...
while (<>) {
... # your program goes here
}
- or download this
LINE:
while (<>) {
$w += split /\W+/;
END { print"$w $.\n" }
}
- or download this
#!/usr/bin/perl -n
# counts words and lines in a file
...
@words = split /\W+/;
$words = @words;
END { print "lines -> $.\nwords -> $words\n"; }
- or download this
#!/usr/bin/perl -w
use strict;
- or download this
my $line;
while (<>) {
...
}
print;
}
- or download this
#!/usr/bin/perl -wp
use strict;
#Adding a commit each 100 lines
unless ( $. % 100 ) { print "commit;\n"; }
- or download this
-p causes Perl to assume the following loop around
your program [...]
...
} continue {
print or die "-p destination: $!\n";
}
- or download this
-i[extension]
specifies that files processed by the "<>"
construct are to be edited in-place. It does
this by renaming the input file, opening [...]
- or download this
#!/usr/bin/perl -wlp
use strict;
# trims lines to 80 columns
substr($_, 80) = "";
- or download this
-l[octnum]
enables automatic line-ending processing.
- or download this
#!/usr/bin/perl -wp
use strict;
...
$\ = $/;
substr($_, 80) = ""
- or download this
#!/usr/bin/perl -wpi
use strict;
...
chomp;
print "$_\n";
}
- or download this
-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
...
@F = split(' ');
print pop(@F), "\n";
}
- or download this
@F The array @F contains the fields of each
line read in when autosplit mode is turned
on. [...]
- or download this
#!/usr/bin/perl -wane
use strict
...
print "$_ -> $commands{$_}\n"
}
}
- or download this
#!/usr/bin/perl -w
use strict;
my @a = (1, 2, 3, 4, 5);
print "@a";
- or download this
#!/usr/bin/perl -w
use strict;
...
$" = "|";
print "@a";
- or download this
#!/usr/bin/perl -w
use strict;
my @a = (1, 2, 3, 4, 5);
print @a;
- or download this
#!/usr/bin/perl -w
use strict;
...
$, = "-";
print @a;
- or download this
perl -MExtUtils::Installed -le '
print for ExtUtils::Installed->new()->modules'
- or download this
perl - le 'use ExtUtils::Installed;
print for ExtUtils::Installed->new()->modules'