--- zsdc <[EMAIL PROTECTED]> wrote: > *Please* CC the mailing list when you answer. I'm > writing it so everyone > on the list could learn something, not just to fix > your program or solve > your particular problem. >
thanks for the reminder zsdc - i should have remembered to cc the list when replying to you. > bis wrote: > > > Tnaks zsdc and JEGII. > > > > --- zsdc <[EMAIL PROTECTED]> wrote: > > > >>It gives a syntax error. Maybe try this: > >> > >> #!/usr/bin/perl -p > >> s/(\s)(.)/$1\u$2/g if/SCTN:/; > > > > This capitalises the first letter of every word in > the > > whole document. > > No, it doesn't. Only the lines containing "SCTN:" > Have you run it? yes i have run it and below is the kind of output i get (original input all lower case except capitalised tags and for SCTN: line which is mixed case): DOCB: SRCE: Marketing Week SCTN: Special Report:pRoMotIons And Incentives PGNO: 5 HDLN: What TEXT: This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces DOCE: DOCB: SRCE: Marketing Week SCTN: Special Report:pRoMotIons And Incentives PGNO: 5 HDLN: What TEXT: This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces This Is Text This Is Text This Is Text These Are Double Spaces DOCE: > > >>or instead of /SCTN:/ use /^SCTN:/ > > > > This doesn't do anything. > > > > or /^\s*SCTN:/ > > > > Nor does this. > > Well... Yes, it does. How did you run it, anyway? I have the script in the Perl/bin directory because it does not run if I have it anywhere else. Also I run it as #!/usr/bin/perl -w because #!/usr/bin/perl -p freezes my MS-DOS prompt. The original input is a file called test1.txt and the output is a file called test3.txt The whole program is as follows: #1. path to input and output file $inputfile = "C:/My Documents/Programming/Perl exercises/test/test1.txt"; $outputfile = "C:/My Documents/Programming/Perl exercises/test/test3.txt"; #2. filehandles open (INPUT, "$inputfile") || die "can't open $testfile"; open (OUTPUT, ">$outputfile") || die "can't open $testfile"; #initialise $text $text = ""; #3. read input file into $text while (<INPUT>){ $text = $text . $_; } # 4) split document by DOCE: string into array of tags @stories = split (/DOCB:/, $text); [EMAIL PROTECTED] is array of each story for (@stories){ # 5) general substitutions #Marketing Week substitutions if (/SRCE:\s*Marketing Week/i) { #put substitutions here s/(\s)(.)/$1\u$2/g if/SCTN:/; #uppercases everything # 6) now put back DOCE: tag into joined up array $text = join ("DOCB:", @stories) } # 7) now output file print OUTPUT $text; #close filehandles close (INPUT); close (OUTPUT); > > > I think the title of my query was misleading - > what I > > maybe should have said was "Uppercasing the first > > letter and lowercasing all the other letters of > every > > word in a mixed case part of a string"? > > This is much harder. It's easy to make the output > like this: > > I'Ve Been Reading O'Reilly Books > > OR: > > I've Been Reading O'reilly Books > > but not: > > I've Been Reading O'Reilly Books > > which is correct. I suggest you to only uppercase > characters, but if you > have to also lowercase the other ones then try: > > #!/usr/bin/perl -p > s/(\s)(\S+)/$1\L\u$2/g if/^\s*SCTN:/; > > or > > #!/usr/bin/perl -p > s/\b(\w+)/\L\u$1/g if/^\s*SCTN:/; > > (and maybe add: > > use locale; I get no result with any of this. > > at the beginning) and see which suits your needs > better. You might find > better examples in the Cookbook. Thank you. I'll take a look. -bis > > -zsdc. > ________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://uk.messenger.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]