#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Stuck w perl script


    []
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    This is a homwork assignment, please don't ask us to debug your entire program.

    Pleas etell us where you are stuck, or what goes wrong when you compile and/or run your program.

    A couple of advice.

    Put the following lines near the top of each of your Perl programs:

    Perl Code:
    use strict;
    use warnings;


    They will help you considerably finding errors or faulty constructs.

    Don't call function with this obsolete syntax:

    Code:
    &task_number2;
    Rather use:

    Code:
    task_number2 ();
    Also, please the code tags for your code, this makes your code more readable and prevents your regex:

    if($x=~m/(\d+)\d+)\d+)\d+)\d+)(\d+)\d+)\d+)/)

    from looking really sad.
    Last edited by Laurent_R; May 25th, 2013 at 10:55 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Whenever I see args such as -n, -t, -v etc I would use the Getopt::Long module to handle the parsing of the args rather than manually parse @ARGV.

    Additionally, I'd write a separate subroutine to handle each of the actions and use a dispatch table to determine which sub to execute. The subroutine names should give an indication of what they do. Names such as "task_number2" and "task_number4" are very poor choices.

    Since you're being given exact widths for each field of the lines in the source file, that tells us that you have a fixed width file format and normally the best way to parse/extract those fields is to use the unpack function instead of a regex. If required, you can apply validation tests on some or all of the fields after using unpack.

IMN logo majestic logo threadwatch logo seochat tools logo