Personally, I think the thing that attracts me to Perl is that you can easily write a filter program using while (<>)
.
#!/usr/bin/perl
while (<>) {
y/a-z/A-Z/;
print;
}
This completes the filter program for uppercase lowercase letters. You can specify as many files as you like with arguments, and if there are no arguments, read from standard input.
$ echo hoge | ./toupper.pl
HOGE
$ ./toupper.pl hoge.txt hoge2.txt
HOGE
HOGE2
$
You can do the same in Python with the fileinput module.
#!/usr/bin/python
import fileinput
for line in fileinput.input():
print line.upper(),
If you specify "-" as the file name, it will be the same as the standard input.
See also: https://docs.python.org/2/library/fileinput.html
Recommended Posts