Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Some things that will make your life easier as a Perl coder

by root (Scribe)
on Nov 03, 1999 at 02:21 UTC ( #917=perltutorial: print w/replies, xml ) Need Help??

Number one: when in doubt use perl -w, or replace #!/usr/bin/perl with #!/usr/bin/perl -w this will give you all kinds of helpful diagnostics when things don't seem to be happening as you'd expect them to.

Number two: use use strict; just toss that in at the top of your program and it will force you to declare your variables before you use them. To declare them all you have to do is something like the following:
my $stuff;
my @array;
my %hash;
my ($count,$max,$min,$avg); #this initializes several scalars at once
This can save you countless hours later if you've mistyped a variable name. You'll know about it.
  • Comment on Some things that will make your life easier as a Perl coder

Replies are listed 'Best First'.
Re: Some things that will make your life easier as a Perl coder
by chrism01 (Friar) on Nov 13, 2007 at 23:58 UTC
    Personally, I ALWAYS use both... I highly recommend that to everybody. Helps enormously.

    Cheers
    Chris

      Thanks chris, i just started learning about perl. It seems like a language that i would like to get to know at an expert level ( i hope). Thanks Kevin
Re: Some things that will make your life easier as a Perl coder
by dannyd (Sexton) on Feb 23, 2011 at 12:16 UTC

    Its amazing how some things can be so short and yet tell you exactly what you need to know.

    Thank a lot!!.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://917]
help
Chatterbox?
[Corion]: haukex: Aaah - I thought you were still running these tests on every machine, but you only run these as author or Devel::Cover tests
[Corion]: haukex: Yeah, I think back then I used Test::Inline, which used a pod parser that was going through some changes and I didn't want to cater for all the various versions and thus stopped testing the Pod completely
[choroba]: I usually do this with presentations
[Corion]: But now I think statically (re)generating the Pod tests is a saner approach, and likely I'll regenerate the tests either in Makefile.PL or from xt/ but have them live below t/
[choroba]: I keep the snippets in files of their own, and use a Makefile to syntax highlight them and insert them into slides, while also running them and inserting the output if required
[Corion]: choroba: Ooooh - I didn't think of that! I write my presentations as POD and if it "roughly" looks like Perl code, I should also syntax-check that...
[haukex]: Yes sorry I don't run them all the time, my POD tests are only run as author tests (and are excluded when I'm using Devel::Cover)
[Corion]: choroba: Hmm - no, I keep the snippets inline, but as my framework also has support for capturing output etc., maybe I should do the same...
[Corion]: haukex: Yes, that approach is sane, and it heals the fragility of Pod parsers in a nice way while still syntax-checking stuff
[choroba]: Unfortunately, none of it is online

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-02-27 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.