Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: need logic and one error help
On 28 Mar, T Raymond wrote:

> #!/usr/bin/perl -w

Refactor with use warnings instead of -w.
-w leaks warnings to all scopes, i.e. external modules,
whereas warnings keeps itself to the local block.
See perldoc warnings therefore.


> print header,

What is header supposed to act on?
If it's the method declared in CGI.pm, which I'd assume,
you need to create an object by saying my $q = new CGI and
replace header with $q->header.


> start_html(-title=>'Employee Search'),
> h1('Teresa Raymond's Employee Search');
>
> &search_form  unless param;

& implies passing @_ to search_form(); unneeded and very
dangerous, in most cases.


>     my $filename='employee.dat';

This is not C, so whitespaces between the variable, the assign
operator and the value is greatly recommended. See man perlstyle
therefore.


>     my $fn_weight;
>     my $ln_weight;
>     my $weight;
>     my $ot_hours;

One can argue, whether declaring those variables in several
or a single line may add up to readability. I prefer the grouped variant
in a single line, unless the variables have any familiarity at all.


>     die "cannot locate $filename\n";

Replace with "die "$filename: $!\n";
$! contains the exception message emitted by many functions
on failure.


>         for (@rows)

Are you sure, you want to have $_ evaluated instead of, say, my
$single_row? Aware of possible variable stomping?


>             if (my @matches = $fname =~ m/^$first_name/ig)
>             {

Conditions usually read CONDITION () {
}


>            if ($employees{$_}{$fname}=~m/^$first_name/ig)

Have you checked the definedness of $first_name via defined()?


> sub sub_calc_ot_pay
> {
>     my $hourly_wage = $_[0];
>     my $ot_hours = $_[1];

my ($hourly_wage, $ot_hours) = @_;


--
The trouble with having an open mind, of course,
is that people will insist on coming along and trying to put things in it.
-- Terry Pratchett

Report this thread to moderator Post Follow-up to this message
Old Post
Steven Schubiger
03-28-05 08:55 AM


RE: need logic and one error help
Steven Schubiger <mailto:steven@accognoscere.org> wrote:

: On 28 Mar, T Raymond wrote:
:
: : print header,
:
: What is header supposed to act on?
: If it's the method declared in CGI.pm, which I'd assume,
: you need to create an object by saying my $q = new CGI and
: replace header with $q->header.

The OP is using the function oriented version of CGI.pm.
This is homework and perhaps his class hasn't gotten to
objects yet.


[snip]
: :     die "cannot locate $filename\n";
:
: Replace with "die "$filename: $!\n";
: $! contains the exception message emitted by many functions
: on failure.

Omit the "\n", it suppresses important information. I
prefer this idiom. The quotes around the filename have saved
me hours. :)

open FH, $file or die qq(Cannot open "$file": $!);


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
03-28-05 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL CGI Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:52 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.