Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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: $!" ;
and
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 $_ ; }

CountZero

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


Comment on Re: Newby question
Select or Download Code
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.

      OGB

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-07-30 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls