Saturday, March 16, 2002, 3:29:29 AM, Yuan Cheng wrote:

> I am wondering what else 'use strict' does besides it
> is stated in the perldoc that it stricts on use of
> 'vars', 'refs' and 'subs'.  Thanks.

They basically stop you from doing things that are
dangerous, or stupid, or could break things in subtle ways.

Timothy Johnson said stuff about vars...

Strictures on 'refs' means that you can't use symbolic
references. Say you defined a variable:

  $foo = "hello, world\n";

then without strict 'refs', you would be able to do:

  $var_name = "foo";
  print $$var_name;

very occasionally you may want to do this, but it's not
common that anyone would want to. It's guaranteed to make
your head hurt working out what are variables and what
aren't, and usually it's better to use a hash.

strict 'subs' generates "a compile-time error if you try to
use a bareword identifier that's not a subroutine, unless it
appears in curly braces or on the left hand side of the "=>"
symbol" [1]

compare:

  #!/usr/bin/perl
  my $greet = hello;
  print "$greet world\n";

which outputs "hello world", to:

  #!/usr/bin/perl
  use strict;
  my $greet = hello;
  print "$greet world\n";

which die's saying:

  Bareword "hello" not allowed while "strict subs" in use at ./strict.pl line 3.

you shouldn't want to use barewords anyway



[1] http://www.perldoc.com/perl5.6.1/lib/strict.html


-- 
Best Regards,
Daniel                   [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to