Link to home
Start Free TrialLog in
Avatar of swinfosec
swinfosec

asked on

file conversion in perl

I am taking an input file with a list of names. then for every occurence of Clark Kent, I am switching it with SUPERMAN!!!. I have some simple code below. where am i going wrong?
#!/usr/bin/perl -w
 
open("name.txt", "<filename.in");
open("nameout.txt", ">filename.out");
while(<name.txt>)
{
        my($line) = $_;
        chomp($line);
        if($name = Clark Kent)
        {
                $newnme = "SUPERMAN!!!";
                my($first, $last) = split(//, $name);
                $line = sprintf($name, $newnme );
        }
}
close("name.txt");
close("nameout.txt");

Open in new window

Avatar of benofvan
benofvan
Flag of United States of America image

One thing I see is that you cannot compare a string with "=", and the string must be quoted.  it must be like:

if ($name eq "Clark Kent") {
}
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial