On 11/14/2012 05:45 PM, Charles DeRykus wrote:
On Wed, Nov 14, 2012 at 9:05 AM, jet speed <speedj...@googlemail.com> wrote:
Hi
Is there a way, i can build an %hash from a file as Input. Appreciate you
help with this.
file.txt
----------------
22:5a => 10.00.00.00.aa.56.9b.7a
32:9c => 10.00.00.00.aa.46.9b.33
a2:cc=> 10.00.00.00.aa.5a.9b.63
Assuming no anomalies/surprises in file.txt:
use File::Slurp;
use strict;
use warnings;
my @lines = read_file( 'file.txt', chomp=>1 );
my %hash = map { split( /\s*=>\s*/,$_ ) } @lines;
i didn't want to jump in with slurping but since you broke the ice
already i will. that can be even shorter as there is no need for the
map, chomp or array (untested):
my %hash = read_file( 'file.txt' ) =~ /^(.+)\s*=>\s*(.+)$/mg ;
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/