Saturday, May 31, 2008

tweet.pl and stweet.pl

Although not my creations really, these two scripts using Net::Twitter are immensely useful for my Twitter account.

tweet.pl

#!/usr/bin/perl -w
use strict;
use warnings;
use utf8;
use Net::Twitter;


scalar @ARGV >= 2 || die "Usage: $0 username:password message\n";
my ($username, $password) = split(/:/, shift @ARGV);

my $twit = Net::Twitter->new(username => $username, password => $password);
my $result = $twit->update(shift @ARGV);

This one reads from stdin:

stweet.pl

#!/usr/bin/perl -w
use strict;
use warnings;
use utf8;
use Net::Twitter;


scalar @ARGV >= 2 || die "Usage: $0 username password\n";
my ($username, $password) = @ARGV;

my $status = '';
($status .= $_ ) while(<STDIN>);
chomp($status);

my $twit = Net::Twitter->new(username => $username, password => $password);
my $result = $twit->update($status);

No comments: