Perl打印正则表达式从数组匹配到html

时间:2016-04-12 14:57:35

标签: html regex perl

我在perl中有以下代码,它将数组的每个值输出到新的HTML表格单元格和表格行

tt[, ff := .(list(approxfun(c(t0,t1,t2), c(y0,y1,y2)))), by = Date]
#         Date t0 t1 t2 y0  y1 y2         ff
#1: 2000-01-01  1  2  3 10 -20 33 <function>
#2: 2000-01-02  2  3  4 20 -30 44 <function>

stocks[tt, y.approx := ff[[1]](t), on = 'Date', by = .EACHI]
stocks
#   Ticker       Date   t y.approx
#1:     xx 2000-01-01 1.8      -14
#2:     xx 2000-01-02 3.5        7
#3:     yy 2000-01-01 1.8      -14
#4:     yy 2000-01-02 3.5        7

数组的内容如下:

$scope.tableParams.reload();

我想在|之前打印所有内容在第一个表格单元格中,然后是|之后的所有内容在该行的第二个表格单元格中

我认为我需要使用正则表达式:

SET NOCOUNT ON

SELECT name, 
       comment, 
       hrs, 
       CONVERT(varchar(20), timestamp, 120) AS timestamp, 
       DATEADD(day, - DATEPART(weekday, timestamp), timestamp) AS Week_Start, 
       CONVERT(varchar(10), DATEPART(ww, DATEADD(dd, 0, timestamp))) AS WeekNo
INTO #TempTableName
FROM Tablename 
WHERE MONTH(timestamp) = '$month'
and YEAR(timestamp) = '$year'
order by wk

while ((select count(*) from #TempTableName) > 0)
begin
    select top 7 * from #TempTableName
    delete top (7) from #TempTableName
end

只是不确定在一行中打印这个的确切语法

2 个答案:

答案 0 :(得分:6)

这真的很简单

use strict;
use warnings 'all';

my @data = qw/
    APPLE|0
    ORANGE|0
    PEAR|1
    GRAPE|0
    TOMATO|1
/;

print "<table>\n";
printf "    <tr><td>%s</td><td>%s</td></tr>\n", split /\|/ for @data;
print "</table>\n";

输出

<table>
    <tr><td>APPLE</td><td>0</td></tr>
    <tr><td>ORANGE</td><td>0</td></tr>
    <tr><td>PEAR</td><td>1</td></tr>
    <tr><td>GRAPE</td><td>0</td></tr>
    <tr><td>TOMATO</td><td>1</td></tr>
</table>

答案 1 :(得分:-1)

您可能需要以下内容:

#!/usr/bin/perl
use strict;
use warnings;


my @names = ("APPLE|0", "ORANGE|0", "PEAR|1", "GRAPE|0", "TOMATO|1");

foreach my $n (@names) {
while ($n =~ m/(.*?)\|(\d+)/g) {
        print "<tr><td>$1<br/></td></tr>\n";
        print "<tr><td>$2<br/></td></tr>\n";
    }
}

<强>输出:

<tr><td>APPLE<br/></td></tr>
<tr><td>0<br/></td></tr>
<tr><td>ORANGE<br/></td></tr>
<tr><td>0<br/></td></tr>
<tr><td>PEAR<br/></td></tr>
<tr><td>1<br/></td></tr>
<tr><td>GRAPE<br/></td></tr>
<tr><td>0<br/></td></tr>
<tr><td>TOMATO<br/></td></tr>
<tr><td>1<br/></td></tr>

<强>样本:

http://ideone.com/QPOvzd