NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Everything Else » perl script for generating code blocks in NK forums

December 10, 2009
by pbfy0
pbfy0's Avatar

here it is, it takes from clipboard if you don't give it an argument, otherwise, it takes from the file you give it as an arg:

#!/usr/bin/perl
use Clipboard;
if(scalar(@ARGV) != 0){
    open IN, ("<$ARGV[0]");# print "\n\n"; # debug

    my $out = "\n\n";

    while(<IN>){
        $out .= "    " . $_;
        # print "    $_"; # debug
    }   
    Clipboard ->copy($out);
}else{
    my $in = Clipboard ->paste;
    my @ins = split(/\n/, $in);
    # print "\n\n"; # debug

    my $out = "\n\n";

    foreach(@ins){      
        $out .= "    " . $_ . "\n";
        # print "    $_"; # debug
    }
    Clipboard ->copy($out);
}

but if you don't want to install the Clipboard module (a PAIN, but worth it I say), here's a simpler version, just takes a file and outputs it with 4 spaces:

#!/usr/bin/perl
open IN, ("<$ARGV[0]");# print "\n\n"; # debug

print "\n\n";

while(<IN>){
    print "    $_";
}

Just something I thought might help

-Paul

P.S. I put those programs on here with themselves! -- :)

December 10, 2009
by Rick_S
Rick_S's Avatar

I know the NK guys are trying to keep the forum overhead light but a stronger suite of forum software would be nice. Editing features, simple [code][/code] [quote][/quote] escape sequences come in very handy and would eliminate the need for all the spaces.

Good idea with the scripts though. I know for the code snippets I posted for my marquee, it took me a couple trys to get it all looking right.

Rick

December 11, 2009
by FWSquatch
FWSquatch's Avatar

I couldn't agree more. I'd like to have a few more features on the forum as well. I think a "posts since last visit" feature could come in real handy.

Pbfy0- Great idea on the Perl script. It can get tedious adding in spaces.

Post a Reply

Please log in to post a reply.

Did you know that a piezoelectric buzzer can be used in reverse as a microphone? Learn more...