in reply to Perl not able to read file

Hello Anonymous Monk,

Fellow monks have provided you a solution to your problem. But why not use a module like File::Slurper that will do all the work for you in the background and possibly more efficiently also.

Take a look I think it will help you to minimize your errors/problems.

Update: I assume you want also to skip lines that do not have any valuable content, something like that?

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; use File::Slurper 'read_lines'; use Scalar::Util qw(looks_like_number); my @content = read_lines('in.txt'); print Dumper \@content; my @final; foreach my $line (@content) { $line =~s/\s+/ /g ; next if (looks_like_number($line)); push @final, $line; } print Dumper \@final; __END__ $ perl test.pl $VAR1 = [ '19760 Austria 7800 Kingsland 124 Petrie Ter +race', '19762 ', '19764 ', '19765 ', '19767 Austria 7864 Kingsland 1/249 Coronati +on Drive', '19768 ', '19770 Austria 7853 Kingsland Lawrence: 1 +03 Frasers Rd', '19771 ', '19775 Austria 7800 Kingsland 127 Edward Str +eet', '19777 ', '19779 ', '19780 Austria 7963 Kingsland 133 King Stree +t', '19782 ', '19784 ', '19785 ', '19787 ', '19789 ', '19791 Austria 7800 Kingsland Riverside Cent +re Level 29 123 Eagle Street', '19793 ', '19795 ', '19796 ', '19799 ', '67301 ', '67302 ', '67304 Austria 7810 Kingsland Argyle Office +Suit 9 20 Argyle Street', '67306 ', '67308' ]; $VAR1 = [ '19760 Austria 7800 Kingsland 124 Petrie Terrace', '19767 Austria 7864 Kingsland 1/249 Coronation Drive', '19770 Austria 7853 Kingsland Lawrence: 103 Frasers Rd', '19775 Austria 7800 Kingsland 127 Edward Street', '19780 Austria 7963 Kingsland 133 King Street', '19791 Austria 7800 Kingsland Riverside Centre Level 29 123 +Eagle Street', '67304 Austria 7810 Kingsland Argyle Office Suit 9 20 Argyle + Street' ];

Then simply use File::Slurper/write_text($filename,_$content,_$encoding,_$crlf) and put your data into a file instead of my array that I placed in the code for demonstration purposes.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!