-1

I have a perl file which in turn calls another perl file. I am expecting output from second perl file. How would I get the output ? Here is what my sample code looks like.

datetimetest.pl

!/usr/bin/perl
use DateTime;
print DateTime->now()->strftime("%a, %d %b %Y %H:%M:%S %z");
print "\n";

my @perloutput = `/usr/bin/perl knowusername.pl`;
print "output:$perloutput[0]\n";
print "output 2: $perloutput[1]\n";

print "output 3: $perloutput[2]\n";

knowusername.pl

#!/usr/bin/perl
print $ENV{"LOGNAME"}."\n";

print "secondoutput\n";

print "thirdoutput\n";

I have edited answer above.

6
  • Take a look at this question: stackoverflow.com/questions/364842/… Commented May 30, 2013 at 8:24
  • @arkascha , how does that link help in my question ? I want to have output from one file to another file. Commented May 30, 2013 at 8:27
  • Sorry, did you even bother to read the first answer in that question? It is about script output to stdout and how to capture it. Commented May 30, 2013 at 8:28
  • You're missing the # in your shebang line. Most likely a copy-paste error. Otherwise, this works for me. Commented May 30, 2013 at 8:31
  • @arkascha, I did look at the first answer, but my question is how do I pass output ? The answer shows how to capture them, not to pass them. Commented May 30, 2013 at 8:34

1 Answer 1

1

First of all, always use use warnings; use strict;

Which would have caught your main issue here.

$output should be $perloutput

print "output:$perloutput[0]\n";
print "output 2: $output[1]\n";

print "output 3: $output[2]\n";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.