monaLisa has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I want to change the following line
otsort ../mydata/SKE_DE_WKey_out.dat ../mydata/SKE_DE_WKey_out.srt /apost s(1001,8,c,a) om(1001,1,c,EQ,' ') f(fix,1371) core(60000)

To:
otsort ../mydata/SKE_DE_WKey_out.dat ../mydata/SKE_DE_WKey_out.srt "/apost s(1001,8,c,a),om(1001,1,c,EQ,' '),record(1371)"
To do that I used the following code, but it doesn't work:
print "#UnixLine\n"; my $endUnixLine =~ s|\/apost.|"//apost."|g; print "$endUnixLine\n"; print outFile "#UnixLine\n"; print outfile "$endUnixLine\n";


Could someone give me an advise?

Mona

Replies are listed 'Best First'.
Re: How to change a part of a line in a text???
by sauoq (Abbot) on Aug 11, 2003 at 10:10 UTC
    To do that I used the following code, but it doesn't work:

    Doesn't work how? It certainly won't make the change you suggest because it seems you are just trying to add some quotes and an extra slash... but even that is failing because

    my $endUnixLine =~ s|\/apost.|"//apost."|g;
    is trying to do the substitution on a newly declared variable. If you were running with warnings on, perl would have barked at you about that.

    If you are having trouble with the regular expression to use, you might help us to help you (and you might help yourself) by providing a better specification of what you actually need to do.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: How to change a part of a line in a text???
by monktim (Friar) on Aug 11, 2003 at 13:06 UTC
    I think you're having trouble with escape characters. I broke it down into steps so you can see it plainly. I could have been very clever and given you one regex that would do it but it is easier to see what is going on here.
    use strict; use warnings; my $str = "otsort ../mydata/SKE_DE_WKey_out.dat ../mydata/SKE_DE_WKey_ +out.srt /apost s(1001,8,c,a) om(1001,1,c,EQ,' ') f(fix,1371) core(600 +00)"; print "$str\n"; $str =~ s/\/apost s/\"\/apost s/; print "$str\n"; $str =~ s/ om\(/,om\(/; print "$str\n"; $str =~ s/ f\(fix.*/,record(1371)/; print "$str\n";