Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitute forward slash for any backslash 2

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
Hello all,

I am processing a text file and I need to replace all the backslashes "\" in the file with forward slashes "/". Here is my code so far:

Code:
open (OUT, ">/home/opc_op/log/pgp_in_process.log") or die ("Error opening log file: $1");

my $out = "";		# undefine $out
my $saw_error = 0;  # Initialize variable to 0

foreach(@diff) {
    chomp;
	s/\//\\/g;     # HERE  IS MY SUBSTITUTION
    next if /^\s*$/;					
    if (/^ERROR--/ || /^-/) {			
        if ($out) {						
            $out =~ s/(--)\s+/$1/;		
            print (OUT "$out\n");		
			$out = "";					
            $saw_error--;				
        }
        if (/^ERROR--/) {				
            $saw_error++;				
        }
    }
    if ($saw_error) {					
        if ($out =~ /\S$/ && /^\S/) {	
            $out .= " ";				
        }
        $out .= $_;						
    }
}

Mike V. you migt recognize this script.

Thanks,

Nick
 
Well, you're may be doing the opposite of what you want
Code:
 s/\//\\/g;     # HERE  IS MY SUBSTITUTION
Code:
 s/\\/\//g;     # HERE  IS MY SUBSTITUTION

No ?
 
Thanks for the reply zephan, I tried it both ways and either way it makes no changes to the output.
 
Here is the contents of the @diff array via:

print "@diff\n";

Code:
a1122
 -------------------------------------------------------------------------------------
 Mon Aug  2 09:20:30 2004
 gpg: encrypted with ELG-E key, ID BC8F2CE8
 gpg: encrypted with 2048-bit ELG-E key, ID F7BA222B, created 2002-01-28
       "FleetBoston Financial DTS <Data_Transmission_Svcs@Fleet.Com> "
 gpg: decryption failed: secret key not available
 ERROR--
     Test error placed in file
     No Commands failed
     Account Name:  FLEET
     File Name:     d:\pgp_user_data\inbound\fleet\vaz.txt.pgp
 ERROR--
     Could not move the following file to detainment
     Filename:     d:\pgp_user_data\inbound\fleet\vaz.txt.pgp	
 Can't call method "code" on an undefined value at inbound.pl line 179.
 -------------------------------------------------------------------------------------
 .
 
zephan,

Sorry, you were right. This seems to work:

s/\\/\//g; # HERE IS MY SUBSTITUTION

I had it backwards, the problem is my eyes, I work between Unix and NT so often, I had a hard time seeing the change.
 
You could use a different delimiter to make it more readable, e.g. curlie braces (and then you don't need to escape the /): s{\\}{/}g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top