Gossamer Forum
Home : General : Perl Programming :

Arrayref

Quote Reply
Arrayref
Can anyone spot the problem with this?

Code:
@{$CFG->{swear_filter}} = split /\n+/, $input->{swear_filter};

$input->{swear_filter} is form input. It is a textarea containing one word per line eg:

bad
words
go
here

.....the code was working but I must have tweaked something and now I get:

Can't use string ("bad
words
go
here") as an ARRAY ref while "strict refs" in use at Admin.pm line 67.

If I turn off strict refs it just updates the config with:

'swear_filter' => 'bad words go here'

....when it should be:

'swear_filter' => ['bad', 'words', 'go', 'here']

I'm embarassed to say I can't figure it out, and as usual it will either be a stupid mistake or I'll figure it out in about 3 seconds.

Last edited by:

RedRum: Mar 9, 2002, 5:11 AM
Quote Reply
Re: [RedRum] Arrayref In reply to
Ugh what did I say!

It was caused further up by:

$CFG->{$_} = $input->{$_} in a loop....I needed:

Code:
$CFG->{$_} = $input->{$_} unless /^swear_filter$/;


....and then further down I could use:

Code:
# Update the swear filter arrayref.
@{$CFG->{swear_filter}} = split /\n+/, $input->{swear_filter};