« April 2024 »
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
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
Saturday, 28 March 2009

Now Playing: perl faq

http://faq.perl.org/

http://faq.perl.org/perlfaq1.html

http://faq.perl.org/perlfaq2.html

http://faq.perl.org/perlfaq3.html

http://faq.perl.org/perlfaq4.html

http://faq.perl.org/perlfaq5.html

http://faq.perl.org/perlfaq6.html

http://faq.perl.org/perlfaq7.html

http://faq.perl.org/perlfaq8.html

 


Posted by shenh at 12:42 AM EDT
perl environment

1): which perl
/usr/bin/perl

2): which perl version
perl -v
perl -version

3): which perl path
PERL5LIB=c:\perl\lib;c:\perl\site\lib
perl -e 'print join "\n", @INC'
perl -e 'print "\@INC is @INC\n";'

# add a search path for perl lib
{push @INC, "/tmp"}

#use lib "/tmp";


4): where is the perl module
4a): perl -MDBD::Oracle -e 'print $INC{"DBD/Oracle.pm"}, "\n"'

perl -MDBI -e 'print $INC{"DBI.pm"}, "\n"'
perl -MTerm::ReadKey -e 'print $INC{"Term/ReadKey.pm"}, "\n"'

4b): which perl module is installed
find . -name ReadKey.pm -exec ls -l {} \;

./perl5/site_perl/5.8.0/sun4-solaris/Term/ReadKey.pm

# for each perl module, find its pm file
find . -name "*.pm" -print
find . -name "*.pm" -exec ls -l { } \;
find . -name "*.pm" -print|xargs ls -l
find . -name "*.pm" |xargs ls -l

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

# perl DBI version
perl -MDBI -e 'DBI->installed_versions;'
perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";'
perl -MDBD::Oracle -e 'print $INC{"DBD/Oracle.pm"}, "\n"'

 


Posted by shenh at 12:31 AM EDT
Friday, 27 March 2009


perl books:
http://www.perl.org/books/library.html
http://www.freeprogrammingresources.com/perlbook.html

Best:

Practical Perl Programming
http://www.cs.cf.ac.uk/Dave/PERL/
 

Essentail Perl
http://cslibrary.stanford.edu/108/
http://cslibrary.stanford.edu/108/EssentialPerl.html

vsbabu

http://vsbabu.org/tutorials/perl/index-2.html#ss2.1

http://www.urgentclick.com/perl-tutorial.html


http://www.perlmonks.org/index.pl?node=Tutorials


http://www.ebb.org/PickingUpPerl/pickingUpPerl.html


http://www.perltutorial.org/


http://www.comp.leeds.ac.uk/Perl/start.html


http://www.perl.com/pub/a/2000/10/begperl1.html


http://www.tizag.com/perlT/perlfirstscript.php


http://www.sthomas.net/roberts-perl-tutorial.htm


http://www.pageresource.com/cgirec/index2.htm

http://affy.blogspot.com/p5be/index.htm

http://docs.rinet.ru/P7/

http://www.linuxtopia.org/online_books/perl/index.html

http://www.faqs.org/docs/perl5int/

http://www.perl.com/pub/a/2000/10/begperl1.html
http://www.perl.com/pub/a/2000/11/begperl2.html
http://www.perl.com/pub/a/2000/11/begperl3.html
http://www.perl.com/pub/a/2000/12/begperl4.html
http://www.perl.com/pub/a/2000/12/begperl5.html
http://www.perl.com/pub/a/2001/01/begperl6.html

http://www.perl.com/pub/a/2008/04/23/a-beginners-introduction-to-perl-510.html
http://www.perl.com/pub/a/2008/05/07/beginners-introduction-to-perl-510-part-2.html


http://news.oreilly.com/2008/06/a-beginners-introduction-to-pe.html


http://broadcast.oreilly.com/2008/09/a-beginners-introduction-to-pe.html

http://www.perl.org/books/beginning-perl/  Simon Cozens ( good but in pdf format )

 


Posted by shenh at 10:41 PM EDT
Updated: Saturday, 28 March 2009 11:05 PM EDT

Newer | Latest | Older