tags:

views:

784

answers:

5

Hi, I'm a complete perl novice, am running a perl script using perl 5.10 and getting this warning:

$* is no longer supported at migrate.pl line 380.

Can anyone describe what $* did and what the recommended replacement of it is now? Alternatively if you could point me to documentation that describes this that would be great.

The script I'm running is to migrate a source code database from vss to svn and can be found here: http://www.x2systems.com/files/migrate.pl.txt

The two snippets of code that use it are:

    $* = 1;
    $/ = ':';

    $cmd = $SSCMD . " Dir -I- \"$proj\"";
    $_ = `$cmd`;

    # what this next expression does is to merge wrapped lines like:
    #    $/DeviceAuthority/src/com/eclyptic/networkdevicedomain/deviceinterrogator/excep
    #    tion:
    # into:
    #    $/DeviceAuthority/src/com/eclyptic/networkdevicedomain/deviceinterrogator/exception:
    s/\n((\w*\-*\.*\w*\/*)+\:)/$1/g;

    $* = 0;

and then some ways later on:

            $cmd = $SSCMD . " get -GTM -W -I-Y -GL\"$localdir\" -V$version \"$file\" 2>&1";
            $out = `$cmd`;

            # get rid of stupid VSS warning messages
            $* = 1;
            $out =~ s/\n?Project.*rebuilt\.//g;
            $out =~ s/\n?File.*rebuilt\.//g;
            $out =~ s/\n.*was moved out of this project.*rebuilt\.//g;
            $out =~ s/\nContinue anyway.*Y//g;
            $* = 0;

many thanks,

  • Rory
+1  A: 

It turns on multi-line mode. Since perl 5.0 (from 1994), the correct way to do that is adding a m and/or the s modifier to your regexps, like this

 s/\n?Project.*rebuilt\.//msg
Leon Timmermans
+2  A: 

From Perl 5.8 version of perlvar:

Set to a non-zero integer value to do multi-line matching within a string [...] Use of $* is deprecated in modern Perl, supplanted by the /s and /m modifiers on pattern matching.

While using /s and /m is much better, you need to set the modifiers (appropriately!) for each regular expression.

perlvar also says "This variable influences the interpretation of only ^ and $." which gives the impression that it's equivalent to /m only and not /s.

Note that $* is a global variable. Because the change to it is not made local with the local keyword, it will affect all regular expressions in the program, not just those that follow it in the block. This will make it more difficult to update the script correctly.

Michael Carman
+10  A: 

From perlvar:

Use of $* is deprecated in modern Perl, supplanted by the /s and /m modifiers on pattern matching.

If you have access to the place where it's being matched just add it to the end:

 $haystack =~ m/.../sm;

If you only have access to the string, you can surround the expression with

 qr/(?ms-ix:$expr)/;

Or in your case:

s/\n((\w*\-*\.*\w*\/*)+\:)/$1/gsm;
Axeman
+1  A: 

It was basically a way of saying that in subsequent regexes (s/// or m//), the ^ or $ assertions should be able to match before or after newlines embedded in the string.

The recommended equivalent is the m modifier at the end of your regex (e.g., s/\n((\w*-*.*\w*\/*)+\:)/$1/gm;).

Alex
+2  A: 

From perldoc perlvar:

$*

Set to a non-zero integer value to do multi-line matching within a string, 0 (or undefined) to tell Perl that it can assume that strings contain a single line, for the purpose of optimizing pattern matches. Pattern matches on strings containing multiple newlines can produce confusing results when $* is 0 or undefined. Default is undefined. (Mnemonic: * matches multiple things.) This variable influences the interpretation of only ^ and $. A literal newline can be searched for even when $* == 0.

Use of $* is deprecated in modern Perl, supplanted by the /s and /m modifiers on pattern matching.

Assigning a non-numerical value to $* triggers a warning (and makes $* act as if $* == 0), while assigning a numerical value to $* makes that an implicit int is applied on the value.

Notitze