- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The G Assertion in Perl
The \G assertion in Perl allows you to continue searching from the point where the last match occurred. For example, in the following code, we have used \G so that we can search to the correct position and then extract some information, without having to create a more complex, single regular expression −
Example
#!/usr/bin/perl $string = "The time is: 12:31:02 on 4/12/00"; $string =~ /:\s+/g; ($time) = ($string =~ /\G(\d+:\d+:\d+)/); $string =~ /.+\s+/g; ($date) = ($string =~ m{\G(\d+/\d+/\d+)}); print "Time: $time, Date: $date\n";
When the above program is executed, it produces the following result −
Time: 12:31:02, Date: 4/12/00
The \G assertion is actually just the metasymbol equivalent of the pos function, so between regular expression calls you can continue to use pos, and even modify the value of pos (and therefore \G) by using pos as an lvalue subroutine.
- Related Articles
- The ? : Operator in Perl
- The $[ Special Variable in Perl
- The Infinite Loop in Perl
- The carp Function in Perl
- The cluck Function in Perl
- The croak Function in Perl
- The confess Function in Perl
- The Match Operator in Perl
- The Substitution Operator in Perl
- The Translation Operator in Perl
- The system() Function in Perl
- The fork() Function in Perl
- The kill() Function in Perl
- Assertion ( (A) ) : In the case of a rainbow, light at the inner surface of the water drop gets internally reflected.Reason ( (mathrm{R}) ); The angle between the refracted ray and normal to the drop surface is greater than the critical angle.(A) Both Assertion and Reason are true and Reason is the correct explanation of the Assertion.(B) Both Assertion and Reason are true but Reason is not a correct explanation of the Assertion(C) Assertion is true but the Reason is false(D) Both Assertion and Reason are false.
- How to handle Assertion Error in Java?

Advertisements