I've been reading about pipes all day, and I'm not sure if they are what I need or not, so I'm just going to ask this question and see what you bearers of wisdom would suggest.

I just want to setup a basic scenario of what I would like to be able to do (hopefully armed with knowledge of how to do this, I can just build on that for what I hope to do later).

There are two scripts: Main.pl and Child.pl

Main.pl has a variable called $contents. $contents gets information added to it as the script goes along, such as html that will later get outputted. So lets say in Main.pl we have:

$content .= qq~ <table> <tr><td> This is table cell one </td><td> This is table cell two </td></tr> </table> ~;

Now, without changing that script at all, I would like to change the contents of the $contents variable using Child.pl.
When $contents contains:

<table> <tr><td> This is table cell one </td><td>

But has not yet added the second table cell, I would like Child.pl to insert:

This is an inserted table cell </td><td>

Into the $contents variable in Main.pl

-----

In scenario #2, let's say we have some code being executed in Main.pl, such as:

open(FILE, "myfile.txt");
@file = <FILE>;
close(FILE);

open(FILE, ">myfile.txt")
print FILE @file;
print FILE "New line of date";
print FILE "\n";
close(FILE);

Now, while that code is executing, I would like Child.pl to add another print statement into the code while it executes, but without actually changing the Main.pl file. So what I'm looking to do is after Main.pl executes the command:

print FILE "New line of date";

But before it executes:

print FILE "\n";

I want it to do another print statement specified in Child.pl:

print FILE " - additional info from Child.pl";

I hope what I'm trying to do makes sense, and hopefully there is a fairly simple (or at least understandable) solution. Thanks for all your help and support.

- Dave


In reply to Inserting one script's info into another script's output by SleepyDave

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.