beppu has asked for the wisdom of the Perl Monks concerning the following question:
Running this script will yield this error:#!/usr/bin/perl -w use strict; use warnings; use HTML::Entities; sub sanitize { # no name? $_[0] ||= "anonymous"; # add missing protocol in $url if ($_[1] && $_[1] !~ /^\w+:/) { $_[1] = "http://" . $_[1] } # add missing protocol in link in $body $_[2] =~ s{\[(.*?)\]}{ my $x = $1; if ($1 !~ /^\w+:/) { if ($1 =~ /\@/) { "[mailto:$x|$x]"; } else { "[http://$x]" } } else { "[$x]" } }gex; # don't let people put in html $_[2] = HTML::Entities::encode($_[2]); } my $body = "Mail me at [bugs\@microsoft.com]."; my $url; my $name; sanitize("", $url, $body); print $body, "\n";
Modification of a read-only value attempted at perl-alias.pl line 9.To prevent this error, how would I check to see if $_[0] is a scalar that I can write to? Thanks in advance. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I check if a scalar in @_ is writable?
by PodMaster (Abbot) on Oct 27, 2003 at 04:04 UTC | |
|
Re: How do I check if a scalar in @_ is writable?
by theorbtwo (Prior) on Oct 27, 2003 at 06:46 UTC | |
by beppu (Hermit) on Oct 27, 2003 at 23:22 UTC | |
|
Re: How do I check if a scalar in @_ is writable?
by tachyon (Chancellor) on Oct 27, 2003 at 04:06 UTC | |
|
Re: How do I check if a scalar in @_ is writable?
by Zaxo (Archbishop) on Oct 27, 2003 at 04:10 UTC | |
|
Re: How do I check if a scalar in @_ is writable?
by batkins (Chaplain) on Oct 27, 2003 at 04:08 UTC |