开发者

Perl, inline function for empty xml tag compression using DOM parser

I'm fairly new to perl and I'm using a perl DOM parser and there is an example of how to handle tag compression with empty elements that gives an example here:

 XML::DOM::setTagCompression (\&my_tag_compression);

 sub my_tag_compression
 {
    my ($tag, $elem) = @_;

    # Print empty br, hr and img tags like this: <br />
    return 2 if $tag =~ /^(br|hr|img)$/;

    开发者_StackOverflow中文版# Print other empty tags like this: <empty></empty>
    return 1;
 }

I understand why this is done, but I don't need anything this sophisticated, since I just want my function to return 1 all of the time. So my "my_tag_compression" sub would be written like...

 XML::DOM::setTagCompression (\&my_tag_compression);

 sub my_tag_compression
 {
    return 1;
 }

How would I, or is it possible, to do the above in one line?


you can write:

XML::DOM::setTagCompression( sub { 1; } );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜