in reply to read the whole folder files

Hello Perl monks, Thank you so much...both your suggestions resolved the issue. However, the output file is in the format as shown below:
meter_read energy_consumption n 00_1 34 n 00_2 53 n 00_3 121 n ... ... meter_read energy_consumption n 00_146 33 n .... ...
Isn't it a bit strange because while reading one file they get sorted into columns like below:
meter_read energy_consumption 00_146 33 00_1 34
And here they don't ? Plus the "n" i.e the \n newline command isn't supposed to show up is it?

Replies are listed 'Best First'.
Re^2: read the whole folder files
by Marshall (Canon) on Apr 10, 2012 at 07:26 UTC
    One way (of many) to parse the data would be like this:
    #!/usr/bin/perl -w use strict; use Data::Dumper; # this is a core module # no "installation" is required my $line = "meter_read energy_consumption n 00_1 34 n 00_2 53 n 00_3 1 +21\n"; # # this extracts number pairs and puts them into a hash # my %hash = $line =~ m/([\d_]+)\s+(\d+)/g; print Dumper \%hash; __END__ $VAR1 = { '00_2' => '53', '00_3' => '121', '00_1' => '34' };