小编kri*_*tin的帖子

使用Perl进行简单的JSON解析

我正在尝试解析Facebook Graph API JSON结果,我遇到了一些麻烦.

我希望做的是打印股票数量:

my $trendsurl = "https://graph.facebook.com/?ids=http://www.filestube.com";
my $json;
{
  local $/; #enable slurp
  open my $fh, "<", $trendsurl;
  $json = <$fh>;
}

my $decoded_json = @{decode_json{shares}};
print $decoded_json;
Run Code Online (Sandbox Code Playgroud)

perl json

35
推荐指数
1
解决办法
8万
查看次数

使用perl比较文件中的行

我一直在尝试比较两个文件之间的行和匹配相同的行.

由于某种原因,下面的代码只会经过'text1.txt'的第一行并打印'if'语句,无论这两个变量是否匹配.

谢谢

use strict;
open( <FILE1>, "<text1.txt" );
open( <FILE2>, "<text2.txt" );
foreach my $first_file (<FILE1>) {
    foreach my $second_file (<FILE2>) {
        if ( $second_file == $first_file ) {
            print "Got a match - $second_file + $first_file";
        }
    }
}
close(FILE1);
close(FILE2);
Run Code Online (Sandbox Code Playgroud)

perl file match

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

perl ×2

file ×1

json ×1

match ×1