Formatting the CURL output of a perl script

Hi, Dear Experts
I've made a simple script with two calls to the CURL command:


# open(FD_IN, "<STDIN") || die "Errore apertura standard input";

while (<STDIN>) {
	$Riga = $_;
	$Riga =~ s/\n//;
	$Riga =~ s/\r//;
	@Campi = split("\t", $Riga);

	system("curl -X POST  -H \"Content-Type: application/xml\" \"".$Campi[2]."/holdings/".$Campi[1]."/items/".$Campi[0]."?op=scan&library=PETFS&department=BIB1PETFSCATFLO&work_order_type=CATFLO&done=true&apikey=xxx\"\n");
	system("curl -X POST  -H \"Content-Type: application/xml\" \"".$Campi[2]."/holdings/".$Campi[1]."/items/".$Campi[0]."?op=scan&library=PETFS&circ_desk=DEFAULT_CIRC_DESK&done=true&apikey=xxx\"\n");


# close(FD_IN);

Open in new window

The script runs as:
I need a quick way -inside the script- for formatting the CURL output registered on output.txt

Thanks a lot,

fabiano petroneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
If the input file is homogeneous in form, use sed on it and process the whole thing at once.

If the input file is not homogeneous in form ...


do while (not EOF(inputfile))
  if (line should be reformatted) then
    reformat nextline;
  end if;
end while;

Open in new window

Run each line through sed, then write the reformatted lines.
fabiano petroneAuthor Commented:
Thanks for the answer
But I need a slice of code inside my script, something like:
system("curl -X POST  -H \"Content-Type: application/xml\" \""..... code to format the output of the preceding line, probably saved on a variable?

If you want to format the curl output before sending it to output.txt , you first need to capture that output in the script then format it as desired and then output it to the file.

To capture the output, you'll need to execute the curl command via backticks or the qx operator (or the appropriate module) instead of the system function.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.