in reply to Re^2: Insert blank rows in a CSV
in thread Insert blank rows in a CSV

Perhaps part of the confusion is that runnig's approach is to make a new copy of the file, adding some lines to the output stream at the appropriate places and then rename the new file to the original file name. So, the original file is not being edited in place, but a wholly new copy of the data is being made into a different file. When the new file is renamed to the orignal file name, it "becomes" the original file and the contents of the original file are automatically deleted (or, if you use the -i command line switch, the old file is renamed to another name so you can go back to it if necessary.)

One nice property of this approach is that if your script bombs in the middle, you still have the original contents around. So, I hope this explains why you don't have to "reserve" space in your original file for the added content.

On the other hand, if you want your original file to actually look like:

<---Start of the CSVFILE -----------------------------> <--Here goes a image ---------------------------------> <--Here goes a blank row -----------------------------> <--Here goes the header ------------------------------> 123456 123 john 9393939 data data 123456 123 john 9393939 data data 123456 123 john 9393939 data data 123456 123 john 9393939 data data 123456 123 john 9393939 data data
and you want the script to replace
<--Here goes a image --------------------------------->
with something, then that's a different problem, but you can still use the same idea:
while (<>) { if (m/^<--Here goes a image.../) { print ...whatever... } else { print; } }
Use the above code with the -i option to use perl's file editing feature. If the rows you want to replace are blank, then just use line numbers as the matching criteria:
while (<>) { if ($. == 2) { print ...image csv line... } else { print; } }