test12.pl to HTML.

index -|- end

Generated: Sat Oct 24 16:35:30 2020 from test12.pl 2018/05/18 1.7 KB. text copy

#!/usr/bin/perl

use strict;
use warnings;

my $line = 'TARGETS = @STATIC_TARGET@ @SHARED_TARGET@';

sub prt($) { print shift; }

# split_space - space_split - 
# like split(/\s/,$txt), but honour double inverted commas
# also accept and split '"something"/>', but ONLY if in the tail
# 2010/05/05 - also want to avoid a tag of '"zlib">'
sub space_split {
   my ($txt) = shift;
   my $len = length($txt);
   my ($k, $ch, $tag, $incomm, $k2, $nch);
   my @arr = ();
   $tag = '';
   $incomm = 0;
   for ($k = 0; $k < $len; $k++) {
      $ch = substr($txt,$k,1);
        $k2 = $k + 1;
        $nch = ($k2 < $len) ? substr($txt,$k2,1) : "";
      if ($incomm) {
         $incomm = 0 if ($ch eq '"');
         $tag .= $ch;
            # add 2010/05/05 to avoid say '"zlib">' begin a tag
            if (!$incomm) {
                push(@arr,$tag);
                $tag = '';
            }
      } elsif ($ch =~ /\s/) { # any spacey char
            push(@arr, $tag) if (length($tag));
         $tag = '';
      } elsif (($ch =~ /\//)&&($nch eq '>')) { # 04/10/2008, but only if before '>' 24/09/2008 add this as well
         push(@arr, $tag) if (length($tag));
         $tag = $ch; # restart tag with this character
      } else {
         $tag .= $ch;
         $incomm = 1 if ($ch eq '"');
      }
   }
   push(@arr, $tag) if (length($tag));
   return @arr;
}

sub do_subs($) {
    my $line = shift;
    my @arr = space_split($line);
    my $cnt = scalar @arr;
    my ($i,$fnd,$rcs,$nval,$val);
    for ($i = 0; $i < $cnt; $i++) {
        $val = $arr[$i];
        if ($val =~ /^\@(\w+)\@$/) {
            $nval = $1;
            prt("$nval\n");
        } else {
            prt("$val\n");
        }
    }

}

do_subs($line);

# eof

index -|- top

checked by tidy  Valid HTML 4.01 Transitional