Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i have a form in which a user can enter their URL, to be attached to their name, and posted on a bulletin, not unlike this one. In other words, the html to printed would look like this: <a href="http://www.somedomain.com">User Name </a>>

And here's what I want it to do:

If they enter their URL as http://www.somedomain.com it simply writes it to the file.

If they enter www.somedomain.com, without the http://, it will add http:// to their URL when printing to the file.

Else, if they enter nothing, it will just print their name.

Thanks in advance.

Gino
gino@smallpondstudios.com

Replies are listed 'Best First'.
Re: easy question for perl novice
by btrott (Parson) on Mar 22, 2000 at 03:13 UTC
    use CGI; my $query = new CGI; my $url = $query->param('url'); my $name = $query->param('name'); $url = "http://" . $url if $url && $url !~ m#^http://#i; open FILE, ">foo" or die "Can't open foo: $!"; print FILE $url ? "<a href=$url>$name</a>" : $name; close FILE or die "Can't close foo: $!";