in reply to Re^2: parse html for specific things
in thread parse html for specific things

Probably because it is not intended to be read by humans. JSON parsers will have no problem with lack of irrelevant white space, so why bother adding white space?
Yes, I fully appreciate that it doesn't matter for parsers. But, still, when I have to write some JSON or some HTML, I usually prefer to insert at least some vertical space (EOLs), because there is almost always a time somewhere in the future when I or another human will need to read the source or change it. My take on this is similar to what I do with Perl or C code: to make it friendly to the human reader. But I certainly understand your point that you may also need to optimize your document's size, especially if it's going to be transmitted zillions of times over a network which may sometimes be slow.

Replies are listed 'Best First'.
Re^4: parse html for specific things
by roboticus (Chancellor) on Dec 18, 2017 at 16:52 UTC

    Laurent_R:

    Yep, that's why my ~/bin directory contains json_prettify.pl:

    #!/usr/bin/perl # # json_prettify.pl <FName> # # Prettifies FName and writes it to FName.out # use strict; use warnings; use JSON; my $json = JSON->new->allow_nonref; while (my $FName = shift) { my $oname = $FName . ".out"; my $txt; { local $/; open my $FH, '<', $FName or die "no! $!\n"; $txt = <$FH>; } my $data = $json->decode($txt); $txt = $json->pretty->encode($data); open my $OFH, '>', $oname or die "No no no! $!\n"; print $OFH $txt; }

    I really need to make a thumb drive with my local ~/bin directory copied to it for when I visit other sites... ;^)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

        hippo:

        $ locate json_xs locate: warning: database ‘/var/locatedb’ is more than 8 days old (act +ual age is 12.3 days) C:/cygwin64\bin\json_xs C:/cygwin64\home\Roboticus\perl5\bin\cpanel_json_xs C:/cygwin64\home\Roboticus\perl5\man\man1\cpanel_json_xs.1 C:/cygwin64\usr\share\man\man1\json_xs.1.gz

        Nice! Now I don't have to bother. I hadn't noticed that I had a tool like that already installed. ;^)

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.