See inline comments
> -----Original Message-----
> From: Bob H [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 22, 2002 11:12 AM
> To: [EMAIL PROTECTED]
> Subject: UPPERCASE and DOING MULTIPLE THINGS
>
>
> I have a script that is *supposed* to search a file and make certain
> words that I have in an array uppercase. My brain is not grokking it.
>
> Q1: What is wrong with my script (below)?
> Q2: Can I update a file in place?
> Q3: How do I run multiple things against one file in one script?
>
> === SCRIPT ===
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> # variables
> my $word = undef;
>
> # setup the words to uppercase
> my @words = qw/ Mary John Joe /;
#you want to use pattern matching like this:
my @words = map qr/$_/i, qw/ Mary John Joe /;
>
> open FILE, ">> NEW1 " or die "can't open FILE: $!";
>
> while (<>) {
> foreach $word (@words) {
> $word = ~ tr /a-z/A-Z/;
> print FILE;
> }
# this whole foreach just changes the words in the array not the file.
# note that you are also reading in from stdin.
# to fix do this
foreach $word (@words){
s/ ## substitute in current line,
($word) # match $word (Mary) case-insenstive,
/ # and replace
uc($1) # with uppercase of same word.
/gex; # g = globally (throughout line as many times), e =
eval right side (uc($1)), x = ignore whitespace and comments
}
print FILE; # print to file after all @words are changed in line
> }
>
> # close the file
> close (FILE);
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]