CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
what else to use for print for output

 



yasdel
Novice

Sep 10, 2010, 7:30 AM

Post #1 of 4 (1273 views)
what else to use for print for output Can't Post

Hi.

How can I output a integer (or string) in perl without using print command so I can fetch by ``?

Assume caller.pl calls prog.pl and the output of caller is required.

caller.pl
{

@a=`prog.pl ...`;
}

prog.pl
{

print $length;
}

In this exmple prog.pl output a $length variable that is caught by the caller. Can I use another command instead of print?


1arryb
User

Sep 10, 2010, 7:50 AM

Post #2 of 4 (1266 views)
Re: [yasdel] what else to use for print for output [In reply to] Can't Post

Hi yasdel,

In a word, "no". Backticks return the standard output of the executed command to the lvalue of the expression (which can be null). It's possible you could torture one of the open commands + redirection to do what you want. On the other hand, print statements aren't that hard. Why do you want to avoid using them?

Cheers,

Larry


yasdel
Novice

Sep 10, 2010, 8:00 AM

Post #3 of 4 (1265 views)
Re: [1arryb] what else to use for print for output [In reply to] Can't Post

ok Larry, I can explain you.

The reason for this request is just to avoid unnecessay printing information. But now I have a real problem. Please take a look at the code below. I would like to make a copy of the parsead[2] which is an integer and save it in a vector @numofAds for later use. In MATLAB it is very easy to do this. In Perl I cannot do that. What is wrong with my code and how I can correct it please?

@numofAds=(1..$nadxml-1);
for $i(0..$nadxml-1){

$data_fileIn=$resultad[$i];
$data_fileOut=">>/tsi/hadrien/deldjoo/Desktop/Stat/Adinventory.txt";
print "\n Processing Ad #", $i+1 , "\n" ;
@parsead=`perl Perl_XMLparsing.pl $data_fileIn`;
$numofAds=$parsead[2];

}

BR,
Yashar


1arryb
User

Sep 10, 2010, 8:36 AM

Post #4 of 4 (1256 views)
Re: [yasdel] what else to use for print for output [In reply to] Can't Post

Hi yasdel,

I haven't been following the saga of your Perl_XMLparsing.pl program closely, but in Perl, the list @numofAds
and the scalar $numofAds are completely different variables.

Perhaps you meant this line:

Code
$numofAds=$parsead[2];

to be:

Code
$numofAds[$i] = $parsead[2];

Cheers,

Larry


(This post was edited by 1arryb on Sep 10, 2010, 9:07 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives