use Flickr::API; use XML::Parser::Lite::Tree::XPath; use warnings; use strict; my $theuser = shift; sub finduser { my $fuser = shift; my ($xpath, @username, $userid); if ($fuser =~ m!http://!i) { $response = $api->execute_method ('flickr.urls.lookupUser', { 'url' => $fuser, }); $xpath = new XML::Parser::Lite::Tree::XPath($response->{tree}); @username = $xpath->select_nodes('/user'); $userid = $username[0]->{attributes}->{id}; } else { $response = $api->execute_method ('flickr.people.findByUsername', { 'username' => $fuser, }); $xpath = new XML::Parser::Lite::Tree::XPath($response->{tree}); @username = $xpath->select_nodes('/user'); $userid = $username[0]->{attributes}->{nsid}; } return $userid; } print finduser ($theuser);