-4

Possible Duplicate:
Split with line with perl

My line:

producător: Carlo Ponti director de imagine: Piero Poletto monteur: Adriana Novelli Distribuţia: Faye Dunaway (Julia) Marcello Mastroianni (Valerion) Caroline Mortimer (Maggie)

I want to split in:

producător: Carlo Ponti 
director de imagine: Piero Poletto
monteur: Adriana Novelli
Distribuţia: Faye Dunaway (Julia) Marcello Mastroianni (Valerion) Caroline Mortimer (Maggie)

Number of lines may differ. I tried with Lookbehind Zero-Width Assertions:

split /(?=\S+:\s*)/, $line

If line containe more than one word (two or three or more) before colon ('director de imagine:' 'director of photography:' 'art director:' etc.) this split line in:

producător: Carlo Ponti director de
imagine: Piero Poletto
monteur: Adriana Novelli
Distribuţia: Faye Dunaway (Julia) Marcello Mastroianni (Valerion) Caroline Mortimer (Maggie)     
Community
  • 1
  • 1
user935420
  • 113
  • 1
  • 7

1 Answers1

2

You haven't given us any criteria on which to split the lines, except for these "headings", which appear arbitrary. With the exception of the last one, all of your headings also appear to be all lower-case.

I am therefore assuming that your headers will be static, and suggest the following:

$line =~ /producător: (.*?) director de imagine: (.*?) monteur: (.*) Distribuţia: (.*)/;
print "producător: $1\n";
print "director de imagine: $2\n";
print "monteur: $3\n";
print "Distribuţia: $4\n";

If you can provide more useful criteria for the split, I may be able to provide a better answer.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189