Formatting the CURL output of a perl script

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

#!/usr/bin/perl

# 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\" \"https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs/".$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\" \"https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs/".$Campi[2]."/holdings/".$Campi[1]."/items/".$Campi[0]."?op=scan&library=PETFS&circ_desk=DEFAULT_CIRC_DESK&done=true&apikey=xxx\"\n");

	$cntRecord++;
}

# close(FD_IN);

Open in new window



The script runs as:
perl script.pl<input.csv>output.txt
I need a quick way -inside the script- for formatting the CURL output registered on output.txt

Thanks a lot,

Fabiano
fabiano petroneAsked:
Who is Participating?

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

x
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 ...

Pseudocode:

openforread(inputfile);
openforwrite(outputfile);
do while (not EOF(inputfile))
  get(nextline,inputfile);
  if (line should be reformatted) then
    reformat nextline;
    write(nextline,outputfile);
  end if;
end while;
close(inputfile);
close(outputfile);

Open in new window


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

Thanks,
Fabiano
0
FishMongerCommented:
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.
0

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
Perl

From novice to tech pro — start learning today.