in reply to Read the values from a file
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read the values from a file
by Anonymous Monk on Aug 23, 2004 at 17:12 UTC | |
|
Re^2: Read the values from a file
by Anonymous Monk on Aug 27, 2004 at 02:54 UTC | |
by davorg (Chancellor) on Aug 27, 2004 at 09:10 UTC |