You are looking at the HTML representation of the XML format.
HTML is good for debugging, but probably is not suitable for your application.
See complete documentation, or
API help for more information.
<?xml version="1.0"?>
<api>
<query-continue>
<allpages gapfrom="Sort by any order" />
</query-continue>
<query>
<pages>
<page pageid="9" ns="0" title="Regex quiz">
<revisions>
<rev xml:space="preserve">'''q1.pl'''
which is different ?
/"(.*)"/
/"([^"]*)"/
/"(.*?)"/
'''q1-b.pl'''
$line1='xx"yyy"x';
$line2='xx"yy"zz"x';
($a) = $line1 =~ /"(.*)"/;
($b)= $line1 =~ /"([^"]*)"/;
($c)= $line1 =~ /"(.*?)"/;
print " line1 = $a, $b, $c\n";
($a) = $line2 =~ /"(.*)"/;
($b)= $line2 =~ /"([^"]*)"/;
($c)= $line2 =~ /"(.*?)"/;
print " line1 = $a, $b, $c\n";
'''q2.txt'''
capture data into 2 variables- data after n until the next tab or the end and data after e
if there is e until the end
example:
'nxxxxxx\teyyyyyyyy'
$n=xxxxxx
$e=yyyyyyyy
or
'nxxxxxx'
$n=xxxxxx
$e=
'''q2.data'''
nxxxx eyyyyyy
nxxxxx
'''q2-a.pl'''
open IN,"q2.data";
while ($line=<IN>){
chomp $line;
my ($n,$e)= $line=~ //;
print "n=$n,e=$e\n";
}
'''q2-b.pl'''
open IN,"q2.data";
while ($line=<IN>){
chomp $line;
my ($n,$e)= $line=~ /[ne]([^\t]+)\t?/g;
my ($n,$e)= $line=~ /n([^\t]+)(?:\te([^\t]+))?/;
print "n=$n,e=$e\n";
}
'''q3.txt'''
capture data beween pairs of $$ with a letter after it, but if there is a single $ then it
is data
and not a separator
$a='AAAA'
$b='BBB$BB$BBB'
$c='CCCC'
or $array[1]='AAAA'
$array[2]='BBB$BB$BBB'
$array[3]='CCCC'
and there can be more...
'''q3-a.pl'''
$line='$$aAAAA$$bBBB$BB$BBB$$cCCCC';
@fields=$line=~//;
($a,$b,$c)=$line=~//;
print "@fields\n";
print"a=$a,b=$b,c=$c";
'''q3-b.pl'''
$line='$$aAAAA$$bBBB$BB$BBB$$cCCCC';
@fields=$line=~/\$\$\w((?:(?!\$\$).)*)/g;
print "@fields\n";
'''q4.txt'''
capture a number of unknown length in a text that follows ab or a but cannot have a c after it
example
ab123c or a123c
$num=''
ab123x or a123x
$num='123'
a1z or ab1 z
$num='1'
'''q4.data'''
xxxxab123cxxxx
xxxxab123xxx
xxxa12345xxxx
xxxxb123xxx
xxxa1234cxxxx
'''q4-a.pl'''
open IN,"q4.data";
while ($line=<IN>){
chomp $line;
print "line = $line\n";
($n)=$line=~/ab?(\d+)[^c\d]/;
print "n=$n\n";
}
'''q4-b.pl'''
open IN,"q4.data";
while ($line=<IN>){
chomp $line;
print "line = $line\n";
$line=~s/ab?(\d+)c//;
($n)=$line=~/ab?(\d+)/;
print "n=$n\n";
}
'''q5.txt'''
separate a line by commas. If there are quotation marks, take what is inside the quotes. If there is a comma inside quotes, it is a literal not a separator
example: "aaaa","bbb,bbbb",ccc,dddd
$a=aaaa
$b=bbb,bbbb
$c=ccc
$d=ddd
'''q5-b.pl'''
$a='"aaaa","bbb,bbbb",ccc,dddd';
@arr=$a=~//;
foreach (@arr){
print"***$_******\n";
}
[[Category:Sample code]]
[[Category:Quizzes]]</rev>
</revisions>
</page>
<page pageid="174" ns="0" title="Simple server with perl">
<revisions>
<rev xml:space="preserve">Run it and in another window, run:
<pre>
telnet localhost 2345
</pre>
<pre>
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket;
use Carp;
my $EOL = "\015\012";
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
my $port = shift || 2345;
my $proto = getprotobyname('tcp');
($port) = $port =~ /^(\d+)$/ or die "invalid port";
socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,
pack("l", 1)) || die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
listen(Server,SOMAXCONN) || die "listen: $!";
logmsg "server started on port $port";
my $paddr;
$SIG{CHLD} = \&REAPER;
for ( ; $paddr = accept(Client,Server); close Client) {
my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET);
logmsg "connection from $name [",
inet_ntoa($iaddr), "]
at port $port";
print Client scalar localtime;
print Client $EOL;
print Client "Hello there",$EOL;
}
</pre></rev>
</revisions>
</page>
</pages>
</query>
</api>