Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #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:


    …but it doesn't work for me:

    use if $/ = "\n", 5.012 => qw( say ); --output:-- Can't locate 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/ line 13. BEGIN failed--compilation aborted at 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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (2)
    As of 2015-10-09 05:43 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (233 votes), past polls