Embedding evaluations in Perl regex

前端 未结 6 1840
猫巷女王i
猫巷女王i 2021-01-05 00:05

So i\'m writing a quick perl script that cleans up some HTML code and runs it through a html -> pdf program. I want to lose as little information as possible, so I\'d like t

6条回答
  •  逝去的感伤
    2021-01-05 00:48

    The (?{...}) pattern is an experimental feature for executing code on the match side, but you want to execute code on the replacement side. Use the /e regular-expression switch for that:

    #! /usr/bin/perl
    
    use warnings;
    use strict;
    
    use POSIX qw/ ceil /;
    
    while () {
      s[] {
        my $rows = ceil(length($3) / 80);
        qq[];
      }egis;
      print;
    }
    
    __DATA__
    
    

    Output:

提交回复
热议问题