in reply to Re: get array number
in thread get array number

Hi Scott,

Thanks for your feedback. The problem is that i might not know what array "Postcode" is and the sequence in the file might not be in orders e.g. it can be Postcode;Name;Address2;Address3;.....

I still need to know postcode or other value is in which array. Is there any way to do it?

Thanks...

Replies are listed 'Best First'.
Re^3: get array number
by Sioln (Sexton) on Jan 20, 2006 at 08:55 UTC
    You wrote:
    I still need to know postcode or other value is in which array. Is there any way to do it?
    Of course there is some way :) We know that postcode is consists of numbers only, name does not include any number, and adress is words & numbers.
    So.. that is draft code for You.
    my @file; $file[0]="Alexey;123456789;USA some state some street home # 12\n"; $file[1]="20102020;Nikola;Russian Federation some state some street ho +me # 13\n"; $file[2]="England some state some street home # 14;5545487987;Max\n"; my @sorted_values; foreach $file_string(@file){#like your while(<>) chomp $file_string; my @string_values=split/;/,$file_string; my $sorted; foreach (@string_values){ if (/\D/ && !/\W/ ){#This is name $sorted->{NAME}=$_; }elsif(/\D/ && /\W/){#This is adress $sorted->{ADRESS}=$_; }else{#This is postcode $sorted->{POSTCODE}=$_; } } push @sorted_values, $sorted; } foreach (@sorted_values){ print "NAME: $_->{NAME} ADRESS: $_->{ADRESS} POSTCODE: $_->{POSTCODE} +\n"; }
Re^3: get array number
by helphand (Pilgrim) on Jan 20, 2006 at 06:34 UTC

    Provided you know the field names in advance, then ikegami's solution will work perfectly for you.

    Scott

Re^3: get array number
by smokemachine (Hermit) on Jan 20, 2006 at 07:50 UTC
    how do you know whose fild is the postcode? on the file have any way to know, cant you organize the file? sorry about my english...