On Sat, 2024-01-13 at 15:00 +0000, Andrew Solomon wrote:
> I think the line:
>
> reply_multi( \$daemon{xmpp_o}, \($adminuser{fromJID}, $fromJID), "blah" );
>
> should have \(...) replaced with [ ... ] :
>
> reply_multi( \$daemon{xmpp_o}, [$adminuser{fromJID}, $fromJID], "blah" );
>
> because
>
> \('foo', 'bar')
>
> evaluates to
>
> (\'foo', \'bar')
>
> Does that clarify this for you?
Not really ... I vaguely thought that [] might do the trick, but
since when is an array in perl declared with [] instead of ()? You
can also do
foreach my $foo ('bar', 'baz') {
print "$foo\n";
}
since foreach takes arrays. So why aren't arrays created the same way
when being passed as parameters to functions (when signatures are
being used)?
Somehow I don't remember what [] exactly do there :/ If that's like
foreach my $foo (@['bar', 'baz'])
I'd guess I remember correctly and it would kinda make sense ...
But still ... Parentheses should take precendence, shouldn't they?
> Andrew
>
> On Sat, Jan 13, 2024 at 2:51 PM hw <[email protected]> wrote:
>
> > Hi,
> >
> > how do I pass an array that is created on the fly as one parameter of
> > a function?
> >
> > Example:
> >
> >
> > use feature 'signatures';
> > no warnings 'experimental::signatures';
> >
> > sub reply_multi ( $xmpp_o, $rcpts, $msg ) {
> > foreach my $rcpt (@$rcpts) {
> > $$xmpp_o->MessageSend( type => 'chat', to => $rcpt, body => $msg );
> > }
> >
> > return;
> > }
> >
> > reply_multi( \$daemon{xmpp_o}, \($adminuser{fromJID}, $fromJID), "blah" );
> >
> >
> > This gives me an error at runtime: "Too many arguments for subroutine
> > 'main::reply_multi' (got 4; expected 3)".
> >
> > Yeah, sure, ok, but is that even right? Or is signatures too
> > experimental to handel that yet? Or how do I do what I want here?
> >
> >
> > --
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> > http://learn.perl.org/
> >
> >
> >
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/