Rosetta Code/Run examples: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: invert comparison)
m (→‎{{header|Perl 6}}: Tweaks, comments)
Line 298: Line 298:


die 'You can select local or remote, but not both...' if $local && $remote;
die 'You can select local or remote, but not both...' if $local && $remote;

## INITIALIZATION


my $client = HTTP::UserAgent.new;
my $client = HTTP::UserAgent.new;
Line 319: Line 321:


run('clear');
run('clear');

## FIGURE OUT WHICH TASKS TO RUN


if $run {
if $run {
Line 349: Line 353:
note "Skipping first $skip tasks..." if $skip;
note "Skipping first $skip tasks..." if $skip;
my $redo;
my $redo;

## MAIN LOOP


for @tasks -> $title {
for @tasks -> $title {
Line 368: Line 374:
say "Getting code from: http://rosettacode.org/wiki/{ $title.subst(' ', '_', :g) }#%l<language>";
say "Getting code from: http://rosettacode.org/wiki/{ $title.subst(' ', '_', :g) }#%l<language>";


my $header = %l<header>; # can't interpolate hash into regex
$entry = $page.comb(/'=={{header|' $(%l<header>) '}}==' .+? [<?before \n'=='<-[={]>*'{{header'> || $] /).Str //
$entry = $page.comb(/'=={{header|' $header '}}==' .+? [<?before \n'=='<-[={]>*'{{header'> || $] /).Str //
uh-oh("No code found\nMay be bad markup");
uh-oh("No code found\nMay be bad markup");


my $lang = %l<language>; # can't interpolate hash into regex
if $entry ~~ /^^ 'See [[' (.+?) '/' $(%l<language>) / { # no code on main page, check sub page
if $entry ~~ /^^ 'See [[' (.+?) '/' $lang / { # no code on main page, check sub page
$entry = $client.get("{ $url }/index.php?title={ uri-escape $/[0].Str ~ '/' ~ %l<language> }&action=raw").content;
$entry = $client.get("{ $url }/index.php?title={ uri-escape $/[0].Str ~ '/' ~ %l<language> }&action=raw").content;
}
}
Line 416: Line 420:


}
}

## SUBROUTINES


sub mediawiki-query ($site, $type, *%query) {
sub mediawiki-query ($site, $type, *%query) {