« March 2009 »
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Perlblog
Tuesday, 31 March 2009


Larry all:
https://www.youtube.com/watch?v=JzIWdJVP-wo&NR=1

-- -----------------------------------------------

Lecture - 21 PERL - Part I
https://www.youtube.com/watch?v=1pVolaKhxVM&feature=PlayList&p=04D5787E247DC324&playnext=1&playnext_from=PL&index=20

Lecture - 22 PERL - Part II
https://www.youtube.com/watch?v=ELp9ytLjupE&feature=PlayList&p=04D5787E247DC324&index=21

Lecture - 23 PERL - Part III
https://www.youtube.com/watch?v=TNIaPKDu678&feature=PlayList&p=04D5787E247DC324&index=22

Lecture -24 PERL-Part IV
https://www.youtube.com/watch?v=-GMDuG-bVfw&feature=PlayList&p=04D5787E247DC324&index=23

printf<<terminator
this is a paragraph
terminator

@month   --> array
$month[1] --> second element, month

@color = ( "red", "green", "blue", "black" )
 <--> @color = qw(red green blue black) 
     #here qw quote word
     $color[1] <--> green

@array1=@array2

@allcolors = ("white" @colors "blown")


@xyz=(2..5);  <---> @xyz=(2,3,4,5)
@xyz=(1 @xyz);
@xyz=(@xyz,6);

-- -----------------------------------

($x, $y, $z)=(10, 20, 30);

($x, $y) = ($y, $x);

($a, @col)=("red", "green", "blue")

($first, @val, $last)=(1,2,3,4)  <--> $last will be undefined


-- ---------------------------------

@list=(1,2,3,4);
$first=$list[0];
$list[1]++;  ---> # array becomes (1. 3. 3. 4)

$x=$list[5]; $x gets the valuw undef

$list[2]="Go"; #array becomes (1,2,"Go",4)

-- -----------------------------------

$#value --> the index of the last element of the array,
            total number minus one

$#value=-1; --> en empty rray has value of -1

-- ---------------------------------
shift and unshift
$first=shift @array;

unshift(@color, "white") --> replace the first element of the array

-- ---------------------------------
pop and push
$first=pop @color  --> get the last element of the array
push(@color, "white") --> replace the last element of an array

-- --------------------------------------------------------------

@array2 = reverse @array1;

@array2 = sort @array1;

@array2 = sort ($a <=> $b) @array1;  # sort numerically

@middle=splice(@colors,1,2); # remove start from second arguments
                              for 3rd argument of elements


-- ---------------------------------------------------------------

split --> string, delimiter --> array
--> @array= split / /, $_

join --> $new = join ' ', $x1, $x2, $x3;

$sep=';';
$new = join $sep, $x1, $x2, $x3;

-- ---------------------------------------------------------------

print @colors; --> print without space
print "@colors"; --> print with space

-- --------------------------------------------------------------
<STDIN> <STDOUT> <STDERR>

<stdin>  # stdin file handler, <stdin> content of the file handler

chop ($name=<stdin>); chop last character
chmop --> only chop the last character if it is a new lines

$. --> line numer
$_ --> content of current operation
$! --> error code/message

$scalar(localtime)

$out="filename";
open XYZ, ">$out" or die "Error in write: $!"
open XYZ, ">>$out" or die "Error in write: $!"

close XYZ;

-- --------------------------------------------------------------

in perl: three things are considered as FALSE
1): The value 0
2): The empty string ("")
3): undef

-- -------------------------------------------------------------

if ($flag == 1 )
if ($name eq "isa" )

number ==  !=  >  <  >= <=
string eq  ne  gt it ge le

and &&
or  ||
not  !

 

-- -------------------------------------------------------------

break out a loop:

last if ( $i > 10); # similar to break
next # similar to continue

 

-- -------------------------------------------------------------


@ARGV

foreach (@ARGV) {
 print "$_\n";
}

-- ------------------------------------------

=~ ==> match
!~ ==> not match

/  /  --> if other delimiter is used, then use m  eg:  (string =~ m[day[ )

-- -------------------------------------------

if ($string =~ /[0123456789]/)  ==> only means digital

^ negation  -->  if ($string =~ /[^aeiou]) { ... ... }

. any single character except newline
\d digit
\w a word character  0-9a-zA-Z
\s space tab
\D not a digit
\W not a word
\S not a space


^ beginning of the string  eg: /^\w/ --> string beginning with a word character
$ end of the string        eg: /\d$/ --> end with a number
\b anchors to a word boundary  eg: /\bGood\b/

*: zero or more
+: one or more
?: zero or one

-- --------------------------------------------------------------

s: subsitution

$new =~ s/pattern_to_match/new_pattern/;

-- -------------------------------------------------------------

/i: ignore
/g: match/substitute all occurrences

-- ------------------------------------------------------------

\1 \2 \3: if still in regular expression
$1 $2 $3: after reguar expression

$&?  string matched
$`?  string before matching string
$'?  string after matching string

$@


-- -------------------------------------------------------------

%hash
http://perldoc.perl.org/functions/map.html
http://www.devshed.com/c/a/Perl/Hash-Mania-With-Perl/1/

# remove or remove from hash
delete $directory{Atul}


# key value hash reversal

%hash2 = reverse %hash1

@all_names = keys %directory;
@all_values = values %direcory;

-- ----------------------------------------------------

subroutine:

1): arguments

@_

$_[0] $_[1] $_[2]


shift @_

-- ---------------------------------------------------

 

 


Posted by shenh at 12:03 AM EDT
Updated: Tuesday, 31 March 2009 12:05 AM EDT

View Latest Entries