Hello Monks!

This is the first time I write something here. Mostly I found solutions in documentations, existing entries here or platforms like stackoverflow.

This time I wasn't able to find a similar problem anywhere, so I decided to ask myself.
(There may be already the question answered anywhere I have, but I didn't get it, it was the same problem.)

foreach my $file ( @files ) { open(my $fh, ">>", $file->{full_path}); # or return(0); print $fh $file->{content}; close($fh); # or return(0); chmod(0755, $file->{full_path}); print "Created \"$file->{full_path}\" with $file->{line_counte +r} line" , ( $file->{line_counter} > 1 ) ? "s" : "" , "\n"; }
When this part of code is executed it tells me
print() on closed filehandle $fh at ./Make.pl line 223. Can't open perl script "../Path/to/file.pm": File or directory not fou +nd

First I didn't get it, because the returns just omitted writing the next files.
How can I do multiple open within the foreach, without print() failing?

I feel as if the open() wasn't executed every time as I expected
The loop is executed within a subroutine.


In reply to foreach a writing open fails through not found file by DomX

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.