Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Newby question

by CountZero (Bishop)
on Aug 05, 2012 at 06:59 UTC ( #985491=note: print w/replies, xml ) Need Help??

in reply to Newby question

This must be a very old book you are reading.

Nowadays it is customary to use the more secure 3 argument variant of open with a lexical filehandle. Also, you do not have to double quote your variables, unless you want to interpolate them into a string.

open my $READFILE, '<', $infile or die "Can not open $infile for parsi +ng: $!" ;
open my $WRITEFILE, '>', $outfile or die "Can not open new replacement + file: $outfile. $!";

Your loop will then be written as follows:

while (<$READFILE>) { # do something to $_ print $WRITEFILE $_ ; }


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^2: Newby question
by Parmenides (Initiate) on Aug 05, 2012 at 08:09 UTC
    I am reading a book called learning perl. It is from 1999 so yes it is old. Do you know of a newer book that includes exercizes in the chapters? Also, big thanks to you all. I got this piece working :)
      If this is 'Learning Perl' by Randal Schwartz, et al., then the fifth edition was published last year by O'Reilly. I'd strongly recommend buying it, Perl has had a few changes in the past 13 years.

      Update: Fixed typo

      I Go Back to Sleep, Now.


        I am now reading a more updated book. The heads up was very much appreciated.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985491]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2018-08-19 00:13 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (186 votes). Check out past polls.