yitzle wrote:

Rob Dixon wrote:

yitzle wrote:

Don't shoot me!
I can't find enum on the perldocs. Perl does have an enum, right?
How do I go about making an enum? I basically want a bunch of
variables to equal subsequent values, eg 0, 1, 2, ...

Perl doesn't provide enum natively. But it's a solution to a
problem, so perhaps
you ought to tell us what the problem is instead of trying to
implement a C solution?

The "problem" is thus.
I an reading in data and using split to get it to an array.
Each element/column has a specific meaning, eg firstName, lastName etc
Rather than using [0], [1] I figured I could set up an enum($firstName, $lastName, etc) I suppose the alternative is to define (constant or variable) each index name manually.
Hm... Stupid me :)

  ($firstName, $lastName, etc) = (1 .. x);

Close enough to the enum :D (unless I messed up the range notation).
I guess that solves it.

BANG!

There's no need to assign names to array indices when you have Perl's hash
structure. Suppose your data is tab-separated, you could write:

my @data;

while (<>) {
 my %record;
 @record{qw(firstName lastName field3 field4)} = split /\t/;
 push @data, \%record;
}

or something similar. No need for C in a Perl program.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to