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!

In reply to Re: Perl not able to read file by thanos1983
in thread Perl not able to read file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.