CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [FishMonger] Perl Lost: Edit Log



7stud
Enthusiast

Nov 2, 2009, 1:32 PM


Views: 5983
Re: [FishMonger] Perl Lost


In Reply To
All Perl scripts should include these 2 pragmas

Code
use strict; 
use warnings;

It's best to use the warnings pragma instead of the -w switch.

All vars should be declared in the smallest scope that they require.


Code
if ($#ARGV == -1)

Is better written as:

Code
if ( !@ARGV )


This line doesn't fully meet the requirements.

Code
if ($filename !~ m/[a-zA-Z]{0,7}\.TXT$/i)


The instructor supplied code is using the bareword READFILE for the filehandle. Since perl 5.6 (which is almost 10 years) it has been recommended (and is better) to use a lexical var for the filehandle and the 3 arg form of open.


Code
open my $READFILE, '<', $filename 
or die "Could not open file '$filename':$!";


Thanks for the tips! I've been reading "man perlintro" and it must be old. It talked about scalar variables($var), array variables (@var), and hash variables (%var), but then in the file section, suddenly it introduced INPUTFILE: a constant like variable, with no explanation.

Should the filehandle variable be capitalized($READFILE)? Also, isn't the 3 arg form of open() a pain to type? It's not considered good style to put the '<' in the same string as $filename, e.g.


Code
my $file; 
open ($file, "<data.txt") or die "....$!";



(This post was edited by 7stud on Nov 2, 2009, 1:43 PM)


Edit Log:
Post edited by 7stud (Enthusiast) on Nov 2, 2009, 1:33 PM
Post edited by 7stud (Enthusiast) on Nov 2, 2009, 1:43 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives