Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does perl special variable $-[0] and $+[0] means

I want to know the meaning of perl special variables $-[0] and $+[0]

I have googled and found that $- represent number of lines left on the page and $+ represent the last bracket matched by the last search pattern.

But my question is what $-[0] and $+[0] means in context of regular expressions.

Let me know if code sample is required.

like image 819
AnonGeek Avatar asked Jun 25 '12 09:06

AnonGeek


People also ask

What Perl special variables?

There are some variables which have a predefined and special meaning in Perl. They are the variables that use punctuation characters after the usual variable indicator ($, @, or %), such as $_ ( explained below ).

What is $? In Perl?

$? is the error code of the child process (perform_task.sh). In the case of your script the return code is shifted eight bits to the right and the result compared with 0. This means the run is considered a failure only if the returned code is > than 255.

What is $0 Perl?

$PROGRAM_NAME $0. Contains the name of the file containing the Perl script being executed. On some operating systems assigning to " $0 " modifies the argument area that the ps(1) program sees. This is more useful as a way of indicating the current program state than it is for hiding the program you're running.


1 Answers

See perldoc perlvar about @+ and @-.

$+[0] is the offset into the string of the end of the entire match.

$-[0] is the offset of the start of the last successful match.

like image 14
Denis Ibaev Avatar answered Oct 09 '22 12:10

Denis Ibaev