Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "$^N" and "$+"?

Can someone show me an example which demonstrates the different behavior of these two variables ( $^N and $+ )?

like image 843
sid_com Avatar asked Nov 24 '10 15:11

sid_com


People also ask

What's the difference between S and N MBTI?

If the second letter of your Myers-Briggs type is an "N," you would be considered intuitive rather than sensing. Where S types favor their senses and facts, N's are concerned with deeper meanings and patterns. They often have an abstract, roundabout way of thinking.

What is the N and S in personality type?

It indicates your personality preferences in four dimensions: Where you focus your attention – Extraversion (E) or Introversion (I) The way you take in information – Sensing (S) or INtuition (N)

What is difference between n ++ and ++ n?

++n increments the value and returns the new one. n++ increments the value and returns the old one. Thus, n++ requires extra storage, as it has to keep track of the old value so it can return it after doing the increment. I would expect the actual difference between these two to be negligible these days.

What does N ++ mean in coding?

++n; increments the value of n before the expression is evaluated. n++; increments the value of n after the expression is evaluated.


1 Answers

From perldoc perlvar:

$+: The text matched by the last bracket of the last successful search pattern.

versus

$^N: The text matched by the used group most-recently closed (i.e. the group with the rightmost closing parenthesis) of the last successful search pattern.

This should illustrate the difference:

#!/usr/bin/perl

use strict; use warnings;

my $s = '12345';

if ( $s =~ /(1([0-9]))/ ) {
    print "$_\n" for $+, $^N;
}

Output:

2
12
like image 192
Sinan Ünür Avatar answered Oct 08 '22 12:10

Sinan Ünür