- # 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;
+ # This sub assumes your string does not match /(["<>])\cC\1/
+ my $ref = defined wantarray ? \(my $copy = $_[0]) : \$_[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 original on error
+ return defined wantarray ? $$ref : undef;