in reply to Re^3: Text file processing question
in thread Text file processing question

What if more than one field contains multiple words ?

In fact now i have multiple words in more than one field:
Nancy Drew Elm Street 600.00 New service Single Stella Barry Pine Avenue 1000.00 Replacement Single Julie Green Palm Street 400.00 Replacement Three Debbie Brown Baker Avenue 800.00 New service Three
perl_seeker

Replies are listed 'Best First'.
Re^5: Text file processing question
by BrowserUk (Patriarch) on Dec 09, 2009 at 12:45 UTC
    #! perl -slw use strict; print "Name of consumer Subdivision Amount Type of work Phase"; printf "%-14s %14s %7.2f %-14s %-s\n", m[(\S+\s\S+)\s+(\S+\s\S+)\s+(\S+)\s+(.+)\s+(\S+)$] while <DATA>; __DATA__ Nancy Drew Elm Street 600.00 New service Single Stella Barry Pine Avenue 1000.00 Replacement Single Julie Green Palm Street 400.00 Replacement Three Debbie Brown Baker Avenue 800.00 New service Three
      Excellent, thank you very much :)

      perl_seeker
      The re appears not to work for this set of data: i.e if each field can have single words/multiple words except the amount field
      Nancy Elm Street 600.00 New service Single phase Stella Barry Petersburg 1000.00 Replacement Single Julie Palm Street 400.00 Replacement Three phase Debbie Brown Bakerville 800.00 New service Three
      perl_seeker

        #! perl -slw use strict; print "Name of consumer Subdivision Amount Type of work Phase"; printf "%-14s %14s %7.2f %-14s %-s\n", m[ ( \S+ (?: \s \S+ )? ) \s+ ( \S+ (?: \s \S+ )? ) \s+ ( [0-9\.]+ ) \s+ ( \S+ (?: \s \S+ )? ) \s+ ( \S+ (?: \s \S+ )? ) $ ]x while <DATA>; __DATA__ Nancy Elm Street 600.00 New service Single phase Stella Barry Petersburg 1000.00 Replacement Single Julie Palm Street 400.00 Replacement Three phase Debbie Brown Bakerville 800.00 New service Three

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.