The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl -I../lib

# To use:
# - Log into your myspace account and find/create a group.
# - Note the group ID (in the URL after "groupID=")
# - To send to all your friends: send_group_invitations groupID
# This script will cache your friend list - delete the cache file if you
# use a different account or want it to re-read the list.
# Note that you can also fill the cache file with a list of
# friendIDs.

# usage: send_group_invitations group_id [ friend_id ... ]

use WWW::Myspace;
use YAML qw'DumpFile LoadFile';

my $myspace = new WWW::Myspace( human => 0 );
die $myspace->error if $myspace->error;

my ( $group_id, @friends ) = @ARGV;

unless ( @friends ) {
	warn "Getting all friends\n";
	if ( -f './invite_friends_cache.yaml' ) {
		warn "Reading from cache file.  Delete group_invite_cache.yaml\n".
			  "if you don't want to do this.\n";
		@friends = LoadFile( 'group_invite_cache.yaml' );
	} else {
		@friends = $myspace->get_friends;
		DumpFile( 'group_invite_cache.yaml', @friends );
	}
}

warn "Inviting " . @friends . " friends.\n";

my ( $passed, $failed ) =
    $myspace->send_group_invitation( $group_id, @friends );
die $myspace->error if $myspace->error;

print "\n\nSent to:\n";
foreach $id ( @{ $passed } ) {
    print $id . "\n";
}

print "Failed to send to:\n";
 foreach $id ( @{ $failed } ) {
    print $id . "\n";
}