Hi Monks!
I am trying to read some file(s), get its size, and if the file(s) are larger than what I've declared in the variable $last_maxsize, delete over sized file content until it reaches the size specified. For some reason the code is deleting all the lines in the file(s) but the first line, the number in the $last_maxsize variable is just been ignored, can anyone help me on that?
Here is the piece of code doing that:

my $last_maxsize = 170000; #I need to delete original files here... open my $last_in, '<', "$path_only/$file_name" or die $!; { local $/ = \$last_maxsize; while ( my $new_record = <$last_in> ) { next if -s $new_record > $last_maxsize; open my $last_out, '>', "$path_only/$file_name" or die $ +!; #It should create the file(s) with a new size print $last_out $new_record; close $last_out or die $!; } close $last_in; }


Thanks a lot!

In reply to Delete On File Size 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.