aelmore has asked for the wisdom of the Perl Monks concerning the following question:
HI all: I've inherited this project and haven't used Perl or CGI in a decade, and even then my knowledge was rudimentary.
This script is supposed to run two CURL commands:
1) First, pull all page ID's and comma separate them.
2) Take ID array, feed them into $id, run curl command to pull page content, and then exports them into an individual HTML file.
It's doing the first part, but only dumping the page ids into the html files. Where is it breaking?
The code with variables redacted:
my $base_url = 'https:// my $user = my $pass = ; #folder change my $out_dir = 'pages'; #format change my $format = 'html'; #pulls all ID's my $out = `curl -u $user:$pass -i $base_url/file/root/tree?format=ids` +; #regex saying any number with a comma after it $out =~ /.+\s*([\d,]+)$/; #separate each id by comma my @ids = split /,/, $1; #pull pageid array, create separate HTML file with page contents foreach my $id (@ids) { print "$id\n"; #passes array into $id and makes curl command to get HTML content. my $json = `curl -u $user:$pass -i $base_url/files/$id/contents?fo +rmat=$format`; $json =~ /^.+\r\n\r\n:?(.+)$/s; my $contents = $1; open(FILE, ">$out_dir/$id.$format") or die "can't open file for $i +d: $!"; print FILE "$contents\n"; close FILE; }
I'm sure it's an easy fix, but my Perl skills are lacking. Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Exporting Curl content to html
by choroba (Cardinal) on Jan 26, 2016 at 16:08 UTC | |
by aelmore (Initiate) on Jan 26, 2016 at 18:25 UTC | |
|
Re: Exporting Curl content to html
by aelmore (Initiate) on Jan 26, 2016 at 18:37 UTC | |
by poj (Abbot) on Jan 26, 2016 at 20:47 UTC | |
|
Re: Exporting Curl content to html
by Anonymous Monk on Jan 26, 2016 at 19:42 UTC |