+
+sub Counter($){
+ my $o = $/; undef $/;
+ open COUNTER, "+<$_[0]";
+ flock COUNTER, 2;
+ seek COUNTER, 0, 0;
+ my $counter = <COUNTER>;
+ seek COUNTER, 0, 0;
+ truncate COUNTER, 0;
+ print COUNTER ++$counter;
+ close COUNTER;
+ $/ = $o;
+ return $counter;
+}
+
+sub AutoURL($){
+ # This sub assumes your string does not match /(["<>])\cC\1/
+ my $ref;
+ if (defined wantarray){
+ $ref = \(my $copy = $_[0]);
+ }else{
+ $ref = \$_[0];
+ }
+ eval {
+ $$ref =~ s/"/"\cC"/g; # Single characters are easier to match :)
+ $$ref =~ s/>/>\cC>/g; # so we can just use a character class []
+ $$ref =~ s/</<\cC</g;
+
+ # Now this is a big, ugly regex! But hey - it works :)
+ $$ref =~ s{((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)}{
+ local $_ = $1;
+ my $scheme = $2;
+ s/// if (my $trailing) = /([\.,!\?\(\)\[\]]+$)/;
+ s/&(?!\x23?\w+;)/&/g;
+ s/\"/"/g;
+ my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
+ qq{<a href="$href" target="_blank">$_</a>$trailing};
+ }eg;
+
+ $$ref =~ s/"\cC"/"/g;
+ $$ref =~ s/>\cC>/>/g;
+ $$ref =~ s/<\cC</</g;
+ };
+ if ($@){ return defined wantarray ? @_ : undef }
+ return defined wantarray ? $$ref : undef;
+}