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";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.