Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

perl::critic::policy::inputoutput::prohibitreadlineinforloop(3) [centos man page]

Perl::Critic::Policy::InputOutput::ProhibitReadlineInForUser(Contributed Perl DocumPerl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop(3)

NAME
Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop - Write "while( $line = <> ){...}" instead of "for(<>){...}". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Using the readline operator in a "for" or "foreach" loop is very slow. The iteration list of the loop creates a list context, which causes the readline operator to read the entire input stream before iteration even starts. Instead, just use a "while" loop, which only reads one line at a time. for my $line ( <$file_handle> ){ do_something($line) } #not ok while ( my $line = <$file_handle> ){ do_something($line) } #ok CONFIGURATION
This Policy is not configurable except for the standard options. AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop(3)

Check Out this Related Man Page

Perl::Critic::Policy::ControlStructures::ProhibitUntilBlUser(Contributed Perl DocumPerl::Critic::Policy::ControlStructures::ProhibitUntilBlocks(3)

NAME
Perl::Critic::Policy::ControlStructures::ProhibitUntilBlocks - Write "while(! $condition)" instead of "until($condition)". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Conway discourages using "until" because it leads to double-negatives that are hard to understand. Instead, reverse the logic and use "while". until($condition) { do_something() } #not ok until(! $no_flag) { do_something() } #really bad while( ! $condition) { do_something() } #ok This Policy only covers the block-form of "until". For the postfix variety, see "ProhibitPostfixControls". CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::Policy::ControlStructures::ProhibitUntilBlocks(3)
Man Page

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Alternative for a while read line loop

HELLO all :), I have been trying to use a simple while loop to read a file " templist", line by line and perform an action. See the code below. The reason for not using a while read line loop is the for the use of the if condition that wouldn't work. I would appreciate some ideas as this has... (2 Replies)
Discussion started by: kabs
2 Replies

2. Shell Programming and Scripting

while loop error

while read line do echo "read line is $line" done < $file where $file is file having following contents 1=one 2=two 3=three but above while loop is not able to print last line !! why ? (3 Replies)
Discussion started by: crackthehit007
3 Replies

3. Shell Programming and Scripting

Opening Mulitple files using For loop in Perl

Hi All, I have a total of ten file to open in the Perl script and i am using a for loop to open each file and capture some strings inside each file. Unfortunately, i encounter the below syntax error. I think there should be something wrong with this term reports_${counting}_${_}.txt but i do... (4 Replies)
Discussion started by: Raynon
4 Replies

4. Shell Programming and Scripting

Push records to array during implicit loop and write to file

NEWBIE ALERT! Hi, I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies

5. Shell Programming and Scripting

Problem in reading a file content

Hi, I am reading a file line by line using read line function of while loop. Each line contains 4 fields. I want to take these 4 values in 4 variables in each iteration so that i can use them in my script. The issue here is that my awk command is returning awkward results - Here is a sample line... (8 Replies)
Discussion started by: garman
8 Replies

6. Shell Programming and Scripting

Perl Diamond Operator

I know that when using 'while (<FILE>) {}', Perl reads only one line of the file at one time, and store it in '$_'. Can I change some parameters so that 'while (<>) {}' can read more than one lines, like 2 or 5 lines at one time? Thanks for the help! (1 Reply)
Discussion started by: zx1106
1 Replies

7. Shell Programming and Scripting

until loop Perl

I am trying to print out a section of a file begining at the start and printng until a character is found. My code and input file are below. This code is printing out every line except for the line with the character which is not what I want the out put should be a file with numbers 1-4. ... (3 Replies)
Discussion started by: cold_Que
3 Replies