#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4

    Perl Critic Questions


    I'm using Perl Critic to help me learn best practices and I'm having an issue with 2 errors.

    1. Useless interpolation of a literal string.

    This comes from:

    Code:
    $a = sprintf "%02x", hex $a;
    The interpolation is not useless to me as I need to convert a randomly selected hex number from 0 - F to 00 - 0F. Is there a better way to do this without getting this error?

    2. Return value of flagged function ignored - print.

    How do i make sure print returns something? Is this necessary? Should I live and die with critic or use my judgement? I got into error 1 by first removing parens from all built in functions. I had always used parens with sprintf in the past.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4
    Originally Posted by dolfantb
    I'm using Perl Critic to help me learn best practices and I'm having an issue with 2 errors.

    1. Useless interpolation of a literal string.

    This comes from:

    Code:
    $a = sprintf "%02x", hex $a;
    The interpolation is not useless to me as I need to convert a randomly selected hex number from 0 - F to 00 - 0F. Is there a better way to do this without getting this error?

    2. Return value of flagged function ignored - print.

    How do i make sure print returns something? Is this necessary? Should I live and die with critic or use my judgement? I got into error 1 by first removing parens from all built in functions. I had always used parens with sprintf in the past.
    I figured the sprintf issue out, just need help with the 2nd problem.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    print returns false on failure. If you're writing to a file or the console that's not likely to happen; writing to a socket however can. But there's no reason to clutter up your program with a mess of "print $x or die;" statements unless you are writing to a handle that has a likelihood of failure and there's something meaningful you can do if it does fail.

    Perlcritic has a lot of (IMHO) useless warnings. Most have explanations their modules (the file will be somewhere like lib\Perl\Critic\Policies\XyzCategory\AbcPolicy.pm), read the perldoc and decide if the warning is useful to you, and if not set up your .perlcritic configuration to ignore it.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4
    Originally Posted by OmegaZero
    print returns false on failure. If you're writing to a file or the console that's not likely to happen; writing to a socket however can. But there's no reason to clutter up your program with a mess of "print $x or die;" statements unless you are writing to a handle that has a likelihood of failure and there's something meaningful you can do if it does fail.

    Perlcritic has a lot of (IMHO) useless warnings. Most have explanations their modules (the file will be somewhere like lib\Perl\Critic\Policies\XyzCategory\AbcPolicy.pm), read the perldoc and decide if the warning is useful to you, and if not set up your .perlcritic configuration to ignore it.
    Thanks, that's the exact kind of information I'm looking for.

IMN logo majestic logo threadwatch logo seochat tools logo