sawoy has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
i have the following problem during creation my own source filter written as XS:

1. for checking that filter is only one applied for source code i do:
if ( av_len(PL_rsfp_filters) > 1 ) { warn("too many filters\n"); }
but this check doesn't work if i use perl script like:
#!/usr/bin/perl use myfilter; use otherfilter; ...
av_len(PL_rsfp_filters) is equal to 1 in this case!

2. i look at sources of perl and found that new filter is added to PL_rsfp_filters after call of filter_add() function.
so i moved my check code after call filter_add() in my module.
but this didn't help.

in result i have a question: what does PL_rsfp_filters contain ? all enabled filters? or something else ?
Thank in advance.

Replies are listed 'Best First'.
Re: PL_rsfp_filters - what does it contain ?
by Anno (Deacon) on Mar 16, 2007 at 12:31 UTC
    #!/usr/bin/perl use myfilter; use otherfilter;
    av_len(PL_rsfp_filters) is equal to 1 in this case!

    Yes, meaning there are two active filters. av_len(), despite its name, returns the highest index in the array, not the number of elements.

    Anno

      thanks, Anno!
      i search aroung PL_rsfp_filters but forget about av_len()
      as i see in sources number of array's elements is always (av_len() + 1). so i can use statement like:
      if ( (av_len(PL_rsfp_filters) + 1) > 1 )
      that is equal to already founded checking:
      if ( av_len(PL_rsfp_filters) > 0 )
        i search aroung PL_rsfp_filters but forget about av_len()

        Ah yes, that's known as an XY problem: You asked (first yourself, then the Perl Monks) about the content of PL_rsfp_filters (that's X), but your problem was understanding av_len() (Y). Good thing you mentioned av_len() in the body of your query. It might have been unanswerable otherwise.

        if ( av_len(PL_rsfp_filters) > 0 )

        Right, that checks for two or more filters. In view of the problem you had with the statement, it probably deserves a comment:

        if ( av_len(PL_rsfp_filters) > 0 ) { /* We only deal with a single filter */
        Anno

        Update: Identified X and Y in the XY problem