Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Perl #3 Strings and Numbers
#1
Perl #3 : Strings and Numbers

Perl only distinguishes between two types of data, those are scalar data and list data. Scalar data, is for single things like numbers or strings of characters. List data is for collective things like arrays. In this tutorial we will only talk of scalar data, ignore list data for now...

Here is a list of valid numbers in Perl.
1
2.1
.2134123
2.
1_122_231
10E2
45e-4
0xbeef
022

Integers and floating point numbers are both represented as you think they would be. The integers represented by whole numbers, then floating with integer then decimal part. Comma's arent allowed so you use _ as you can see in 1_122_231 The Underscores represent comma's
Exponents you use a lower or upper letter case e
Hexadecimal and octal numbers are represented by 0x or 0

Strings

A string a collection of letters. They are a form of Scalar data in Perl.
To represent a string you either use ' ' or " "
'String'
"String"
"Hello World!\n"

Ok now back onto strings, strings can use any kind of ASCII data, that includes things like binary!

Ok here would be a good place to explain the whole double quotes/ single quotes thing. Ok when using double quotes ("") you are allowed to use variables and other non "plain text". You also can use normal typing but double quotes allows you to call on a Variable like "My name is $name "
While single quotes ('') You cant call on things like variables. You cant use things like \n (New line) (Those are called Escape characters), you only can type "Hello my name is austin"

LINE--------------------------------OUTPUT

"Hello $ownername"------------------------Hello Wade
'Hello $ownername'------------------------Hello $ownername

[color="#FF8C00"]
Some Escape characters[/color]

\n New Line
\r Carriage Return
\f Formfeed
\t Tab
\a Bell
\b Backspace
\e Escape
\u Makes next letter Uppercase
\l Makes next letter Lowercase
\U Makes all following letters Uppercase
\L Makes all following letters Lowercase
\E Ends \U, \L, or \Q expressions

Empty Strings, is a string with no characters. Empty strings look like this "". Its not an empty string if it has a space in it like " ". The space is what no longer makes it an empty string.


Here is a bit on variables!

Variables must have $ at the beginning

Set a variable with the assignment operator which is the equals sign ( = )

So like $a = 1 would set the variable as 1

Then there is $a = $b = 1 would set $a to 1 and $b to 1

Thats all for now
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compile Error in Perl liveproject101 0 1,155 04-12-2013, 03:08 AM
Last Post: liveproject101
  [Perl] IRC Bot wchar_t 26 12,894 08-20-2012, 01:40 PM
Last Post: Trump
  Perl Ebook ven0m 2 1,628 05-04-2012, 08:14 AM
Last Post: ven0m
  Help with a program written in perl Rodman42866 1 1,532 03-09-2012, 03:16 AM
Last Post: AceInfinity
  HTML perl script AceInfinity 5 2,411 12-03-2011, 11:35 PM
Last Post: Closed Account

Forum Jump:


Users browsing this thread: 1 Guest(s)