are there structures in Perl??

I am a new Perl programmer tho I do know C/Win32 HTML and some Java(script). I volenteered to be teh Webmaster for my BSA troop(Im 15, and no I'm not a scriptkiddie nor have I EVER typed 13373) without knowledge of the fact that the whole thing is in PERL. Fortually the old Webmaster set up a very easy updating mechanisms but its limited and I like to know whats going on behind the scenes. Anyways The one thing I want to do is resort the rooster and I thought it would be easier and more logical to use structures then several arrays like you would in C. But it never mentions structures in my book and I was wondering if such a thing existed or something similar. Thanks for any help in advance and sorry for my rambling.


  • yes yes, you can use structures in perl. although i dont think you would need to use them for sorting items since perl allows you to write sort subroutines, which dictates how items are to be sorted. anyway, here is an example of how to make and use structures using the standard Class::Struct module.

    use Class::Struct;

    #create structure definition
    #num is a scalar as is den
    struct Fraction => { num => '$', den => '$'};

    my $f = Fraction->new();

    $f->num(1); #put 1 in the numerator
    $f->den(2); #put 2 in the denominator
    #this creates a fraction which is equivilant to one half

    #retrieve and print values from the structure
    printf "The value of the fraction is: %d/%d", $f->num, $f->den;


    this may or may not help much. what i think you really want is a sort subroutine, which may prove to be much easier and much faster. either way will work, but what i think you are trying to do is write c code in perl, which isnt the best idea. now ill stop being a dick and wish you the best in your perl coding. hope i have been of some assistance. come back soon.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion