FAQ
Hi all,
I am a novice to perl. I find Perl very interesting and I am studying how to
write and compile perl scripts without syntax and compilation errors. I need
heads up on how.

thanks,
DJ

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus

Search Discussions

  • Wiggins d'Anconia at Feb 8, 2003 at 11:09 pm

    dakenah johnson wrote:
    Hi all,
    I am a novice to perl. I find Perl very interesting and I am studying
    how to write and compile perl scripts without syntax and compilation
    errors. I need heads up on how.
    This is a very vague question...but here are some pointers:

    always do:

    use strict;
    use warnings;

    At the beginning of your scripts, this will save you many headaches later.

    You can run syntax checks of your script without executing them by doing:

    perl -c <name of script>

    Familiarize yourself with the perldocs, check to see what is available
    to you by doing:

    perldoc perl

    And for specific error messages that you may receive, check:

    perldoc perldiag

    Finally don't be afraid to ask questions, here or in other forums, don't
    get frustrated, experience takes time to develop, and if you haven't
    already, check out "Learning Perl" from O'Reilly (http://www.ora.com) it
    is an excellent resource (from what I have heard, would have been nice
    to know that 6 years ago ;-))

    Good luck....

    http://danconia.org
  • Rob Dixon at Feb 8, 2003 at 11:10 pm

    Dakenah Johnson wrote:
    Hi all,
    I am a novice to perl. I find Perl very interesting and I am studying
    how to write and compile perl scripts without syntax and compilation
    errors. I need heads up on how.
    Erm. That's a bit of a broad brief isn't it? I think I have to throw it
    back to you and say, "What problems are you having with syntax and
    compilation areas?".

    Except to say:

    use strict;
    use warnings;

    at the beginning of every Perl peogram!

    Cheers,

    Rob
  • R. Joseph Newton at Feb 9, 2003 at 1:33 am

    dakenah johnson wrote:

    Hi all,
    I am a novice to perl. I find Perl very interesting and I am studying how to
    write and compile perl scripts without syntax and compilation errors. I need
    heads up on how.

    thanks,
    DJ
    Hi DJ,

    You might want to re-think your emphasis here. Of ocurse, you need to eliminate these errors, but not by suppression. For instance, you can reduce the number of error messages vastly simply by removing the use strict; statement. Your code may then compile without explicit error. Unfortunately there is a good chance that it will not be doing what you think it is, or what you want.

    These errors, or to be more specific, the rules whose violation invokes the errors, are your friends. They will generally indicate an underlying logic error. If you suppress the error, the program will go ahead and run on broken logic. That's the sort of convenience that could toast a system.

    Perl is a syntactically tricky languiage. Because many of the operators are highly context-sensitive, a formulation that works very well in one place will not work at all in another.

    You definitely should have a basic reference. Randal Schartz's "Learning Perl" is considered the essential starter text, but has one major shortcoming in that it seems to constantly make external reference to Larry Wall's Programming Perl. This strikes me as a sort of sweetheart deal.

    As the others have told you, use strict and use warnings are a good place to start. These will force you to predeclare the scope and containment capacity of your variables. I personally would prefer that data type was also explicitly declared, but that's not the way Perl works. Most Perl users prefer the features that allow us to use the same variable to represent both a numerical value and its representation. As for me, it gives me the Willies--but I still use it.

    I suggest that you focus first on the logic--what you want to accomplish, what steps must be taken to do it, what values must be stored, accessed or manipulated. The language and its syntax are only a medium for communicating that logic, so don't worry about syntax errors until you see them. Then work on specific examples, since there is no blanket recipe for preventing them.

    One other tip--when you do start testing scripts, and you need jhelp with compiler errors, please mark the line numbers the error messages refer to. You may have to change code editors to find one that shows line numbers, but they are the most useful debugging information available to you or those helping you.

    Joseph
  • James Parsons at Feb 19, 2003 at 10:46 pm
    Ok here go's again.


    I have anywhere from 1 - 15 files in a directory, and I could have up to 5
    files with the same header record. and the rest have different header
    records. So what I would like to is

    read each file and when there's a match rename that file to something else

    example
    filea's header record = TORONTO then rename filea to File.001
    and when it reads fileb and it has the same header record then rename fileb
    to file.002..

    Is too simple for Perl?

    thanks
    James
  • Wagner, David --- Senior Programmer Analyst --- WGO at Feb 20, 2003 at 3:37 am

    James Parsons wrote:
    Ok here go's again.


    I have anywhere from 1 - 15 files in a directory, and I could have
    up to 5 files with the same header record. and the rest have
    different header records. So what I would like to is

    read each file and when there's a match rename that file to
    something else

    example
    filea's header record = TORONTO then rename filea to File.001
    and when it reads fileb and it has the same header record then
    rename fileb to file.002..

    Is too simple for Perl?

    thanks
    James
    Are you going to keep the renamed files in the same directory or
    different? I know you show filea to file.001, but will the files be in the
    format of file? and the rename files file.nnn?

    A little more info would be helpful.

    Wags ;)


    **********************************************************
    This message contains information that is confidential
    and proprietary to FedEx Freight or its affiliates.
    It is intended only for the recipient named and for
    the express purpose(s) described therein.
    Any other use is prohibited.
    ****************************************************************

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 8, '03 at 10:58p
activeFeb 20, '03 at 3:37a
posts6
users6
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase