&sub qw(1 2);

Q

QoS

Hi,

How come this works:

&ezmenu qw(
++ Action Lookup Cancel -- Exit
++ Edit Cut Copy Paste
++ Logfile View Save -- Clear
++ Options Font Color
++ Help Help About
);

But this produces syntax error:

ezmenu qw(
++ Action Lookup Cancel -- Exit
++ Edit Cut Copy Paste
++ Logfile View Save -- Clear
++ Options Font Color
++ Help Help About
);

Is this a feature of using & vs invoking a sub without & ?

Thanks,

Jason
 
T

Tad J McClellan

How come this works:

&ezmenu qw(
++ Action Lookup Cancel -- Exit
++ Edit Cut Copy Paste
++ Logfile View Save -- Clear
++ Options Font Color
++ Help Help About
);

But this produces syntax error:

ezmenu qw(
++ Action Lookup Cancel -- Exit
++ Edit Cut Copy Paste
++ Logfile View Save -- Clear
++ Options Font Color
++ Help Help About
);

Is this a feature of using & vs invoking a sub without & ?


Kinda sorta.

If you want to omit the ampersand and omit parenthesis, then you must
pay attention to this from perlsub:

NAME LIST; # Parentheses optional if predeclared/imported.

You have omitted the parenthesis but you have NOT predeclared/imported.

Either pre_define_ ezmenu() before you call it:

sub ezmenu {
# do stuff
}
...
ezmenu qw( ... );

or, pre_declare_ ezmenu() before you call it:

sub ezmenu;
...
ezmenu qw( ... );
...
sub ezmenu {
# do stuff
}

or, don't omit the parenthesis:

ezmenu (qw( ... ));

but in that case, I'd chose some qw delimiter other than parens:

ezmenu (qw/ ... /);
 
Q

QoS

Tad J McClellan said:
Kinda sorta.

If you want to omit the ampersand and omit parenthesis, then you must
pay attention to this from perlsub:

NAME LIST; # Parentheses optional if predeclared/imported.

You have omitted the parenthesis but you have NOT predeclared/imported.

Either pre_define_ ezmenu() before you call it:

sub ezmenu {
# do stuff
}
...
ezmenu qw( ... );

or, pre_declare_ ezmenu() before you call it:

sub ezmenu;
...
ezmenu qw( ... );
...
sub ezmenu {
# do stuff
}

or, don't omit the parenthesis:

ezmenu (qw( ... ));

but in that case, I'd chose some qw delimiter other than parens:

ezmenu (qw/ ... /);

So there is a way to do this without an ampersand; that is great, thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top