Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

What do you mean with "formatted text"? That you get a lot of spaces? That's because you have those spaces in your string values for 'body'. If you want a newline you must use \n as in your second example, Perl doesn't care about newlines you used to format the script in which you defined the data structure.

But there are some other issues here:

  • your array seems to contain hashes with a single key ('Body'). If there are no other keys then you don't want an array of hashes, you want an array of arrays but maybe that's just the case in your short exapmle here? Is it possible that 'Body' is the name of a workflow? In that case you want a hash of arrays
  • you probably don't want the formatting ()newlines, spaces) in your strings at all. A data structure should store data. formatting should be done at the point of consumption of the data structure. For exmaple: if you need to print the data structure as a list in HTML you want to wrap each element in list tags. If you want to dump it to the command line, you want to add newlines at the end of each string. Try to separate data from presentation. Feel free to ask if you need more details about this.
  • the actual strings ("1. Blah..") you are storing there represent an ordered list, therefore you should store them as an array, not one long string as you do now.
  • In short, I think this is what you should have:

    my %workflows = ( 'workflow1' => [ "first step", "second step", "third step" ], 'workflow2' => [ "first step", "second step", "third step" ], );
    Print a workflow to the command line:
    print "Workflow1 is:\n" . join("\n", @%{$workflows{'workflow1'}})."\n" +;
    I hope that helps to get you started - welcome to Perl!

    In reply to Re: Multiline Hash - how to get rid of formatting? by tospo
    in thread Multiline Hash - how to get rid of formatting? by klassisc

    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-02-22 13:42 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (293 votes). Check out past polls.