Turn use strict 'refs' back on after no strict 'refs'

Turn use strict 'refs' back on after no strict 'refs'

Post by Dan Mu » Sat, 05 Jul 2003 01:25:44



Howdy all.

I have the need to turn off strict refs for one line.
I want to make sure strict refs is back on afterward.

if(...) {
        no strict 'refs';
        ...use refs here...
        use strict 'refs';

Quote:}

Is that how I turn them back on or ???
(I think all 'use's get done before anything else so it would be pointless to have it there? )

Or does the no strict 'refs' apply only within it's own block so after I'm out of that if{} statement strict refs are back on?

Thanks

Dan

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Jenda Krynic » Sat, 05 Jul 2003 02:37:51



Quote:> Howdy all.

> I have the need to turn off strict refs for one line.
> I want to make sure strict refs is back on afterward.

> if(...) {
>  no strict 'refs';
>  ...use refs here...
>  use strict 'refs';
> }

> Is that how I turn them back on or ???

Yes

Quote:> (I think all 'use's get done before anything else so it would be
> pointless to have it there? )

No. The use strict ... gets executed just at the right time ... when
Perl parses&compiles your code.

Quote:> Or does the no strict 'refs' apply only within it's own block so after
> I'm out of that if{} statement strict refs are back on?

Yes.

Jenda

When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by mgol.. » Sat, 05 Jul 2003 02:39:42


----- Original Message -----

Date: Thursday, July 3, 2003 12:25 pm
Subject: Turn use strict 'refs' back on after no strict 'refs'

> Howdy all.

Hi Dan,

Quote:

> I have the need to turn off strict refs for one line.
> I want to make sure strict refs is back on afterward.

> if(...) {
>    no strict 'refs';
>    ...use refs here...
>    use strict 'refs';
> }

> Is that how I turn them back on or ???

according to perlmodlib its only enforced untill the end of he block, In your example I would asume you would need an additional block with the if block.
just my $.02

Mark G.

> (I think all 'use's get done before anything else so it would be
> pointless to have it there? )

> Or does the no strict 'refs' apply only within it's own block so
> after I'm out of that if{} statement strict refs are back on?

> Thanks

> Dan

> --



 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Dan Mu » Sat, 05 Jul 2003 02:45:56


Excellent thanks Jenda, all very helpful!

Just By the way, Mail::Sender rocks!

Have agood one

Dan


> > Howdy all.

> > I have the need to turn off strict refs for one line.
> > I want to make sure strict refs is back on afterward.

> > if(...) {
> >  no strict 'refs';
> >  ...use refs here...
> >  use strict 'refs';
> > }

> > Is that how I turn them back on or ???

> Yes

> > (I think all 'use's get done before anything else so it would be
> > pointless to have it there? )

> No. The use strict ... gets executed just at the right time ... when
> Perl parses&compiles your code.

> > Or does the no strict 'refs' apply only within it's own
> block so after
> > I'm out of that if{} statement strict refs are back on?

> Yes.

> Jenda

> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
>    -- Terry Pratchett in Sourcery

> --



 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Dan Mu » Sat, 05 Jul 2003 02:46:53


Quote:> according to perlmodlib its only enforced untill the end of
> he block, In your example I would asume you would need an
> additional block with the if block. just my $.02

> Mark G.

Thanks Mark! I'll take your $.02 and play around with it!

Dan

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Bob Showalt » Sat, 05 Jul 2003 02:52:37



> Howdy all.

> I have the need to turn off strict refs for one line.
> I want to make sure strict refs is back on afterward.

> if(...) {
>    no strict 'refs';
>    ...use refs here...
>    use strict 'refs';
> }

> Is that how I turn them back on or ???
> (I think all 'use's get done before anything else so it would
> be pointless to have it there? )

You can turn it back on like that. "use" happens at compile-time, but strict
checking also happens at compile-time, so it all works out correctly (with
some help from the magcial behavior of the special $^H variable).

Quote:

> Or does the no strict 'refs' apply only within it's own block
> so after I'm out of that if{} statement strict refs are back on?

Yes, that's true as well. (It's documented under perldoc perlvar, search for
$^H)

Sometimes you want to localize the action to just the right-side of an
assignment. For example:

  use strict;
  our $bar = 1;
  my $ref = 'bar';
  my $foo = $$ref;       # error: symbolic reference

You can do that with:

   my $foo = do { no strict 'refs'; $$ref };

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Dan Mu » Sat, 05 Jul 2003 03:02:29



> > Howdy all.

> > I have the need to turn off strict refs for one line.
> > I want to make sure strict refs is back on afterward.

> > if(...) {
> >       no strict 'refs';
> >       ...use refs here...
> >       use strict 'refs';
> > }

> > Is that how I turn them back on or ???
> > (I think all 'use's get done before anything else so it would be
> > pointless to have it there? )

> You can turn it back on like that. "use" happens at
> compile-time, but strict checking also happens at
> compile-time, so it all works out correctly (with some help
> from the magcial behavior of the special $^H variable).

> > Or does the no strict 'refs' apply only within it's own
> block so after
> > I'm out of that if{} statement strict refs are back on?

> Yes, that's true as well. (It's documented under perldoc
> perlvar, search for
> $^H)

> Sometimes you want to localize the action to just the
> right-side of an assignment. For example:

>   use strict;
>   our $bar = 1;
>   my $ref = 'bar';
>   my $foo = $$ref;       # error: symbolic reference

> You can do that with:

>    my $foo = do { no strict 'refs'; $$ref };

Ooohh cool. Thanks for the info, I'll tuck that way under my hat also!

Thanks

Dan

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Rob Dix » Sat, 05 Jul 2003 03:12:00



> Howdy all.

> I have the need to turn off strict refs for one line.
> I want to make sure strict refs is back on afterward.

> if(...) {
> no strict 'refs';
> ...use refs here...
> use strict 'refs';
> }

> Is that how I turn them back on or ???
> (I think all 'use's get done before anything else so it would be pointless to have it there? )

> Or does the no strict 'refs' apply only within it's own block so after I'm out of that if{} statement strict refs are back on?

Hi Dan.

'Yes' to your last sentence. Has anybody said that yet?

The use/no for a pragma applies only to its containing
block (or file). (It's very non-Perl to explain why, so I
won't.) Check out

  use strict;

  our $a = 99;
  my $n = 'a';

  {
    no strict 'refs';
    print $$n, "\n";
  }

  print $$n, "\n";

will error only on the second 'print' statement. It's
immaterial whether the block is controlled by an 'if',
'while', 'for' etc.

HTH,

Rob

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Rob Dix » Sat, 05 Jul 2003 03:12:57



> Ooohh cool. Thanks for the info, I'll tuck that way under my hat also!

Get a BIG hat :)

Rob

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Dan Mu » Sat, 05 Jul 2003 03:33:44



> > Howdy all.

> > I have the need to turn off strict refs for one line.
> > I want to make sure strict refs is back on afterward.

> > if(...) {
> > no strict 'refs';
> > ...use refs here...
> > use strict 'refs';
> > }

> > Is that how I turn them back on or ???
> > (I think all 'use's get done before anything else so it would be
> > pointless to have it there? )

> > Or does the no strict 'refs' apply only within it's own
> block so after
> > I'm out of that if{} statement strict refs are back on?

> Hi Dan.

> 'Yes' to your last sentence. Has anybody said that yet?

> The use/no for a pragma applies only to its containing
> block (or file). (It's very non-Perl to explain why, so I
> won't.) Check out

>   use strict;

>   our $a = 99;
>   my $n = 'a';

>   {
>     no strict 'refs';
>     print $$n, "\n";
>   }

>   print $$n, "\n";

> will error only on the second 'print' statement. It's
> immaterial whether the block is controlled by an 'if',
> 'while', 'for' etc.

> HTH,

Yup, that helps a lot, (as usual ;p) thanks!
Dan

- Show quoted text -

Quote:

> Rob

 
 
 

Turn use strict 'refs' back on after no strict 'refs'

Post by Dan Mu » Sat, 05 Jul 2003 03:34:47



> > Ooohh cool. Thanks for the info, I'll tuck that way under
> my hat also!

> Get a BIG hat :)

Oh I got several, one of them is Red :)
Quote:

> Rob

 
 
 

1. Declare $main::scalar in begin with 'use strict'

I'm trying to declare a variable $log that is a reference to an array that
will contain the small amounts of data that need to be logged throughout a
backup script i'm working on. I'd like to declare this scalar reference in
the BEGIN function, but i can't use it outside of the BEGIN function if i
declare 'my $log' in BEGIN.

Hmmm.... And since BEGIN is the first function to be called (right??) how
might i declare the scalar as global?

Well, actually, i just tried 'use vars qw($log)' and it seems to have solved
that problem.

But! i also have a function being used to assign the reference to $log that
will point to the log array, and it ?needs? to be prototyped before the call
is made to it... and i just tried 'use subs qw(StartLog(...))' but it claims
it still needs to be prototyped before the call.. i think.  

Any ideas?

I get this error after a call is made within BEGIN like such

# START PERL CODE

use strict;
use warnings;

use vars qw($log);
use subs qw(&StartLog(...));

 ...
 ...

BEGIN
{
        $log = &StartLog(...);
        ...

 ...
 ...

# END PERL CODE

(here's the error..)

        Undefined subroutine &main::StartLog called at localMysqlHotCopyToRemote.pl        
line 349.
        BEGIN failed--compilation aborted at localMysqlHotCopyToRemote.pl line 357.

If anyone could briefly explain what the differences are between calling a
sub-routine with the amperstand '&' and without it. I remember reading about
it somewhere... Does it have to do with my problem?

        Thanks a bundle (Bundle::CPAN!! HA HE HA! Damn, that was bad)
                -Chris

2. Ann: ToDoPlus/Trip

3. Fwd: Re: Declare $main::scalar in begin with 'use strict'

4. WoW!!!!!!!!

5. Complaint from 'use strict' about bareword;

6. Wanted: Cisco 1004 Router

7. using 'map' with mixture of scalars and array refs...

8. Macintosh software synth recommendations?

9. "" "" "" " '' '' '' '' '' '' '' ''

10. 'previous page' / 'back button' in a PDF

11. ''''''Astra-1200s 3.1 Firmware available here'''''''

12. Has anyone used 'C-Pen 800C' or 'QuickLink Pen' handheld pen scanners?

13. Boundry Alignment problem: Using operator '<<' to build 'any'