Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^6: Group __DATA__ lines in a while?

by Lady_Aleena (Curate)
on Nov 10, 2013 at 23:16 UTC ( #1061933=note: print w/replies, xml ) Need Help??

in reply to Re^5: Group __DATA__ lines in a while?
in thread Group __DATA__ lines in a while?

I just want you to know, I did it your way when I made a handful of additions. You were right about the elsifs spiraling out of control. Here is the updated version. :)

sub story { my ($source,$magic) = @_; my $tab = 3; my $inc = 0; my @sections; my @toc; while (my $line = <$source>) { chomp($line); next if !$line; if ($line =~ /^2/) { my ($number,$text) = split(/ /,$line,2); push @toc, anchor(textify($text), { href => '#'.idify($text) }); $inc++; } push @{$sections[$inc]}, $line; } $inc = 0; for my $section (@sections) { if ($section) { section($tab, sub { for my $line (@{$section}) { line($tab, $line), next if $line =~ /^</; line($tab, "<$line>"), next if $line =~ /^[bh]r$/; $magic->{$1}->(), next if $line =~ /^&\s+(.*)/; blockquote($tab, $1), next if $line =~ /^bq\s(.*)/; item($tab, $1), next if $line =~ /^\*\s(.*)/; item($tab, $2, { value => $1 }), next if $line =~ /^\*(\d+)\ +s(.*)/; heading($tab, $1, $2, { id => idify($2) }), next if $line + =~ /^([1-6])\s+(.*)/; paragraph($tab, $line, { class => 'author' }), next if $line + =~ /^by /; paragraph($tab, $line); } }); } if ($inc == 0 && @toc > 3) { section($tab, sub { my $class = @toc > 25 ? @toc > 50 ? 'four' : 'three' : 'two'; my $style = @toc > 50 ? 'font-size:smaller' : undef; list($tab, 'u', \@toc, { class => $class, style => $style }); }, { class => 'contents'} ); } $inc++; } # paragraph($tab,"written by $root_user", { class => 'author' }); }
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^7: Group __DATA__ lines in a while?
by hdb (Monsignor) on Nov 11, 2013 at 08:44 UTC

    Thanks for letting me know.

    Are these scripts called every time someone visits your website? Or are they part of the build process of the website?

    If your scripts get ever more complicated it might make sense to cache the resulting HTML files rather than generating them every time dynamically. The script could check whether the HTML file is older than the input file and only then generate output.

      Each script is loaded into the browser every time. Storing the HTML would be huge. I came to perl to make my site as teeny-weeny as possible, and I have succeeded. Since I don't have to store so much HTML (some inline elements remain to be coded out), my site has gone from 10 MB (the max allowed on one web server) to a mere 2.5 MB with a lot more content and data! All of those HTML tags take up a lot of space.

      No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
      Lady Aleena
        gzip, its for internet :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061933]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-06-23 10:51 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.