-
Notifications
You must be signed in to change notification settings - Fork 5
/
print-emojiSentences.pl
67 lines (50 loc) · 1.47 KB
/
print-emojiSentences.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env perl
# default: printing sentences that contain emoji character
# with "r" option for printing sentences that do not contain emoji character
# with "c" option for cleaning emoji character
#
# Ye Kyaw Thu, NICT, Kyoto, Japan
#
# last updated: 25 April 2015
# usage: perl print-emojiSentences.pl <input-file> [options]
# e.g. perl ./print-emojiSentences.pl ./tst-emoji
# e.g. perl ./print-emojiSentences.pl ./tst-emoji c
# e.g. perl ./print-emojiSentences.pl ./tst-emoji r
use strict;
use warnings;
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
open (my $inputFILE,"<:encoding(utf8)", $ARGV[0]) or die "Couldn't open input file $ARGV[0]!, $!\n";
if (! defined $ARGV[1]){
while (!eof($inputFILE)) {
my $line = <$inputFILE>;
if (($line ne '') & ($line !~ /^ *$/) & ($line =~ /(\p{Emoticons})/g)) {
chomp($line);
print "$line\n";
}
}
}
elsif ($ARGV[1] eq "r"){
while (!eof($inputFILE)) {
my $line = <$inputFILE>;
if (($line ne '') & ($line !~ /^ *$/) & ($line !~ /(\p{Emoticons})/g)) {
chomp($line);
print "$line\n";
}
}
}
elsif ($ARGV[1] eq "c"){
while (!eof($inputFILE)) {
my $line = <$inputFILE>;
if (($line ne '') & ($line !~ /^ *$/)) {
chomp($line);
$line =~ s/(\p{Emoticons})//g;
if ($line ne ''){
print "$line\n";
}
}
}
}
close ($inputFILE);