<commit_before>---
layout: article
title: "Perl"
categories: clients
tags: [clients]
show_related: true
image:
    teaser: /language_logos/perl.svg
---

The Perl client is still in development.  For now, you can do a raw POST inside your Perl code to call any algorithm:

#### Calling an algorithm in Perl

{% highlight perl %}
  
use LWP::UserAgent;

# get your API Key at http://algorithmia.com/user#credentials
my $api_key = 'YOUR_API_KEY';

# pick an algorithm at http://algorithmia.com/algorithms/ (and append a version number)
my $algo = 'util/Echo/0.2.1';
 
# most algorithms accept JSON Objects
my $post_data = '{ "hello": "world" }';

# prepare POST to algorithm endpoint
my $req = HTTP::Request->new(POST => 'http://api.algorithmia.com/v1/algo/' . $algo);
$req->header('content-type' => 'application/json');
$req->header('Authorization' => 'Simple ' . $api_key);
 
# run the algorithm and get the results (usually a JSON-encoded string)
$req->content($post_data);
my $ua = LWP::UserAgent->new;
my $resp = $ua->request($req);

# if the POST succeeds, the returned $message will usually contain JSON
# with either a 'response' field or an 'error' feild
# consider using JSON::Parse to decode: search.cpan.org/perldoc?JSON::Parse
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "$message";
}
else {
    print 'POST error: ', $resp->code, ': ', $resp->message;
}
{% endhighlight %}

#### Additional information

While most algorithms accept JSON Objects, you can also use `Content-Type: text/plain` for ones which require bare string input, or `Content-Type: application/octet-stream` for those that require a binary (such as an image file). Adjust the line beginning with `my $post_data` as needed.

See the full [cURL Client Guide]({{ site.baseurl }}/clients/curl) and [API Specification](http://docs.algorithmia.com/#api-specification) for additional details
on calling algorithms and managing data with POSTs.<commit_msg>Perl psuedo-client-guide (instructions on using raw POST inside Perl)<commit_after>---
layout: article
title: "Perl"
categories: clients
tags: [clients]
show_related: true
image:
    teaser: /language_logos/perl.svg
---

The Perl client is still in development.  For now, you can do a raw POST inside your Perl code to call any algorithm:

#### Calling an algorithm in Perl

{% highlight perl %}
  
use LWP::UserAgent;

# get your API Key at http://algorithmia.com/user#credentials
my $api_key = 'YOUR_API_KEY';

# pick an algorithm at http://algorithmia.com/algorithms/ (and append a version number)
my $algo = 'util/Echo/0.2.1';

# most algorithms accept JSON Objects
my $post_data = '{ "hello": "world" }';

# prepare POST to algorithm endpoint
my $req = HTTP::Request->new(POST => 'http://api.algorithmia.com/v1/algo/'.$algo);
$req->header('content-type' => 'application/json');
$req->header('Authorization' => 'Simple '.$api_key);

# run the algorithm and get the results (usually a JSON-encoded string)
$req->content($post_data);
my $ua = LWP::UserAgent->new;
my $resp = $ua->request($req);

# if the POST succeeds, the returned $resp->decoded_content will usually
# contain JSON with either a 'response' field or an 'error' field
# consider using JSON::Parse to decode: http://search.cpan.org/perldoc?JSON::Parse
if ($resp->is_success) {
    print $resp->decoded_content;
} else {
    print 'POST error: ', $resp->code, ': ', $resp->message;
}
{% endhighlight %}

#### Additional information

While most algorithms accept JSON Objects, you can also use `Content-Type: text/plain` for ones which require bare string input, or `Content-Type: application/octet-stream` for those that require a binary (such as an image file). Adjust the line beginning with `my $post_data` as needed.

See the full [cURL Client Guide]({{ site.baseurl }}/clients/curl) and [API Specification](http://docs.algorithmia.com/#api-specification) for additional details
on calling algorithms and managing data with POSTs.
{'fraction_non_alphanumeric': 0.13405705629891443, 'fraction_numerical': 0.002019691996970462, 'mean_word_length': 4.643874643874644, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5965284', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1203, 'n_words': 435}