Denham Eva wrote: > > Hello Listers, Hello,
> I am struggling to get this right. Beginner in perl, so please forgive > ignorance, but the regular expressions are confusing. > > I am trying to read in a file, with content as follows > ---snip--- > 1984 by George Orwell > A BEND IN THE RIVER by V.S. Naipaul > A CLOCKWORK ORANGE by Anthony Burgess > A DANCE TO THE MUSIC OF TIME (series) by Anthony Powell > A FAREWELL TO ARMS by Ernest Hemingway > A HANDFUL OF DUST by Evelyn Waugh > ---end snip--- > The idea is to list by Author ie. > > George Orwell - 1984 > V.S. Naipaul - A BEND IN THE RIVER > Anthony Burgess - A CLOCKWORK ORANGE > Anthony Powell - A DANCE TO THE MUSIC OF TIME (series) > Ernest Hemingway - A FAREWELL TO ARMS > Evelyn Waugh - A HANDFUL OF DUST > > OK my code thus far is:- > > --- Spin Code --- > open(INFILE,"books.txt")||die "Cann't Open"; > > while(<INFILE>) { > $_ =~ m/[A-Fa-z0-9]/ || die "Sorry Don't Work"; # Here regex is for > everything > # But I would like to chop it up to divide Authors from Books > # Then to add them together with:- print "$author - $Book" -:for instance > # In the end to write the output to a seperate file. > > $index = $_; > > print $index; > } > --- Close Code --- open INFILE, 'books.txt' or die "Cannot open 'books.txt': $!"; while ( <INFILE> ) { chomp; s/(.+?)\s+by\s+(.+)/$2 - $1/ print "$_\n"; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]