Can someone show me an example which demonstrates the different behavior of these two variables ( $^N and $+ )?
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.
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)
++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.
++n; increments the value of n before the expression is evaluated. n++; increments the value of n after the expression is evaluated.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With