A processing instruction for robots

Robert Hanson rhanson at blast.net
Tue Dec 7 19:03:24 GMT 1999


> I'm open to changing this, but I thought I would start
> with the most strict version. The advantage of the strict
> version is that it doesn't need to be parsed.

> The Desparate Perl Hacker can do four regex compares
> for the four variants and get back to work.

I guess that depends on how "desparate" they are.  It is relatively easy to do
no matter what order the attributes are.  I would suggest not specifying an
order unless you can think up a better reason for keeping it.

Below is sample code with the output...  (notice the 8 examples with varying
attribute orders an values... but only 2 regexes).

----------------------------------
# Tested Perl code
my @examples = (
 '<?robots index="yes" follow="yes"?>',
 '<?robots index="no"  follow="yes"?>',
 '<?robots index="yes" follow="no" ?>',
 '<?robots index="no"  follow="no" ?>',
 '<?robots follow="yes" index="yes"?>',
 '<?robots follow="no"  index="yes"?>',
 '<?robots follow="yes" index="no" ?>',
 '<?robots follow="no"  index="no" ?>'
 );

foreach my $ex1 ( @examples )
 {
 if ( $ex1 =~ /<\?robots((?:\s+(?:index|follow)="(?:yes|no)"){2})\s*\?>/ )
  {
  my %tmp;
  while ( $ex1 =~ /\s+(index|follow)="(yes|no)"/g )
   {
   $tmp{$1} = $2;
   }
  print "Follow: $tmp{follow}  Index: $tmp{index}\n";
  }
 }

==== OUTPUT ====
Follow: yes  Index: yes
Follow: yes  Index: no
Follow: no   Index: yes
Follow: no   Index: no
Follow: yes  Index: yes
Follow: no   Index: yes
Follow: yes  Index: no
Follow: no   Index: no
===============




xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)





More information about the Xml-dev mailing list