Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

use of $*

by millan123 (Initiate)
on Aug 01, 2014 at 08:36 UTC ( [id://1095858]=perlquestion: print w/replies, xml ) Need Help??

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

I am seeing old perl code 5.001 where i can see code as below.
$old = $*; $* =1;
Came to know $* is deprecated. But not able find what does it mean.please let me know what does it work and which special variable is used in place of $* in higher versions of Perl.

Replies are listed 'Best First'.
Re: use of $*
by moritz (Cardinal) on Aug 01, 2014 at 08:40 UTC
Re: use of $*
by GrandFather (Saint) on Aug 01, 2014 at 08:41 UTC

    $* was used to enable multi-line matching in regular expressions. It's been replaced by the m and s flags. m lets ^ and $ match at line ends. s lets . match new line characters.

    In isolation $* doesn't mean anything. You need to look for uses of regular expression matches to figure out what it might be doing. Look for uses of =~ and examine the code around it.

    Perl is the programming world's equivalent of English
Re: use of $*
by ikegami (Patriarch) on Aug 01, 2014 at 11:50 UTC

    It was the same as using /m on all your match and substitution operators, except it overrode instructions to turn /m off.

    For example, qr/foo$/ shouldn't match "foo\nbar\n" even if it's used as /$re/m.

    $ perl5010 -le' $re = qr/foo$/; print $re; print "foo\nbar\n" =~ /$re/m ?1:0 ' (?-xism:foo$) # -m: Turn /m off. 0

    But it did before 5.10

    $ perl5008009 -le' $re = qr/foo$/; print $re; print "foo\nbar\n" =~ /$re/m ?1:0 ' (?-xism:foo$) 1 # Matched as if /m was on for the subpattern.

    This was fixed, but there was no way of fixing $* which had the same error.

    $ perl5008009 -le' $re = qr/foo$/; print $re; local $* = 1; print "foo\nbar\n" =~ /$re/ ?1:0 ' (?-xism:foo$) 1

    So it was dropped.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: use of $*
by davido (Cardinal) on Aug 01, 2014 at 14:49 UTC

    Not even deprecated anymore. I believe current Perl has removed it. As of 5.20 (possibly earlier) if you use it:

    perl -E '$*=1;' $* is no longer supported at -e line 1.

    If you want the full explanation of what it used to do, look at an older version of the documentation. 5.8.9 ought to do, and it's available on perldoc.perl.org: http://perldoc.perl.org/5.8.9/perlvar.html:

    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 .


    Dave

      Apparently already unsupported in Perl 5.14:
      $ perl -E '$*=1;' $* is no longer supported at -e line 1. $ perl -v This is perl 5, version 14, subversion 4 (v5.14.4) built for cygwin-th +read-multi (with 7 registered patches, see perl -V for more detail) Copyright 1987-2013, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1095858]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found