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

Hi,

I've been trying to write a configuration file with one string, but the string includes an whole object not just one line like the most configuration modules work:

host
host='example.com'
port='80'

But in my case it's a bigger object, this is how parse.pl looks like:

#!/usr/bin/perl my $p = Parse::BBCode->new({ tags => { '' => sub { my $e = Parse::BBCode::escape_html($_[2]); $e =~ s/\r?\n|\r/<br>\n/g; $e }, i => '<i>%s</i>', b => '<b>%{parse}s</b>', field => '<fieldset>%{parse}s</fieldset>', size => '<font size="%a">%{parse}s</font>', url => 'url:<a href="%{link}A">%{parse}s</a>', wikipedia => 'url:<a href="http://wikipedia.../?search +=%{uri}A">%{parse}s</a>', noparse => '<pre>%{html}s</pre>', quote => 'block:<blockquote>%s</blockquote>', code => { code => sub { my ($parser, $attr, $content, $attribute_fallb +ack) = @_; if ($attr eq 'perl') { # use some syntax highlighter $content = highlight_perl($content); } else { $content = Parse::BBCode::escape_html($$co +ntent); } "<tt>$content</tt>" }, parse => 0, class => 'block', }, hr => { class => 'block', output => '<hr>', single => 1, }, }, } ); 1;


and parse.pl is located in the dir: /var/www/board/parse.pl where my other forum scripts are running from, I know it's really simple but no internet resource could give me the answer please help me.

Greetings Pr0t0n

Replies are listed 'Best First'.
Re: BBCode Parser in configuration file
by CountZero (Bishop) on Jul 04, 2009 at 22:44 UTC
    YAML can save objects into a file:
    use strict; use YAML::Any; use DateTime; my $dt = DateTime->new( year => 1964, month => 10, day => 16, hour => 16, minute => 12, second => 47, nanosecond => 500000000, time_zone => 'Asia/Taipei', ); print Dump($dt);
    Output:
    --- !!perl/hash:DateTime formatter: ~ local_c: day: 16 day_of_quarter: 16 day_of_week: 5 day_of_year: 290 hour: 16 minute: 12 month: 10 quarter: 4 second: 47 year: 1964 local_rd_days: 717260 local_rd_secs: 58367 locale: !!perl/hash:DateTime::Locale::en_US default_date_format_length: medium default_time_format_length: medium en_complete_name: English United States en_language: English en_territory: United States id: en_US native_complete_name: English United States native_language: English native_territory: United States offset_modifier: 0 rd_nanosecs: 500000000 tz: !!perl/hash:DateTime::TimeZone::Asia::Taipei is_olson: 1 max_year: 2018 name: Asia/Taipei spans: - - -1.#INF - 59800434840 - -1.#INF - 59800464000 - 29160 - 0 - LMT - - 59800434840 - 61357104000 - 59800463640 - 61357132800 - 28800 - 0 - CT - - (... SNIP ...) - - 62474770800 - 1.#INF - 62474799600 - 1.#INF - 28800 - 0 - CST utc_rd_days: 717260 utc_rd_secs: 29567 utc_year: 1965

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Hmmm... yes read about that in a search, but I don't think that's gonna work for me because
      I can't use any of the variables of it in plain text 'cause that string is needed by this module:

      http://search.cpan.org/~tinita/Parse-BBCode-0.09/lib/Parse/BBCode.pm

      So I need that entire string from $p = Parse::BBCode-new();
      as an object and not in plain text, maybe I explain it wrong, if you follow that link
      you get BBCode parser I use.

      Hope you can help,
      Pr0t0n
        but I don't think that's gonna work for me
        Did you actually try it? You have to show some effort yourself.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: BBCode Parser in configuration file
by Mr. Muskrat (Canon) on Jul 05, 2009 at 14:06 UTC

    Why would you use Parse::BBCode to read a configuration file? That module is intended to turn BB code (as used in bulletin boards) into HTML or plain text.