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

hi, while working on a script to automize Clearcase labelling I came across a weird problem. while running this code:
#perl -w use strict; my $view; my $labelold; my $labelnew; my $ab; my $ba; my $element; my $rc; my $path; my $path2; my $input; my $comment; my @VOBs; my @lijst; #system("cls"); print "\nThis script will apply a label to all objects of another labe +l."; print "\nplease enter the name of the active view (e.g.: u12345-1): "; chomp ($view = <STDIN>); while(){ print "\nEnter the name of a VOB you want to access (e.g.: PowerCe +nter, PowerCenter_s), press Enter when finished:"; chomp ($ab = <STDIN>); unless($ab){last;} push(@VOBs, $ab); } print "\nGive the name of the old label (e.g.: DXOPRJ0-1.0.0): "; chomp($labelold = <STDIN>); print "\nGive the name of the new label (e.g.: DXOPRJ0-1.0.1): "; chomp($labelnew = <STDIN>); print "\n Give the comment for the new label: "; chomp($comment =<STDIN>); $path = "u:\\$view\\"; chdir($path); foreach $element(@VOBs){ $path2 = $path . "\\$element"; chdir($path2); $ab = "cleartool mklbtype -c \"$comment\" $labelnew"; $rc = system "$ab"; while($rc!=0){ $rc = 0; print "\nlabel $labelnew already existed! Do you want to repla +ce it(y\/n)?"; chomp($input = <STDIN>); unless($input eq 'n'||$input eq 'no'||$input eq 'N'||$input eq + 'NO'){ $ba = "cleartool rmtype –rmall lbtype:$labelnew"; #121#print "$ba"; $rc = system("$ba"); if($rc!=0){print "\ndeletion of CC label failed!";} $rc = system "$ab"; } } chdir($path); $ab = "cleartool find $element -version \"lbtype($labelold)\" -exe +c \"cleartool mklabel -replace $labelnew %CLEARCASE_XPN%\""; $rc = system "$ab"; if($rc!=0){ die "\nan error occured..."; } else{ print "\nlabelling $element succesfull!";} }
the print statement #121# returns "cleartool rmtype ūrmall lbtype:LABEL" instead of "cleartool rmtype -rmall lbtype:LABEL" this of course results in an error with the system call. I tried to use backticks, but the same problem occurs. When skipping this option the program gives the correct result. To test the nature of this problem I made a quick program with only the print statement:
#perl -w use strict; print "cleartool rmtype -rmall lbtype:LABEL";
This returns the correct output. At this point I was lost. Does someone know what causes this problem and how to solve it?

Replies are listed 'Best First'.
Re: Printing - on windows
by almut (Canon) on Apr 07, 2009 at 08:39 UTC

    Your dash in -rmall seems to be a unicode character (U+2013, '–'), not the expected normal ASCII dash '-'.  Can't tell you how that got into the code, though.

      replacing the - with a - solved the problem. Reflecting, I think the unicode - came into the perl program because I copied it from the Clearcase manual (HTML). Of course I didn't realise the conversion conflict with Unicode/ASCII. Many thanks!
Re: Printing - on windows
by BrowserUk (Patriarch) on Apr 07, 2009 at 08:53 UTC

    You are basically saying that when you execute these two lines:

    $ba = "cleartool rmtype –rmall lbtype:$labelnew"; #121#print "$ba";

    you get this output (assuming that $labelnew contains LABEL):

    cleartool rmtype ūrmall lbtype:LABEL

    The simple answer is: That cannot happen!. But since you're here asking, you've obviously seen it happen, so the question is how could that come about.

    The only possibility that comes to mind is that the editor you are using has somehow encoded a unicode character within your source file that displays as '-', but when interpreted as ascii (or roman1 or whatever codepage is selected on your terminal where you are viewing the output), it appears as the accented character you see there.

    To check that hypothesis, I viewed the source of your post in my editor and what I found is that the '-' character shown in your post above, is actually a unicode multibyte character. I tried to paste a copy of what I see here, but once it has been through the process of being pasted in my browser, uploaded to PM, stored and retrieved through their DB and re-displayed, it looks like an ordinary '-' again.

    So, my suggestion is this.

    1. Go into the source file in your editor and delete the 3 characters ' -r' in that line and save the file and exit the editor (completely).
    2. Re-start the editor and re-load the source file and re-type those 3 characters.
    3. Save it and re-run the program.

    With luck the problem will have "gone away". If not, sorry to have wasted your time.

    (Are you using Word as your source editor? If not, which editor are you using?)


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      thanks for the answer. You were right (though only the - should be replaced, but of course, better safe than sorry.) I was using UltraEdit editor with syntax highlighting for perl.
Re: Printing - on windows
by cdarke (Prior) on Apr 07, 2009 at 10:29 UTC
    You can also get this issue with "smart quotes" - double and single.