We Recommend

Learning Perl Learning Perl
In this smooth, carefully paced course, a leading Perl trainer teaches you to program in the language that threatens to make C, sed, awk, and the Unix shell obsolete for many tasks. This book is the "official" guide for both formal (classroom) and informal learning. It is fully accessible to the novice programmer.


Posted By

iblis on 08/05/07


Tagged

osx rpc snipperl smultron


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

mabridge
schoobidoo
stavelin
sidisinsane


Post a snippet (add-on for Smultron)


Published in: Perl 


  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Frontier::Client;
  4. #
  5. # Post a snippet (add-on for Smultron)
  6. # perl smultron snipperl rpc
  7. #
  8. # (paste the script as a New Command in Tools menu, for example: Post it)
  9. # (then select lines of code and run the script, Tools -> Commands -> Post it)
  10. #
  11. # post title grabbed from first non-empty comment, if any
  12. # tags grabbed from second non-empty comment, if any
  13. # language set to first tag, if many of them, else set to bash
  14. #
  15. my $key = ''; # (your API key)
  16.  
  17. my $tempfile = '%%s';
  18. die "Please select some text\n" if ($tempfile =~ /^\%\%s$/);
  19.  
  20. open(FC, "<:utf8", $tempfile);
  21. my $title='no title yet';
  22. my $code = '';
  23. my $tags = '';
  24. my $language = 'bash';
  25. my $flag = 0;
  26. while (<FC>) {
  27. if (/^\#[^!]\s*(.+)/ && $flag == 0) {
  28. $title = $1;
  29. $flag++;
  30. }
  31. elsif (/^\#[^!]\s*(.+)/ && $flag == 1) {
  32. $tags = $1;
  33. $flag++;
  34. if (/(\w+) (.+)/) {
  35. $language = $1;
  36. $tags = $2;
  37. }
  38. }
  39. $code = $code . $_;
  40. }
  41.  
  42. my $session = Frontier::Client->new( url => 'http://snipplr.com/xml-rpc.php', debug => 0,);
  43. my @args = ($key, $title, $code, $tags, $language);
  44. my $result = $session->call('snippet.post', @args);

Report this snippet 

You need to login to post a comment.