GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PERL::CRITIC::POLICY::BUILTINFUNCTIONS::PROHIBITUSELESSTOPIC (3)

.ds Aq ’

NAME

Perl::Critic::Policy::BuiltinFunctions::ProhibitUselessTopic - Don’t pass $_ to built-in functions that assume it, or to most filetest operators.

CONTENTS

AFFILIATION

This Policy is part of the Perl::Critic distribution.

DESCRIPTION

There are a number of places where $_, or the topic variable, is unnecessary.

    Topic unnecessary for certain Perl built-in functions

Many Perl built-in functions will operate on $_ if no argument is passed. For example, the length function will operate on $_ by default. This snippet:



    for ( @list ) {
        if ( length( $_ ) == 4 ) { ...



is more idiomatically written as:



    for ( @list ) {
        if ( length == 4 ) { ...



In the case of the split function, the second argument is the one that defaults to $_. This snippet:



    for ( @list ) {
        my @args = split /\t/, $_;



is better written as:



    for ( @list ) {
        my @args = split /\t/;



There is one built-in that this policy does <B>notB> check for: reverse called with $_.

The reverse function only operates on $_ if called in scalar context. Therefore:



    for ( @list ) {
        my $backwards = reverse $_;



is better written as:



    for ( @list ) {
        my $backwards = reverse;



However, the distinction for scalar vs. list context on reverse is not yet working. See KNOWN BUGS below.

    Topic unnecessary for most filetest operators

Another place that $_ is unnecessary is with a filetest operator.



    # These are identical.
    my $size = -s $_;
    my $size = -s;

    # These are identical.
    if ( -r $_ ) { ...
    if ( -r ) { ...



The exception is after the -t filetest operator, which instead of defaulting to $_ defaults to STDIN.



    # These are NOT identical.
    if ( -t $_ ) { ...
    if ( -t ) { ...  # Checks STDIN, not $_



KNOWN BUGS

This policy flags a false positive on reverse called in list context, since reverse in list context does not assume $_.



    my $s = reverse( $_ ); # $_ is useless.
    my @a = reverse( $_ ); # $_ is not useless here.



CONFIGURATION

This Policy is not configurable except for the standard options.

AUTHOR

Andy Lester <andy@petdance.com>

COPYRIGHT

Copyright (c) 2013 Andy Lester <andy@petdance.com>

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PERL::CRITIC::POLICY::BUILTINFUNCTIONS::PROHIBITUSELESSTOPIC (3) 2016-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.