Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I don't understand why you're using feature qw(say) if you wanna redefine 'say.

I had trouble understanding that too. But as I understand it, the op turned on say() with his use statement, and now the op has say() statements littered throughout the code. Now the op wants to figure out a way to make his say() statements print nothing if a switch is set. Note that his custom say() sub doesn't print anything if $verbose is false.

As for 'use if', I was looking at that too, and I found two problems with it:

  1. 'use if' doesn't work as advertised for me. Here is the syntax shown in the 'if' pragma:

    use if CONDITION, MODULE => ARGUMENTS

    …but it doesn't work for me:

    use if $/ = "\n", 5.012 => qw( say ); --output:-- Can't locate 5.012.pm in @INC (@INC contains: /Users/7stud/perl5/perlb +rew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level /Users/7stud +/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0 /Users/7stud/p +erl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level /Users/7stud +/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0 .) at /Users/7stud/perl5 +/perlbrew/perls/perl-5.16.0/lib/5.16.0/if.pm line 13. BEGIN failed--compilation aborted at 2.pl line 1.

    Yet all my perl programs use 5.012 without error. In addition, the 'use if' can't see a my variable in the code, e.g.

    my $verbose = 1;

    Apparently, 'use if' can only see a global variable that exists at compile time. Using our to declare $verbose doesn't work either:

    our $verbose = 1; use if $verbose, 'strict'; $v = 'hello';

    No error. I see that you got around that problem with use constant.

  2. Turning off say() will cause all the say() statements in the op's code to produce errors.

It looks like 'use subs' can be made to work (I think you originally posted something about that??):

use strict; use warnings; #use 5.012; #enables say() use subs qw( say ); my $verbose = 1; sub say { if ($verbose) { print shift, " world\n"; } } say 'hello'; --output:-- hello world

In reply to Re: Redefining Imported Subs: of scope and no by 7stud
in thread Redefining Imported Subs: of scope and no by temporal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-16 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found