• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 116
  • Last Modified:

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
0
fabiano petrone
Asked:
fabiano petrone
1 Solution
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now