
mk_bold
Novice
Feb 13, 2014, 4:42 AM
Post #1 of 3
(3342 views)
|
Padre Perl printing/software problem
|
Can't Post
|
|
This is not as much a perl question as a Padre question. So I am not sure I put it the correct place. I am working on a Oauth script in Padre perl (1.00) and having trouble printing the output out to see if it works. This do not give any output:
# Get tokens my $tokenString = get_token(); # Split get_token response into a hash. my %words = split /[=&]/, $tokenString; # Define the tokens: my $oauth_token = $words{oauth_token}; my $oauth_token_secret = $words{oauth_token_secret}; # Test if it works print "Oauth: $oauth_token\nOauth secret: $oauth_token_secret"; But if I take the exact same code, but add a few newlines before print. It works:
# Get tokens my $tokenString = get_token(); # Split get_token response into a hash. my %words = split /[=&]/, $tokenString; # Define the tokens: my $oauth_token = $words{oauth_token}; my $oauth_token_secret = $words{oauth_token_secret}; # Test if it works print "Oauth: $oauth_token\nOauth secret: $oauth_token_secret"; Why on earth is that?! Is it just a very weird bug or am I missing something here? The full code below (modified version of an example found online):
#!/usr/bin/perl -w # Hattrick Oauth: use strict; use diagnostics; use strict; use lib 'extra_mods'; use lib 'extra_mods/5.8'; use JSON; use Net::OAuth; use LWP::UserAgent; use Data::Dumper; $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; # PROVIDE YOUR KEY HERE my $cc_key = "blalbalblablab"; # PROVIDE YOUR SECRET HERE my $cc_secret = "lalalallalallaalallaa"; # Get tokens my $tokenString = get_token(); # Split get_token response into a hash. my %words = split /[=&]/, $tokenString; # Define the tokens: my $oauth_token = $words{oauth_token}; my $oauth_token_secret = $words{oauth_token_secret}; # Test if it works print "Oauth: $oauth_token\nOauth secret: $oauth_token_secret"; # Get token sub: sub get_token { my $ua = LWP::UserAgent->new; # Source Url my $url = "https://chpp.hattrick.org/oauth/request_token.ashx"; # Create request my $request = Net::OAuth->request("request token")->new( consumer_key => $cc_key, consumer_secret => $cc_secret, request_url => $url, request_method => 'GET', signature_method => 'HMAC-SHA1', timestamp => time, nonce => 'hsu94j3884jdopsl', callback => ' https://chpp.hattrick.org/oauth/request_token.ashx', ); # Sign request $request->sign; # Get message to the Service Provider my $res = $ua->get( $request->to_url ); # If request is success, display content if ( $res->is_success ) { return $res->content; } else { # Print error and die Dumper $res; die "Something went wrong"; } }
|