Obviously you should use an external module if you can. But having just spent the last few minutes writing the code, I'm going to post it here anyway :)
#!/usr/bin/perl use strict; use warnings; my $brand = shift || die "Must give a brand\n"; my %data; while (<DATA>) { chomp; next unless /^\[$brand\]$/ .. !/\S/; next if /^\[/; next unless /\S/; my ($k, $v) = split /\s*=\s*/, $_, 2; $data{$k} = $v; } foreach (keys %data) { print "$_ => $data{$_}\n"; } __END__ [NEWBRAND] #LOGIN FOR THAT PARTICULAR BRAND #Get the LOgin and Password according to Brand [AN] LOGIN = H006698 PASSWORD = $"?Y?? [AZ] LOGIN = H006699 PASSWORD = ???S? [CL] LOGIN = H007985 PASSWORD = 8?|?E?0 [CM] LOGIN = H006897 PASSWORD = $"?Y?? [CU] LOGIN = H006701 PASSWORD = $"?Y?? [GM] LOGIN = H006703 PASSWORD = 8?|?E?0
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: Read the values from a file
by davorg
in thread Read the values from a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |