in reply to Re: Parsing and adding to a "variable".
in thread Parsing and adding to a "variable".

I am using MySQL. When I create a newsletter using the system, when I hit submit, I have it first get the 'text', then parse it, adding it to paragraphs:
my $_content_to_add = param("content"); $_content_to_add = join '', map { "<p>$_</p>\n" } split /(?:\r?\n)+/, +$_content_to_add;
So now in the database, the paragraphs are in the correct tags.

I guess I could count them, but how can I count </p>\n<p> Entries in the text?

Thanks,
Richard

Replies are listed 'Best First'.
Re: Re: Parsing and adding to a "variable".
by Vautrin (Hermit) on Jan 24, 2004 at 15:12 UTC

    Just expand out that one line expression so that you're saving the value of the number of paragraphs (i.e. by putting it into an array before putting it into $_content_to_add). Or I suppose you could just try: my $number_of_paragraphs = scalar (split /(?:\r?\n)+/, $_content_to_add);.

      Most encouraging! Thank you Vautrin.... my $number_of_paragraphs = scalar (split /(?:\r?\n)+/, $_content_to_add); worked! It counted the number of pargraphs :o)

      Thanks again!!
      Richard
      Whoa there, don't do that. split in scalar context will indeed return the number you want, but will have the side effect of replacing the contents of your @_ array. This unfortunate behaviour has been deprecated and will give a warning.
        Well then, what do you suggest I do?

        I don't know which @_ array your reffering too. In this line of code, I'm not using any arrays, I don't think.

        Please expand upon your comments. I would appreciate it.

        thx,
        Richard