in reply to Re: Perl record types
in thread Perl record types

Why not just:
use constant FILE_NAME => 3; # ... unless ( -d $parms[FILE_NAME] ) { # # do some ftp stuff here. # }
Gives you compile-time checks and has all the advantages of the hash solution.

Replies are listed 'Best First'.
Re^3: Perl record types
by dwm042 (Priest) on Jan 18, 2008 at 19:33 UTC
    plobsing, your suggestion improves readability, but the code is still directly tied to the data file and its internal representation. Consider this scenario:

    1. You write a piece of code tied to the data representation.

    2. You leave the company.

    3. It becomes very popular.

    4. Dozens of people want to use it, but they want to each make lots of small changes to the data representation. Rather than rewriting the code to handle all cases, they cut and paste unique versions of the code and change the constant mapping to fit their unique cases.

    And all I'll say is, I've been there, at step 5, when someone gets asked to refactor all those scripts into 1 script.

    So I beg to differ: as long as your code is tied directly to data representation, it isn't as good as indirect solutions, where the representation can be modified without affecting running code.

    Update: typo fix