use warnings unless $foo

F

Florian Kaufmann

use, no, package are special in that I can not say

use warnings if $foo;

Is there a name for those keywords which do not form a normal
expression? I.e. where I can not append a statement modifier.

Where in the perldoc do I find a complete list of those keywords?

Thank you

Flo
 
J

Jürgen Exner

Florian Kaufmann said:
use, no, package are special in that I can not say

use warnings if $foo;

Well, yes, you can. But it doesn't do what you seem to expect it to do.
use() is executed at compile time because it is a short form of
BEGIN { require Module; import Module LIST; }

If you don't want that but want it to be executed at compile time after
evaluating and assessing $foo then just use the block without the
BEGIN/END:
if $foo then {require warnings; import warnings;}
Is there a name for those keywords which do not form a normal
expression? I.e. where I can not append a statement modifier.

Missleading way of thinking. The problem is It is not that you can't
statement modifiers, it is that
 
J

Jürgen Exner

Jürgen Exner said:
Well, yes, you can. But it doesn't do what you seem to expect it to do.
use() is executed at compile time because it is a short form of
BEGIN { require Module; import Module LIST; }

If you don't want that but want it to be executed at compile time after
evaluating and assessing $foo then just use the block without the
BEGIN/END:
if $foo then {require warnings; import warnings;}

Misleading way of thinking. The problem is NOT that you couldn't
use statement modifiers. The problem is that that BEGIN/END enforces
execution at compile time, i.e. before perl had any chance to look at
the condition 'if $foo'.

About the fourth line of
perldoc -f use

As for where to find "BEGIN/END": that's a good question :) I couldn't
find an entry after a brief search.

jue
 
F

Florian Kaufmann

Well, yes, you can. But it doesn't do what you seem to expect it to do.

Apparently not:

$ perl -e 'use warnings if $foo'
syntax error at -e line 1, near "use warnings if"
Execution of -e aborted due to compilation errors.
$ perl --version

This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

It's not that I currently wan't to do such sort of thing, I just want
to learn Pearl properly. But you mentioned the right thing: use, no,
package happen at compile time. So I ask another way round: Is there a
complete list of things (keywords?) that happen at compile time, and
thus can't have a statement modifier. Is there a name for the group of
such things?

Flo
 
A

A. Sinan Unur

use, no, package are special in that I can not say

use warnings if $foo;

perldoc if

Example:

C:\Temp> cat t.pl
#!/usr/bin/perl

use if $ENV{STRICT}, 'strict';
use if $ENV{WARNINGS}, 'warnings';

print "$x = something\n";

__END__

C:\Temp> t
= something

C:\Temp> t
Name "main::x" used only once: possible typo at C:\Temp\t.pl line 6.
Use of uninitialized value $x in concatenation (.) or string at C:\Temp
\t.pl line 6.
= something

C:\Temp> set strict=1

C:\Temp> t
Global symbol "$x" requires explicit package name at C:\Temp\t.pl line
6. Execution of C:\Temp\t.pl aborted due to compilation errors.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
T

Tad J McClellan

Jürgen Exner said:
As for where to find "BEGIN/END": that's a good question :) I couldn't
find an entry after a brief search.


See the "BEGIN, CHECK, INIT and END" section in perlmod.pod.

Took me less than two seconds to find it, because of the indexes
I've created as described at the end of the Perl problem resolution checklist:

http://groups.google.com/groups/[email protected]


I don't actually do the "cd ..." part, I've defined an alias for that.

So I just did:

gopod
grep BEGIN all.heads


:)
 
T

Tad J McClellan

Jürgen Exner said:
Well, yes, you can. But it doesn't do what you seem to expect it to do.
use() is executed at compile time because it is a short form of
BEGIN { require Module; import Module LIST; }

If you don't want that but want it to be executed at compile time after
^^^^^^^^^^^^

s/compile time/run time/;
 
T

Tad J McClellan

Please choose one posting address, and stick to it.

It's not that I currently wan't to do such sort of thing


It's not that you currently wa not to do such sort of thing?
 
I

Ilya Zakharevich

Misleading way of thinking. The problem is NOT that you couldn't
use statement modifiers. The problem is that that BEGIN/END enforces
execution at compile time, i.e. before perl had any chance to look at
the condition 'if $foo'.

This is not fully kosher explanation. Note that arguments to `use'
ARE executed at compile time. Why not if/unless conditions?

Note that this bug in Perl has a fix - for about a decade. It is just
that some %@$#$* rejected my patch which fixed this bug.

Thus I needed to created this `use if ...' ugliness...

Hope this helps,
Ilya
 
S

sln

Please choose one posting address, and stick to it.




It's not that you currently wa not to do such sort of thing?

I just wan't to say Tad, you should learn English because I do'nt
think yo've been to school lately.

-sln
 
S

sln

use, no, package are special in that I can not say

use warnings if $foo;

Is there a name for those keywords which do not form a normal
expression? I.e. where I can not append a statement modifier.

Where in the perldoc do I find a complete list of those keywords?

Thank you

Flo

Yeah, isin't some use's pragmata though? If not then all pragmata are
packages then. How bizzare.. Never get what you wan't huh. Not out of Perl.
If you did, there would be no air time for the hackers with no jobs here.

-sln
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top