in reply to Re^2: Matching part of a line and saving it into a variable
in thread Matching part of a line and saving it into a variable

What is so difficult about showing us --say-- 10 relevant lines of your CSV file (including the header line, if any), so we can work on it? Is the data that secret and confidential?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

  • Comment on Re^3: Matching part of a line and saving it into a variable

Replies are listed 'Best First'.
Re^4: Matching part of a line and saving it into a variable
by mistamutt (Novice) on Mar 14, 2011 at 18:50 UTC

    Sorry, I was trying as much as possible to do it myself and following tips to try and learn. Thanks for helping thus far. Here are a few lines:

    "Barber Shop: NW, 147-2220, Washington 992,,,,, ,"Lawrence, Jerry A.",Buzz,,Clean,Cash,, ,"Wallace, Bob W.",Caesar,,High,Credit,, ,"Anthony, Ronald",Caesar,,Close,Cash,, ,"Nelson, Dwight R.",Buzz,,Clean,Check,, ,"Jamison, Jeff S.",Caesar,,High,Credit,, ,"Favors, Eric S.",Shave,,Skin,Cash,, ,"Williams, Herb C.",Fade,,High,Check,, ,"Carter, Shaun ",Caesar,,Low,Cash,,

    Once again, all I want to do is save the name into $last $first $mid A few people don't have middle initials though, so I'm not entirely sure how to handle that..

      What do you think of this?
      use Modern::Perl; while (<DATA>) { my ($last, $first, $mid) = /^,"([^",]+),\s([^\s"]+)\s?([^"]*)/; say "LAST: $last FIRST: $first MID: $mid" if $last; } __DATA__ "Barber Shop: NW, 147-2220, Washington 992,,,,, ,"Lawrence, Jerry A.",Buzz,,Clean,Cash,, ,"Wallace, Bob W.",Caesar,,High,Credit,, ,"Anthony, Ronald",Caesar,,Close,Cash,, ,"Nelson, Dwight R.",Buzz,,Clean,Check,, ,"Jamison, Jeff S.",Caesar,,High,Credit,, ,"Favors, Eric S.",Shave,,Skin,Cash,, ,"Williams, Herb C.",Fade,,High,Check,, ,"Carter, Shaun ",Caesar,,Low,Cash,,
      Output:
      LAST: Lawrence FIRST: Jerry MID: A. LAST: Wallace FIRST: Bob MID: W. LAST: Anthony FIRST: Ronald MID: LAST: Nelson FIRST: Dwight MID: R. LAST: Jamison FIRST: Jeff MID: S. LAST: Favors FIRST: Eric MID: S. LAST: Williams FIRST: Herb MID: C. LAST: Carter FIRST: Shaun MID:

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James