Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

folding Data::Dumper output

by morgon (Priest)
on Dec 12, 2018 at 23:04 UTC ( #1227183=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

sometimes I have the problem of having to look at large Data::Dumper or json dumps.

With json I can simply load them into vim and with "foldmethod=syntax" I can easily fold them and so navigate easily the hierarchies of large documents.

Unfortunately I have yet to figure out how to fold Data::Dumper output in vim in a similar way.

Does someone have a tip here?

Many thanks and sorry for posting a question that may more pertain to vim than to perl...

Replies are listed 'Best First'.
Re: folding Data::Dumper output
by talexb (Canon) on Dec 13, 2018 at 05:51 UTC
Re: folding Data::Dumper output
by stevieb (Canon) on Dec 12, 2018 at 23:24 UTC

    No worries asking vim (or Emacs) questions related to Perl. If it's about Perl, you're loved. If it's about vi(m) you're also loved. If it's about Emacs, some will love you ;)

    I've never thought about wrapping output before. I wrap my subs in the following way in my .vimrc.

    function GetPerlFold() if getline(v:lnum) =~ '^\s*sub\s' return ">1" elseif getline(v:lnum) =~ '\}\s*$' let my_perlnum = v:lnum let my_perlmax = line("$") while (1) let my_perlnum = my_perlnum + 1 if my_perlnum > my_perlmax return "<1" endif let my_perldata = getline(my_perlnum) if my_perldata =~ '^\s*\(\#.*\)\?$' " do nothing elseif my_perldata =~ '^\s*sub\s' return "<1" else return "=" endif endwhile else return "=" endif endfunction setlocal foldexpr=GetPerlFold() setlocal foldmethod=expr

    I'm very curious to find out how this ends up. Never thought of having folds in a dumper output before.

    Please supply an example output so that there's something to test/work with. Preferably, within your OP so that everyone has a chance to see it.

      > If it's about Emacs, some will love you ;)

      talking about ... xD

      Activating cperl-mode and hs-minor-mode is all you need to be able to fold Perl data structures with hide-show commands.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: folding Data::Dumper output
by tybalt89 (Parson) on Dec 13, 2018 at 01:00 UTC

    Try

    foldmethod=indent

    and maybe switch to Data::Dump (or not).

    (Based on a simple fake structure.)

      Or maybe Data::Dump::Color :-) (I find colors generally helpful, plus the module produces other visual aids like: array index, hash key index, and depth indicator.)
Re: folding Data::Dumper output
by learnedbyerror (Monk) on Dec 16, 2018 at 18:56 UTC

    You may want to consider using another tool - Data::Printer is currently my favorite. Many years ago, almost a decade ago, I became frustrated with Data::Dumper and used Data::Dumper::PerlTidy when it first was released to CPAN. Since then, I have utilized a number of other modules that I will not list at this time. Data::Printer has been around for quite a while and is well supported. If you need need is formatting only, then its function p() and np() will likely cover your needs.

    Cheere, lbe

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1227183]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2019-08-21 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?