Link to home
Start Free TrialLog in
Avatar of fabiano petrone
fabiano petroneFlag for Italy

asked on

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
Avatar of Dr. Klahn
Dr. Klahn

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.
Avatar of fabiano petrone

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial