I am trying to piece together other scripts i have seen to be able to loop through a list of users on the channel.
Here is what i have come up with
my $channel = @_;
foreach my $nick ($channel->nicks()) {
$server->command("msg $chatchannel $nick->{nick}");
}
But all i get from that is
Can't call method "nicks" without a package or object reference at /root/.irssi/scripts/test.pl line 64.
which is referring to
$channel->nicks()
Am i going about this the wrong way? or should this be working? I have seen many other scripts using $channel->nicks() so i know it must work?
Edit
I should also mention that this is already define further up in the code
my ($server, $msg, $target, $channel, $chatnet) = @_;
But when i try it with that $channel variable i get
Can't locate object method "nicks" via package "[email protected]" (perhaps you forgot to load "[email protected]"?) at /root/.irssi/scripts/test.pl line 64.
Since the left hand side (LHS) of
my $channel = @_;
is a scalar it imposes scalar context on the@_
array. This means that the length of the array gets assigned to$channel
. You want to assign withmy ($channel) = @_;
so that the LHS is in list context and that the first element in the@_
array gets assigned to your scalar.Ref:
What is the difference between the scalar and list contexts in Perl?
Scalar and List context in Perl