Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

    Title:
    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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-09-22 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (179 votes), past polls