On Mon Nov 17 2008 @ 10:21, John W. Krahn wrote: > Set paragraph mode. > >> while (<>) { > > Read a paragraph into $_. In your example a paragraph is: > > " field:value > field:value > field:value > > " > >> my @fields = split /^([^:]+):\s*/m; > > Since there are multiple lines in a paragraph they use /^/m to work on > one line at a time. That pattern splits into three fields, the field > before '([^:]+):\s*', which will be '' for the first line, the field > enclosed in parentheses '[^:]+', and the field after '([^:]+):\s*'. > > >> shift @fields; > > The first field is always empty so remove it. > > >> push(@Array_of_Records, { map /(.*)/, @fields }); > > Store the fields as a hash at the end of @Array_of_Records. The filter > /(.*)/ ensures that no newlines are included in the keys or values of > the hash.
Thanks for your careful explanation. I was just in the process of writing that I had worked out that the map keeps newlines out. I'll push my luck and ask two further questions. First, what exactly is the "null field" at the start of my first line, or where does it come from? In the version you wrote of my data, you visualized it with a space, but it's not (normally) visible. (This may just be something very simple about computers and how they represent text that I don't know.) Second, if I know that my records only have newlines at the end of lines is there any larger advantage to using the map construct above instead of simply chomp @fields? (One advantage of chomp for me is that I'm in no danger of misunderstanding it later.) Thanks again, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/