Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
  • SQL
  • Web Development
  • System Design
  • Aptitude
  • GfG Premium
Open In App
Next Article:
Perl - Listing your Program with a Debugger
Next article icon

Perl - Listing your Program with a Debugger

Last Updated : 02 Jul, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Perfect programs are hard to get in the very first attempt. They have to go through various steps of debugging to fix all errors. There are two types of errors – Syntax errors and Logical errors. Syntax errors are easy to fix and are found fast. On the other hand, logical errors are hard to find and fix. Thus, a debugger is required to fix those errors.

In Perl, a debugger is an environment that executes the program line by line. This process is also known as single-stepping through the program. To enter into debugger, follow the Syntax given below: Syntax:
perl -d <program_name>
Sample Program to Debug: Perl
#!/usr/bin/perl -w  # Perl program for a simple calculator use strict;      my $op; my $num1; my $num2; my $result; my $flag;      calculator();      sub calculator  {     print "Enter operation you want to perform -Add, Sub, Mult, Div - ";     chomp($op = <>);     print "Enter first number: ";chomp($num1 = <>);     print "Enter second number: ";chomp($num2 = <>);      # Check for arithmetic operation     if ($op =~ /^a/) {         $result = $num1 + $num2;     } elsif ($op =~ /^s/) {         $result = $num1 - $num2;     } elsif ($op =~ /^m/) {         $result = $num1 * $num2;     } elsif ($op =~ /^d/) {         $result = $num1 / $num2;     }      # Print the answer of above operation     print "Result: $result\n";      # Calling the function recursively     print "Do another calculation ? ";chomp($flag = <>);     if ($flag =~ /^y/) {         calculator();     } else {         print "Thank You !!\n";     } } 

Listing Sample Code with Debugger

  1. ‘l’ command : The ‘l’ command lets us print a partial part of our scripts. There are several versions of this command that we can use –
    • Use ‘l’ – Displays 10 lines of script from location of cursor.
    • Using l 4+6 – Displays 6 lines of script starting from line 4.
    • Using l 4-7 – Displays lines 4 through 7 of script.
    • Using l 20 – Displays script on line 20.
    • Using l foo – Displays approximately first 10 lines of foo() function.
  2. ‘-‘ command : Outputs 10 lines of script before the current line. Suppose that you are current on line 20, then, lines 9 to 19 will be displayed.
  3. ‘w’ command : Adds a watch expression. Syntax:
    w $variable_name
  4. ‘//’ and ‘??’ : // and ?? search for a given pattern in the script. The /pattern/ searches for a pattern in forward direction while, the ?pattern? searches for a pattern in the backward direction from the current position of cursor. Syntax:
    /pattern/ or ?pattern?
  5. ‘S’ command : This command lists all the subroutines not matching a given pattern. Syntax:
    S expression 

Next Article
Perl - Listing your Program with a Debugger

C

chinmay_bhide
Improve
Article Tags :
  • Perl

Similar Reads

    Perl Stepping Through Programs with a Debugger
    Controlling program execution in Perl can be done by telling the debugger to execute up to a certain specified point in the program, called a breakpoint. These breakpoints enable the user to divide the program into sections and look for errors. Following are some commands in a debugger that are used
    3 min read
    Perl | Displaying Variable Values with a Debugger
    Debugger in Perl comes up with various features thus making the debugging process quite simple and effective. One of the most powerful features of Perl Debugger is displaying variable values. This feature allows us to display the value of any variable at any time. There are two basic commands to imp
    3 min read
    Debugging in R Programming
    Debugging is a process of cleaning a program code from bugs to run it successfully. While writing codes, some mistakes or problems automatically appears after the compilation of code and are harder to diagnose. So, fixing it takes a lot of time and after multiple levels of calls. Debugging in R is t
    3 min read
    Perl - Introduction to Debugger
    Sure, here's an introduction to the debugger in Perl: The Perl debugger is a tool that helps you find and fix bugs in your Perl programs. It allows you to step through your code one line at a time, examine variables and expressions, set breakpoints, and much more. The debugger can be used in both co
    9 min read
    C++ Program to Print Your Own Name
    Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C++ program.ExamplesInput: name = "Anmol"Output: AnmolExplanation: Given name is printed on the output screen.Input: name = "Alex"Output: AlexExplanation: Given
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences