Re: Re: modifing and writing to a file (solved)

2003-07-24 Thread Ged
In case anyone else was following this, and for the search purposes in the archives, 
with the help on this list and the perldocs, I completed my program.


#!usr/bin/perl

# This program will change an original file(s) from lowercase to uppercase
# It will then write the mods to the original file and make a backup of the old one
# If you don't want a backup, assign a null string to $^I

if (@ARGV) {
$^I=".bk";
while (<>) {
print uc;
} 
} else {
print "Please enter file you wish to modify in the command line\n";
print "e.g. program.pl   \n";
}


Hopefully it may be of some use to somebody else starting out and stumbling in this 
area.



> 
> From: Ged <[EMAIL PROTECTED]>
> Date: 2003/07/24 Thu AM 08:47:23 GMT
> To: [EMAIL PROTECTED]
> Subject: Re: Re: modifing and writing to a file
> 
> ahhh, thanks. Yes, that makes sense now.
> 
> after reading up on the 'uc' function, I have now got my program to work as required.
> 
> Thanks to all for their input.
> 
> Ged.
> 
> > 
> > From: Sudarshan Raghavan <[EMAIL PROTECTED]>
> > Date: 2003/07/24 Thu AM 08:43:55 GMT
> > To: [EMAIL PROTECTED]
> > Subject: Re: modifing and writing to a file
> > 
> > NYIMI Jose (BMB) wrote:
> > 
> > >s/a-z/A-Z/g should be s/[a-z]/[A-Z]/g;
> > >
> > 
> > Character classes are only possible in the matching part of the regex, 
> > not in the replacement part. You regex says substitute all occurences of 
> > a lowercase alphabet with the string '[A-Z]'
> > 


-
Email provided by http://www.ntlhome.com/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Re: modifing and writing to a file

2003-07-24 Thread Ged
ahhh, thanks. Yes, that makes sense now.

after reading up on the 'uc' function, I have now got my program to work as required.

Thanks to all for their input.

Ged.

> 
> From: Sudarshan Raghavan <[EMAIL PROTECTED]>
> Date: 2003/07/24 Thu AM 08:43:55 GMT
> To: [EMAIL PROTECTED]
> Subject: Re: modifing and writing to a file
> 
> NYIMI Jose (BMB) wrote:
> 
> >s/a-z/A-Z/g should be s/[a-z]/[A-Z]/g;
> >
> 
> Character classes are only possible in the matching part of the regex, 
> not in the replacement part. You regex says substitute all occurences of 
> a lowercase alphabet with the string '[A-Z]'
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-
Email provided by http://www.ntlhome.com/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: modifing and writing to a file

2003-07-24 Thread Sudarshan Raghavan
NYIMI Jose (BMB) wrote:

s/a-z/A-Z/g should be s/[a-z]/[A-Z]/g;

Character classes are only possible in the matching part of the regex, 
not in the replacement part. You regex says substitute all occurences of 
a lowercase alphabet with the string '[A-Z]'



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: modifing and writing to a file

2003-07-24 Thread NYIMI Jose (BMB)
s/a-z/A-Z/g should be s/[a-z]/[A-Z]/g;

You also use uc function like this :
print BACKUP uc "$_";
#or
#print BACKUP uc ; 

C:\>perldoc -f uc
uc EXPR
uc  Returns an uppercased version of EXPR. This is the internal
function implementing the "\U" escape in double-quoted
strings.
Respects current LC_CTYPE locale if "use locale" in force.
See
the perllocale manpage. Under Unicode ("use utf8") it uses
the
standard Unicode uppercase mappings. (It does not attempt to
do
titlecase mapping on initial letters. See "ucfirst" for
that.)

If EXPR is omitted, uses "$_".


C:\>

-Original Message-
From: Ged [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 24, 2003 10:00 AM
To: [EMAIL PROTECTED]
Subject: modifing and writing to a file


Hi all,

I am very new to perl (2 days) but am finding it very rewarding. I have
however stumbled across a problem hopefully somebody can help me with.

I am trying to open a file, change the text from lowercase to uppercase
and rewrite it to a backup file. However, I only seem to be duplicating
the original file. Here is my code:

$stuff="c:/ged/perl files/stuff.txt";
$backup="c:/ged/perl files/stuff.bk";

open STUFF, $stuff or die "Cannot open $stuff for read :$!"; open
BACKUP, ">$backup" or die "Cannot open $backup for write :$!";

while () {
s/a-z/A-Z/g;
print BACKUP "$_";
}

can anyone see where I am going wrong.

Thanks,

Ged.

-
Email provided by http://www.ntlhome.com/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: modifing and writing to a file

2003-07-24 Thread Janek Schleicher
Ged wrote at Thu, 24 Jul 2003 08:00:04 +:

> I am very new to perl (2 days) but am finding it very rewarding. I have however 
> stumbled across a problem hopefully somebody can help me with.
> 
> I am trying to open a file, change the text from lowercase to uppercase and rewrite 
> it to a backup file. However, I only seem to be duplicating the original file. Here 
> is my code:
> 
> $stuff="c:/ged/perl files/stuff.txt";
> $backup="c:/ged/perl files/stuff.bk";
> 
> open STUFF, $stuff or die "Cannot open $stuff for read :$!";
> open BACKUP, ">$backup" or die "Cannot open $backup for write :$!";
> 
> while () {
>   s/a-z/A-Z/g;
   ^^

You meant tr instead.
(The substitution really changes all occurrences of the string "a-z" to
"A-Z".

>   print BACKUP "$_";

Please read
perldoc -q 'What\'s wrong with always quoting "$vars"'

> }

However, there is a shorter other way, as Perl has a builtin uppercase
function:

while () {
print BACKUP, uc;
}

Please read 
perldoc -f uc
for details.


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: modifing and writing to a file

2003-07-24 Thread Marcos . Rebelo
if you are new to perl try

perl -e "print uc($_) while (<>);" c:/ged/perl files/stuff.txt > c:/ged/perl
files/stuff.bk

-Original Message-
From: Ged [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 10:00 AM
To: [EMAIL PROTECTED]
Subject: modifing and writing to a file


Hi all,

I am very new to perl (2 days) but am finding it very rewarding. I have
however stumbled across a problem hopefully somebody can help me with.

I am trying to open a file, change the text from lowercase to uppercase and
rewrite it to a backup file. However, I only seem to be duplicating the
original file. Here is my code:

$stuff="c:/ged/perl files/stuff.txt";
$backup="c:/ged/perl files/stuff.bk";

open STUFF, $stuff or die "Cannot open $stuff for read :$!";
open BACKUP, ">$backup" or die "Cannot open $backup for write :$!";

while () {
s/a-z/A-Z/g;
print BACKUP "$_";
}

can anyone see where I am going wrong.

Thanks,

Ged.

-
Email provided by http://www.ntlhome.com/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



modifing and writing to a file

2003-07-24 Thread Ged
Hi all,

I am very new to perl (2 days) but am finding it very rewarding. I have however 
stumbled across a problem hopefully somebody can help me with.

I am trying to open a file, change the text from lowercase to uppercase and rewrite it 
to a backup file. However, I only seem to be duplicating the original file. Here is my 
code:

$stuff="c:/ged/perl files/stuff.txt";
$backup="c:/ged/perl files/stuff.bk";

open STUFF, $stuff or die "Cannot open $stuff for read :$!";
open BACKUP, ">$backup" or die "Cannot open $backup for write :$!";

while () {
s/a-z/A-Z/g;
print BACKUP "$_";
}

can anyone see where I am going wrong.

Thanks,

Ged.

-
Email provided by http://www.ntlhome.com/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]