Fall Semester 2021-2022 Scripting Languages For VLSI Design Automation LAB - 05 - PERL Regular Expression
Fall Semester 2021-2022 Scripting Languages For VLSI Design Automation LAB - 05 - PERL Regular Expression
cd ./Scripting/Perl/PERL_Practice_Lab
gedit reg_exp.pl
#!/usr/bin/perl
#Following lines of code shows to search the pattern every in the variable $_
if( $_ =~ /every/) {
#Following line shows to search any numerical pattern in the variable $string
if($string =~ /[123456789]/) {
#It also shows how to memorize and recall the memorized pattern
if($a =~ /(\w+)\s(\w+)\s(\w+)\s\1/) {
} else {
Step 4: Save the contents and execute the script from the terminal to see the output.
perl reg_exp.pl
Note: Try to use and get familiar with the following pattern abbreviation, anchors and
multipliers.
Pattern Abbreviations:
Anchor Meaning
^ Anchors to the beginning of a string
$ Anchors to the end of a string
\b Anchors to a word boundary
Pattern Multipliers:
Symbol Meaning
This section contains an example script to show how to open, read and write to a file.
A file can be opened using the open keyword and can be closed using the close keyword.
There are three modes of opening the file viz., read mode, write mode and append mode.
MODE OPERAND
Read <
Write >
Append >>
gedit file_handling.pl
#Following script shows how to open and read the contents of a file
while (<FH1>) {
print “$_”;
close (FH1);
while (<FH1>) {
print “End of File Reached…written the contents of one file to the other file\n”;
close (FH1);
close (FH2);
Scripting Languages for VLSI Design Automation
Step 3: Save and execute the script.