http://qs1969.pair.com?node_id=484443


in reply to detecting pod in files?

I wouldn't call it easyer but at the first detection of a pod directive I would set the flag an bail out of the loop instead of searching the rest of the file. It is also posible that a file will not contain '=pod' but still have pod in it. I would use something like this:
my $file = '/tmp/file'; open(IN, "<$file") or die "$0: cannot read file '$file': $!"; my $pod = 0; while (<IN>) { $pod = 1, last if /^=\w/ } #/^=(pod|head\d|over|item|back|cut)/ might be more accurate #=begin, =end, and =for are ommited because they would #usualy be ignored by pod2* close(IN); pod2html($file) if $pod;

Replies are listed 'Best First'.
Re^2: detecting pod in files?
by brian_d_foy (Abbot) on Aug 17, 2005 at 17:17 UTC

    You can't do it this simply. Although a pod directive starts at the beginning of a line with an =, that has to happen when Perl isn't expecting something else. (Curiously, BBEdit gets this wrong too).

    # this isn't pod $time =time ;
    Or
    $string =<<"HERE"; =value =item HERE

    You can can't just look for a particular pod directive (such as =pod, in the original post, because it might not show up. Indeed, I have rarely used =pod.

    There are plenty of Pod modules, so use those instead of rolling your own. :)

    --
    brian d foy <brian@stonehenge.com>