Skip to content
asicguru.tech@gmail.com
REGISTER LOGIN
AsicGuru Ventures
  • All Courses
  • CONTACT
  • GALLERY
  • HOME
  • Tutorials

0

Verilog Tutorial

17
  • Verilog Introduction
  • Lexical Tokens
  • Gate-Level Modelling
  • Data Types
  • Operators
  • Operands
  • Modules
  • Behavioral Modeling
  • Timing Controls
  • Procedures: Always and Initial Blocks
  • Functions
  • Tasks
  • Component Inference
  • Finite State Machines.
  • Compiler Directives
  • System Tasks and Functions
  • Test Benches

System Verilog

23
  • System Verilog Introduction
  • Data Types
  • Type Casting
  • Arrays
  • Associative Arrays
  • Dynamic Arrays
  • Queue
  • Operators
  • Procedural statements and Control flow
  • Classes
  • Inheritance
  • Encapsulation
  • This and Super operator
  • In-Line Constraints
  • Class Constraints
  • Virtual Classes
  • Parameterized Classes
  • Classes Summary
  • Singleton Classes
  • Functional Coverage Introduction
  • Covergroup
  • Tools
  • Books

Scripting

15
  • Introduction
  • Perl Tutorial
  • What is Perl
  • Perl: Syntax And Variable
  • Perl Strings
  • Perl Arrays
  • Perl Associative Arrays
  • If/While Syntax
  • File Input
  • Print Output
  • String Processing with Regular Expressions
  • Subroutines
  • Running External Programs
  • References
  • Terse Perl

Makefile

1
  • Makefile Tutorial
View Categories
  • Home
  • Tutorials
  • Scripting
  • Perl Strings

Perl Strings

1 min read

Strings


Strings constants are enclosed within double quotes (“) or in single quotes (‘). Strings in double quotes are treated specially — special directives like \n (newline) and \x20 (hex 20) are expanded.
More importantly, a variable, such as $x, inside a double quoted string is evaluated at run-time and the result is pasted into the string. This evaluation of variables into strings is called “interpolation” and it’s a great Perl feature. Single quoted (‘) strings suppress all the special evaluation — they do not evaluate \n or $x, and they may contain newlines.


$fname = “binky.txt”;
$a = “Could not open the file $fname.”;                   ## $fname evaluated and pasted in– neato!

$b = ‘Could not open the file $fname.’;                   ## single quotes (‘) do no special evaluation

## $a is now “Could not open the file binky.txt.”

## $b is now “Could not open the file $fname.”


The characters ‘$’ and ‘@’ are used to trigger interpolation into strings, so those characters need to be escaped with a backslash (\) if you want them in a string. For example:
“nick\@stanford.edu found \$1”.

The dot operator (.) concatenates two strings. If Perl has a number or other type when it wants a string, it just silently converts the value to a string and continues. It works the other way too — a string such as “42” will evaluate to the integer 42 in an integer context.
$num = 42;
$string = “The ” . $num . ” ultimate” . ” answer”;
## $string is now “The 42 ultimate answer”

The operators eq (equal) and ne (not equal) compare two strings. Do not use == to compare strings; use == to compare numbers.
$string = “hello”;
($string eq (“hell” . “o”)) ==> TRUE
($string eq “HELLO”) ==> FALSE
$num = 42;
($num-2 == 40)           ==> TRUE
The lc(“Hello”) operator returns the all lower-case version “hello”, and uc(“Hello”) returns the all upper-case version “HELLO”.

Fast And Loose Perl


When Perl sees an expression that doesn’t make sense, such as a variable that has not been given a value, it tends to just silently pass over the problem and use some default value such as undef.
This is better than C or C++ which tend to crash when you do something wrong. Still, you need to be careful with Perl code since it’s easy for the language to do something you did not have in mind. Just because Perl code compiles, don’t assume it’s doing what you intended. Anything compiles in Perl.

Updated on May 4, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
Perl: Syntax And VariablePerl Arrays

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • May 2025

Categories

  • Slider Post
  • Uncategorized

Copyright @ Asicguru Ventures by Misbah WP | Proudly powered by WordPress