:
는 내가 뭘 바라고하는 주식의 수를 인쇄했다. 방금 주석 달기로 다시 작성했습니다.
#!/usr/bin/perl
use LWP::Simple; # From CPAN
use JSON qw(decode_json); # From CPAN
use Data::Dumper; # Perl core module
use strict; # Good practice
use warnings; # Good practice
my $trendsurl = "https://graph.facebook.com/?ids=http://www.filestube.com";
# open is for files. unless you have a file called
# 'https://graph.facebook.com/?ids=http://www.filestube.com' in your
# local filesystem, this won't work.
#{
# local $/; #enable slurp
# open my $fh, "<", $trendsurl;
# $json = <$fh>;
#}
# 'get' is exported by LWP::Simple; install LWP from CPAN unless you have it.
# You need it or something similar (HTTP::Tiny, maybe?) to get web pages.
my $json = get($trendsurl);
die "Could not get $trendsurl!" unless defined $json;
# This next line isn't Perl. don't know what you're going for.
#my $decoded_json = @{decode_json{shares}};
# Decode the entire JSON
my $decoded_json = decode_json($json);
# you'll get this (it'll print out); comment this when done.
print Dumper $decoded_json;
# Access the shares like this:
print "Shares: ",
$decoded_json->{'http://www.filestube.com'}{'shares'},
"\n";
실행하여 출력을 확인하십시오. 진행 상황을 이해하면 print Dumper $decoded_json;
행을 주석으로 처리 할 수 있습니다.
대 한 respon se. 필자는 15 년 동안 많은 펄 코드를 작성하지 않았기 때문에 철저한 예제를 통해 펄의 속도를 높일 수있었습니다. – fool4jesus