Perl Writing Variables to File

Associate
Joined
28 May 2008
Posts
346
In my perl program I have to write certain details to a file, I am using the code..

Code:
open (MYFILE, '>>myfile.txt');
    print MYFILE "Name: $sname $fname\n\n";

    close(MYFILE);

The entered name "Joe Bloggs" will be written as "Bloggs Joe"

Does any one know how I can edit my code so it writes the name like...

"BLOGGS_JOE"

Thanks :D
 
Well converting to uppercase is easy

$name =~ tr/a-z/A-Z/;
$fname =~ tr/a-z/A-Z/;

join the output together with a _
$output_name = join ('_',$name,$fname);

should be able to turn it into a one liner, but do your own homework ;)
 
Back
Top Bottom