Array
#! / usr / bin / perl
my $ str = "hello, nihao, no, o, good";
my @arr = split (/, /, $ str);
print "len:". @arr. "\ n";
for (my $ i = 0; $ i <@arr; $ i ++)
{# Brackets must have
print @arr [$ i]. "\ n";
}
#! / usr / bin / perl
@ ifs = qw (eth1 eth2.45 eth3);
$ it = grep / eth2 $ /, @ifs;
if ($ it == 0) {
print "NO \ n";
}
else {
print "YES \ n";
}
2. Coding
Reference: http://bbs.chinaunix.net/thread-1751048-1-1.html
Perl's utf8 and encoding processing
This article is based on the perldoc and test results that the author consulted. In view of the fact that some people are often troubled by coding problems, I now summarize what I know about Perl utf8 and coding processing. Due to the limited knowledge, there may be some mistakes. If necessary, you can refer to:
perldoc Encode
perldoc PerlIO
perldoc utf8
perldoc encoding
The following functions are used to provide useful help:
Encode :: is_utf8 ($ str) # When the string utf8 flag is on, return true, otherwise return false
utf8 :: is_utf8 ($ str) # Same as above
Encode :: _ utf8_on ($ str) # Manually set the utf8 flag to on
Encode :: _ utf8_off ($ str) # Manually set the utf8 flag to off
PerlIO :: get_layers (FP) # get handle layers
3. my $ len = length ($ taginfo);
4. if ($ catname ne $ tagname)
http://www.cbi.pku.edu.cn/chinese/documents/perl/perl3.htm# Fourth, logical operators
my $ a = 4;
if ($ a == 4)
{
print "a == 4 \ n";
}
if ($ a! = 3)
{
print "a! = 3 \ n";
}
5. Open (GO, ">> text.txt") uses append, don't use>,> will clear the original file, and write from it, >> is append
open (MYFILE, "> info");
foreach my $ key (keys% newinfo)
{
my $ value = $ newinfo {$ key}; #index
my $ tagids = "";
if (exists ($ newinfo_tagid {$ key}))
{
$ tagids = $ newinfo_tagid {$ key};
}
print MYFILE $ value. "_". $ cat. "\ t $ key \ t $ addtag, $ tagids \ n";
}
close (MYFILE);
6. my @arrs = split (/ \ | /, $ key);
Dictionary array length
#The length of the array can be used
$ i = @arr; # $ i to get the length of the array
Or directly use scalar (@arr) to get the length of the array
$ # typeArr can return the index of the last element of the typeArr array, which is 1 less than scalar (@arr)
scalar (keys% hash)
perl study notes