Thursday, June 24, 2010

Post highlight code in blog using vim

I want to post code in my blogger,as well as vim have a feature that convert it's content to html ,so I use vim's TOhtml command convert a perl code and clip it to blogger it workwell?

1 #!/usr/bin/env perl
2 use Net::Ping;
3 use Data::Dumper;
4 use Thread;
5 use Thread::Queue;
6 #use strict;
7 use warnings;
8 $q=Thread::Queue->new();
9 $hosts=Thread::Queue->new();
10 sub now{
11 ($sec,$min,$hour,$day,$mon,$year,$weekday,$yeardate,$savinglightday)=(localtime(time));
12 $sec = ($sec < 10)? "0$sec":$sec;
13 $min = ($min < 10)? "0$min":$min;
14 $hour = ($hour < 10)? "0$hour":$hour;
15 $day = ($day < 10)? "0$day":$day;
16 $mon = ($mon < 9)? "0".($mon+1):($mon+1);
17 $year += 1900;
18 $now = "$year-$mon-$day $hour:$min:$sec";
19 }
20
21 sub ping_host{
22 my ($name)=@_;
23 my $pinger=Net::Ping->new("icmp");
24 while(defined(my $ip=$q->dequeue_nb())){
25 if ($pinger->ping($ip)){
26 my $curtime=&now;
27 print "$curtime $name: ping $ip success","\n";
28 $hosts->enqueue($ip);
29 }
30 }
31 $pinger->close()
32 }
33
34 for my $hostid(1..255){
35 my $ip2="192.168.1.$hostid";
36 $q->enqueue($ip2);
37 }
38 my @thread=();
39 for(my $i=0;$i<50;$i++){
40 my $t=Thread->new(\&ping_host,"Thread $i");
41 push(@thread,$t);
42 }
43 for(@thread) {
44 $_->join()
45 }
46 #print Dumper($hosts)
47

No comments:

Post a Comment