May 15, 2012

send email in perl

There are 3 ways to send mail from Perl
  • shelling out to /usr/sbin/sendmail
  • using Net::SMTP directly when the application did not need to send attachments
  • using MIME::Lite when you did need to include attachments

Out of these MIME::Lite is best as it handles attachments and performance perspective.
Let us explain sending email using MIME::Lite 


#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use MIME::Lite;

    my $msg = MIME::Lite->new(
        From     =>'admin@example.com',
        To       =>'user@example.com',
        Subject  =>'testing a mail with attachments',
        Type =>'multipart/mixed'
    ) die "Error creating multipart container: $!\n";
  
    ### Add the text message part
    $msg->attach (
      Type => 'TEXT',
      Data => "Here is the attachment file(s) you wanted"
    ) or die "Error adding the text message part: $!\n";

    ### Add the GIF file
    $msg->attach (
       Type => 'image/gif',
       Path => my_file.gif,
       Filename => your_file.gif,
       Disposition => 'attachment'
    ) or die "Error adding $file_gif: $!\n";

    ### Add the ZIP file
    $msg->attach (
       Type => 'application/zip',
       Path => my_file.zip,
       Filename => your_file.zip,
       Disposition => 'attachment'
    ) or die "Error adding $file_zip: $!\n";

       $msg->send;

1;





Delete logs older than 7 days

#! /usr/bin/perl

use strict;
use warnings;
#use CGI;
#use CGI::Carp qw(fatalsToBrowser);   
use Data::Dumper;

foreach my $file (</test/logs/log_*.txt>) {   
    if ( -M $file > 7 ) {
        print "\n Deleting the log file more than 7 days old: " . $file;
        unlink $file; #or die "\nFailed to remove $file: $!";
    }
}

print "\n\n";


1;


Note:
  • The above program is based on the time stamp of the files. 
  • The program detects files staring with 'log_' format and deletes these files whose time stamp of the file is greater than 7 days (since the current time stamp).
  • '-M' is used to check the timestamp
  • 'ulink' is used to remove file 
  • Please change the corresponding shebang line  (#! /usr/bin/perl) if you are using windows environment to test this perl script
  • In the above example, in the specified path (/test/logs/) I have some files like... Let us assume we have files like this 
log_1.txt (7 days old)
log_2.txt (8 days old)
log_3.txt (9 days old)
log_4.txt (10 days old)
log_5.txt (3 days old)
log_6.txt (4 days old)
error_log.txt (10 days old)
server_log.txt (10 days old)

Program Output: The program will delete files
log_1.txt, log_2.txt, log_3.txt, log_4.txt

Since the files 'error_log.txt' and 'server_log.txt' won't start with 'log_' the program don't delete them irrespective of the timestamp.


May 14, 2012

Perl Books

Please find all the Perl books at one place. For Perl, O'Reilly series books are well known.

As a Perl developer, I have personally gone through books of O'Reilly series books and I found those books are informative and useful for my career as a developer.

I have gone through books like Programming Perl, Perl Best Practices, Mastering Regular Expressions etc.,

Note: Please note that I am not marketing O'Reilly books in anyway. Its my personal opinion.

For your ease, I am keeping the collection of Perl books at one place, please go through.


Learning Perl :




Programming Perl :


Intermediate Perl :




Mastering Perl :
Link to be updated.....

Begenning Perl :


Perl Best Practices:


Object Oriented Perl:


Minimal Perl:


Perl Hacks:


Perl CookBook


Perl for Dummies:


Advanced Perl Programming:


Automating System Adminstration with Perl:



Mastering Regular Expressions:


Regular Expressions Cookbook:

May 11, 2012

Non Capturing Paranthesis (?:) in Regular Expressions

From my earlier blog on capturing, you might have understood about the capturing concept in regular expressions.

Let us now look the Non-capturing concept in regular expressions with a simple example

To achieve non-capturing parenthesis use "?:" 

E.g.  $input = +456.987c
        $input = ~/([-+]?[0-9]+(?:\.[0-9]*)?)([cf])$/     
   
     Where  $1 = ([-+]?[0-9]+(\.[0-9]*)?) #which matches '456.987'
                  $2 = ([cf])                                #which matches 'c'




Carefully observe, here
$2 is not (?:\.[0-9]*) but instead it is ([cf]), why because (?:\.[0-9]*) is starting with ?: which means it is not being captured, so $2 becomes ([cf])
                     
Advantages of Non-Capturing:
    1) Avoids unnecessary Capturing (Matches only what ever required)
    2) Efficiency Enhancement



Please refer to my earlier blog on capturing

I will be discussing about "Look Around" concepts of regular expressions in my coming blog.

Don't hesitate to comment if you have any doubts or queries on this topic.

Thanks for your valuable time and have a great day :-)


May 9, 2012

Capturing in Regular Expressions

Parenthesis inside regex will be grouped as well as captured.
Let me explain the grouping concept with an example where in you want to validate a decimal part

Eg: Validation for decimal part as given in the below mentioned example

        $input = +345.34f
        $input = ~/([-+]?[0-9]+(\.[0-9]*)?)([cf])$/
        where
                  $1 = /([-+]?[0-9]+(\.[0-9]*)?)    # 345.34
                  $2 = (\.[0-9]*)                            # .34
                  $3 = ([cf])                                  #  f

Notations used in the above example :
1) $1, $2, $3 are grouping data, one can capture the specific data and use it later in the program with $1, $2, $3 etc.,
2) *, + are greedy operators, they match more than what they required, that's why they are called as Greedy Operators
3) ? is a limiting operator which limits the mapping to what ever required
4) [] is a character class
5) $2 lies within $1 even then they both are distinct
6) $ represents the end of the string

Advantages of capturing:
 a) You can capture the data and use the data later in the program
 b) Very useful when we want to grep or capture tricky regex

Disadvantages of unnecessary Capturing:
 a) Waste of memory.
 b) Performance problem.
 c) Regex will be costlier


I hope you have really liked today's topic.

Please share your views with me in case of any any doubts/suggestions. Feel free, don't hesitate :-)

I will be explaining about the Non-Capturing Parenthesis in my next blog. Keep watching my blog.

Thanks for your valuable time. Have a good day :-)

May 4, 2012

Regular expressions or Regex or Regexp

Regular Expressions are some patterns describing some amount of text.

Real World Application of Regular Expressions:
Suppose you have a file that contains comma separated employee details like
First name, Last name, Cell no, Salary, address, Email etc.,
1) You want to extract only the Employee name and email-id from that huge list of data.

2) You are looping through the employee details, you just want to pick all the employees info whose salary is greater than 5000$
3) You want to replace all the occurrences of a misspelled employee name
e.g., Grorge to George

And lot more............



Advantages of Regular Expressions:
1) Regular expressions is a part and parcel in Perl.
2) It makes the life easy for a developer or programmer to search/replace a pattern in a line.
3) It saves a lot of time of the developer or programmer


General Topics on Regular Expressions:
1) Search & Replace
2) Start and End of String or Match
3) Word Boundaries etc.,


Advanced Topics on Regular Expressions:
1) Capturing
2) Non-Capturing PAranthesis
3) Look Around Concepts
4) Look Ahead
5) Look Behind
6) Back Tracking
7) Atomic Grouping
8) Possessive Quantifiers etc.,

We will discuss these topics one by one in brief in the coming posts.
Thanks for your valuable time, Have a good day :-)


Apr 29, 2012

use of $_

#!F:\Perl\bin\perl -w
use strict;

1) print "\n", $_ for (1..10);

2)
my %hash = ( a => 100, b => 200, c => 300);
print "\n", $_ for keys(%hash);:

Apr 27, 2012

CPAN - Perl Modules Repository



   



You can find lots and useful perl modules in the site www.cpan.org
The commonly used modules are :
1) strict
2) warnings
3) Time::Local
4) CGI
5) Data::Dumper
6) Carp etc.,


Another way to delete old files in perl

Note: 
1) Please remove comment (#)
2) 'unlink' is the command used to remove file in Unix
 
#!perl
foreach my $file (</path/to/logs/*.log>) {
  next unless -M $file > 7;
  print "Deleting the File $file...\n";
  # unlink $file or die "Failed to remove file $file: $!";
}
-->

Apr 26, 2012

Delete files older than X days on Linux


find /path/to/files* -mtime +5 -exec rm {} \;

This is an example, which deletes files older than 5 days from unix command line itself

Note:
1)  Apply this from unix command line itself

Jun 22, 2008

Array in Perl

Array:

Its a sequenced list of elements.
Array index starts with zero.

use strict;
use warnings;
use Data::Dumper;

my @arr = ("Mother Teresa", "Abraham Lincoln", "Winston Churchill", "Mahathma Gandhi");

print "\n Print Array Values just like that : @arr";

print "\n\n Print Array Values with Dumper : " . Dumper(\@arr);


my @num_arr = qw/100 200 300/;

print "\n First Val : " . $num_arr[0];

print "\n";

Outout :

 Print Array Values just like that : Mother Teresa Abraham Lincoln Winston Churchill Mahathma Gandhi

 Print Array Values with Dumper : $VAR1 = [
          'Mother Teresa',
          'Abraham Lincoln',
          'Winston Churchill',
          'Mahathma Gandhi'
        ];

 First Val : 100
  


Please refer to other topics in Perl like :
How to read command line arguments in Perl
How to pass command line arguments to perl script
Loop through Directory and read the files in Perl
How to create excel report in Perl


Please refer to other topics on Unix like :
Unix Delete Duplicated Lines in a File
Unix Unique Lines in a File
Unix Grep Examples
Unix Cut Command Examples
Search a Directory in Unix
Unix For Loop
pushd & popd in Unix
Find Size of Directory
Word Count


Please refer to other topics on AWK like :
Awk Examples
Print First Two Columns of File
Print Last Two Columns of File


Please refer to other topics on Dict like :
Dict in Python
Dict keys and values in Python


Please refer to other topics on List like :
List in Python
Append to list in Python
Delete the last name from the list in Python
Remove an element from List in Python
Check an element exists in an list in Python
Python Filter Vs Map Vs List Comprehension


Please refer to other topics on File Concepts like :
Print File Content in Python
Print File in Reverse Order in Python


Please refer to Regular Expressions Concepts :
Brief on Regular Expressions
Greedy Operators in Regular Expressions in Perl
Modifiers in Regular Expressions in Perl
Capturing concept in Regular Expressions in Perl
Capture Pre Match ,Post Match, Exact match in Regular Expressions in Perl
Non Capturing Paranthesis in Regular Expressions in Perl
Substitute nth occurance in Regular Expressions in Perl
All Topics in Regular Expressions in Perl


You might also wish to read other topics on Python like :
Python Class and Object Example
Inheritance in Python
Packages in Python
Exceptions in Python
How to remove duplicate lines from a file in Perl
How to remove duplicate lines from a file in Pyhton


Scalar

Scalar : 

In Perl, scalar can store a single value at any time.
In the following example, $str contains a string value.
We can store any single integer, string, float value in a scalar. It's as simple as that.

E.g., $str1 = 100;
        $str2 = 'test';
        $str3 = 300.2;


use strict;
use warnings;
use Data::Dumper;

#In Perl, scalar can store a single value at any time.
#In the following example, $str contains a string value.
#We can store any single integer, string, float value in a scalar. It's as simple as that.


#Integer
my $num = 300;
print "\n Number : " . $num;

#String
my $str = "Alex Perter John Dane";

#Array
my @arr = split(/ /,$str);

print "\n After Split : " . Dumper(\@arr);
  

Output:
 Number : 300
 After Split : $VAR1 = [
          'Alex',
          'Perter',
          'John',
          'Dane'
        ];


Please refer to other topics in Perl like :
How to read command line arguments in Perl
How to pass command line arguments to perl script
Loop through Directory and read the files in Perl
How to create excel report in Perl


Please refer to other topics on Unix like :
Unix Delete Duplicated Lines in a File
Unix Unique Lines in a File
Unix Grep Examples
Unix Cut Command Examples
Search a Directory in Unix
Unix For Loop
pushd & popd in Unix
Find Size of Directory
Word Count


Please refer to other topics on AWK like :
Awk Examples
Print First Two Columns of File
Print Last Two Columns of File


Please refer to other topics on Dict like :
Dict in Python
Dict keys and values in Python


Please refer to other topics on List like :
List in Python
Append to list in Python
Delete the last name from the list in Python
Remove an element from List in Python
Check an element exists in an list in Python
Python Filter Vs Map Vs List Comprehension


Please refer to other topics on File Concepts like :
Print File Content in Python
Print File in Reverse Order in Python


Please refer to Regular Expressions Concepts :
Brief on Regular Expressions
Greedy Operators in Regular Expressions in Perl
Modifiers in Regular Expressions in Perl
Capturing concept in Regular Expressions in Perl
Capture Pre Match ,Post Match, Exact match in Regular Expressions in Perl
Non Capturing Paranthesis in Regular Expressions in Perl
Substitute nth occurance in Regular Expressions in Perl
All Topics in Regular Expressions in Perl


You might also wish to read other topics on Python like :
Python Class and Object Example
Inheritance in Python
Packages in Python
Exceptions in Python
How to remove duplicate lines from a file in Perl
How to remove duplicate lines from a file in Pyhton


Get unique elements from string

#!F:\Perl\bin\perl -w
use strict;
use Data::Dumper;
my $abc = "prabhath vamsi vamsi eswar sandhya vinayaka ";

my @arr = split /\s+/, $abc;
my %uniq = map { $_, 1} @arr;
my @final = keys %uniq;
print Dumper(\@final)

map

1)
$str = "2-5,3-9,1-2,8-1,4-7,5-9,20-3,16-9";
@array=split(/,/, $str);
my @a1= (map
{
($left,$right)=split(/-/,$_);
$left*$right;
}
@array
);
print join(",",@a1),"\n";

2)
@array = (20, 3, 1, 9, 100, 88, 75);
my @new_array = (map { $_*2; } @array);
print join(",", @new_array), "\n";

reverse keyword

#!F:\Perl\bin\perl -w
use strict;

my $a=9;
print "Before Reverse:\n", (1..$a);
print "\nAfter Reverse:\n", reverse (1 .. $a);

Get unique keys from different hashes

- As we konw, keys in a hash are unique, but not the values.

#!F:\Perl\bin\perl -w
use Data::Dumper;
use strict;

#Get unique keys from different hashes
my %hash1 = (a=>10,b=>20,c=>30);
my %hash2 = (a1=>10,b1=>20,c1=>30);
my %hash3 = (a=>10,b=>20,c=>30);
my %uniq_hash;
for my $each (keys(%hash1), keys(%hash2), keys(%hash3)) {
$uniq_hash{$each}++;
}
print "\n", $_ for (keys %uniq_hash),"\n";

Get unique elemenets from Arrays

#!F:\Perl\bin\perl -w
use Data::Dumper;
use strict;

#unique elements from different arrays
my @array1 = (10,20,30);
my @array2 = (11,22,33);
my @array3 = (10,20,30);
my %uniq_arr;

for my $each (@array2, @array3, @array1) {
$uniq_arr{$each}++;
}
print "\n", $_ for (keys %uniq_arr),"\n";

' tr ' or ' y '

Removing the duplicate characters from the string:

#!F:\Perl\bin\perl -w
use strict;


#Removing the duplicate characters ('c' , 'd') but not ('e') from the string
my $val = 'abcccdddddeeeeeeeeeeeeecccccc';
print "\n Given String:", $val;

$val =~ y/cd//s; # 'y' is nothing but 'tr'

print "\nAfter :$val\n";

Defining a undefined variable

If a variable is not defined, we can define like this instead of IF block.

#!F:\Perl\bin\perl
use strict;
use warnings;

# Very simple and easy to use
$a;
$a |= "prabhath";
print "\n Value is:", $a;


=cut
We can avoid the unnecessary if and defined code

$a = 'vamsi';
if ( not defined $a) {
$a = 'prabhath';
}
=cut

substitute for n'th occurance

#!F:\Perl\bin\perl -w
use strict;

# Substitue 3rd occurance of 'perl' with 'PERL'
my $text = 'perl is good, perl is better, perl is best';
print "\n INPUT Text:", $text;

my $nth_occurance = 3;
my $count=0;

$text =~ s{(perl)}{
++$count == $nth_occurance ? 'PERL' : $1
}ige;

print "\n OUTPUT Text:", $text,"\n";

Sort an Array

1) For number Array

#!F:\Perl\bin\perl -w
use Data::Dumper;

my @array = (20,10,50,40,30); #Unsorted Number Array
print "\n Unsorted Array is: @array";
my @sorted = sort { $a <=> $b } @array;

# '<=>' for numbers only
# 'cmp' used for numbers as well as strings
print "\n sorted Array is: @sorted";
my @sorted = sort { $a cmp $b } @array;

print "\n sorted Array is: @sorted";


2) For String Array

#!F:\Perl\bin\perl -w
use Data::Dumper;
#Unsorted String Array
my @array = qw/sandhya eswar prabhath vamsi/;
print "\n Unsorted Array is: @array";

my @sorted = sort { $a cmp $b } @array;

# 'cmp' can be used for both strings as well as numbers
print "\n sorted Array is: @sorted";

Slurp

- Slurp means reading or writing a file at one shot, instead of
reading or writing line by line.
- Generally slurp if very fast than normal reading a file line by line
- But slurp uses more memory, as it needs to keep th whole file
in a scalar (or) an array, but now a days as everybody is
having enormous amount of hard disk space and RAM, its not
a problem with Slurp.
- But those people where memeory and space concerns are there,
don't go for Slurp
- Some Cpan modules on Slurp are:
1) Slurp # Allows you to read multiple files at a time
2) File::Slurp # Good module for Slurp
3) Perl6::Slurp # Recent module on Slurp with lot more features


The Program will read a folder and read all the files and slurp them into an array and writes to output file
-------------------------------
#!F:\Perl\bin\perl -w

use Slurp;
use File::Slurp;
use Data::Dumper;
use strict;

my $dir='F:\Documents and Settings\Administrator\Desktop\sample_programs';
opendir DIR, $dir or die "cannot open dir $dir: $!";
my @file= readdir DIR;
closedir DIR;

my @final_files;
print "\n All file names before:", Dumper(\@file);

for (@file) {
next if($_ =~/^\.+|\.swp$|\~$/ig);
push (@final_files, $_);
}

my @zx = slurp(@final_files);
write_file('output.txt', @zx);

my @out = File::Slurp::read_file('output.txt');
print "\n output:" , Dumper(\@out);

Get a Random element from an Array

#!F:\Perl\bin\perl -w
use Data::Dumper;

my @array = (10,20,30,40,50);
#'rand' gives some random index number
$index = rand @array;
print "\n Random index from an array is:", $index;
$element = $array[$index];
print "\n Random element from an array is:", $element,"\n";

While loop in Perl

We can loop through For/Foreach/While in Perl.

We can discuss while loop now with the following example.



use strict;
use warnings;
use Data::Dumper;

my @names = ("Mother Teresa", "Abraham Lincoln", "Winston Churchill", "Mahathma Gandhi");

print "\n Looping While using counter";

my $i=0;

print "\n Scalar Array Size " . scalar(@names) . "\n";

while ($i <= $#names) {
   print "\n Looping ... " . $names[$i] . "\n";
   $i++;
}

print "\n";
  

Output :
 Looping While using counter
 Scalar Array Size 4

 Looping ... Mother Teresa

 Looping ... Abraham Lincoln

 Looping ... Winston Churchill

 Looping ... Mahathma Gandhi
 


Please refer to other topics in Perl like :
How to read command line arguments in Perl
How to pass command line arguments to perl script
Loop through Directory and read the files in Perl
How to create excel report in Perl


Please refer to other topics on Unix like :
Unix Delete Duplicated Lines in a File
Unix Unique Lines in a File
Unix Grep Examples
Unix Cut Command Examples
Search a Directory in Unix
Unix For Loop
pushd & popd in Unix
Find Size of Directory
Word Count


Please refer to other topics on AWK like :
Awk Examples
Print First Two Columns of File
Print Last Two Columns of File


Please refer to other topics on Dict like :
Dict in Python
Dict keys and values in Python


Please refer to other topics on List like :
List in Python
Append to list in Python
Delete the last name from the list in Python
Remove an element from List in Python
Check an element exists in an list in Python
Python Filter Vs Map Vs List Comprehension


Please refer to other topics on File Concepts like :
Print File Content in Python
Print File in Reverse Order in Python


Please refer to Regular Expressions Concepts :
Brief on Regular Expressions
Greedy Operators in Regular Expressions in Perl
Modifiers in Regular Expressions in Perl
Capturing concept in Regular Expressions in Perl
Capture Pre Match ,Post Match, Exact match in Regular Expressions in Perl
Non Capturing Paranthesis in Regular Expressions in Perl
Substitute nth occurance in Regular Expressions in Perl
All Topics in Regular Expressions in Perl


You might also wish to read other topics on Python like :
Python Class and Object Example
Inheritance in Python
Packages in Python
Exceptions in Python
How to remove duplicate lines from a file in Perl
How to remove duplicate lines from a file in Pyhton


Example on Greedy Operator ' * '

#!F:\Perl\bin\perl -w
use strict;

my $str = "perl is awesome, I am also awesome";
$str =~ /.*awesome/; # '*' is greedy operator, so it is not satisfied with the first occurance
print $&,"\n"; # perl is awesome, I am also awesome

#To restict the greeedyness to first occurance
#Use '?' operator to restrict the greediness
$str =~ /.*?awesome/;
print $&,"\n"; #perl is awesome

$^O gives the OS name

#!F:\Perl\bin\perl -w
use strict;
print "$^0\n";

Different ways to remove duplicates from array

#!F:\Perl\bin\perl -w
use strict;
use Data::Dumper;

#Remove duplicates from array.
my @array = qw/10 20 20 20 30 40 40 40 50 50 50/;
print "\n Duplicate array: @array";

1) Good

my %hash;
$hash{$_} = 0 for (@array);
# $hash{$_} = () for (@array); #You can do this also

my @final = keys (%hash);
print "\n Unique Array: @final";
print "\n";


2) Best of all

my %hash = map { $_ , 1 } @array;
my @uniq = keys %hash;
print "\n Uniq Array:", Dumper(\@uniq);


3) Costly process as it involves 'greping'

my %saw;
my @out = grep(!$saw{$_}++, @array);
print "\n Uniq Array: @out \n";

How to create an unique array

#!F:\Perl\bin\perl -w
use Data::Dumper;

my @array_with_duplicate_elements = qw/ 1 2 3 4 5 5 5 5 4 4 4/;
my %hash = map { $_, 1 } @array_with_duplicate_elements;
my @unique_array = keys %hash;
print Dumper(\@unique_array);

Hash in Perl

Hashes are like named key value pairs.
Keys are always unique, Values can be anything.
It's best practice to use hashes, they are efficient.

 

use strict;
use warnings;
use Data::Dumper;

my %hash = (a => 10,
            e => 40,
            c => 30,
            d => 40,
            b => 20,
            a => 100);

#Print Keys
print "\n Only Keys:\n" . Dumper(keys %hash);

print "\n\n";
#Print Values
print "\n Only Values:\n" . Dumper(values %hash);


print "\n\n";
#Print Keys and Values
while ( my ($key, $value) = each %hash)
{
   print "$key => $value\n";
}

print "\n\n";



#Print Keys
print "\n Sorted Keys:\n" . Dumper(sort keys %hash);

print "\n\n";
#Print Values
print "\n Sorted Values:\n" . Dumper(sort values %hash);
  
Output:

 Only Keys:
$VAR1 = 'e';
$VAR2 = 'c';
$VAR3 = 'a';
$VAR4 = 'b';
$VAR5 = 'd';



 Only Values:
$VAR1 = 40;
$VAR2 = 30;
$VAR3 = 100;
$VAR4 = 20;
$VAR5 = 40;


e => 40
c => 30
a => 100
b => 20
d => 40



 Sorted Keys:
$VAR1 = 'a';
$VAR2 = 'b';
$VAR3 = 'c';
$VAR4 = 'd';
$VAR5 = 'e';



 Sorted Values:
$VAR1 = 100;
$VAR2 = 20;
$VAR3 = 30;
$VAR4 = 40;
$VAR5 = 40;
  


Please refer to other topics in Perl like :
How to read command line arguments in Perl
How to pass command line arguments to perl script
Loop through Directory and read the files in Perl
How to create excel report in Perl


Please refer to other topics on Unix like :
Unix Delete Duplicated Lines in a File
Unix Unique Lines in a File
Unix Grep Examples
Unix Cut Command Examples
Search a Directory in Unix
Unix For Loop
pushd & popd in Unix
Find Size of Directory
Word Count


Please refer to other topics on AWK like :
Awk Examples
Print First Two Columns of File
Print Last Two Columns of File


Please refer to other topics on Dict like :
Dict in Python
Dict keys and values in Python


Please refer to other topics on List like :
List in Python
Append to list in Python
Delete the last name from the list in Python
Remove an element from List in Python
Check an element exists in an list in Python
Python Filter Vs Map Vs List Comprehension


Please refer to other topics on File Concepts like :
Print File Content in Python
Print File in Reverse Order in Python


Please refer to Regular Expressions Concepts :
Brief on Regular Expressions
Greedy Operators in Regular Expressions in Perl
Modifiers in Regular Expressions in Perl
Capturing concept in Regular Expressions in Perl
Capture Pre Match ,Post Match, Exact match in Regular Expressions in Perl
Non Capturing Paranthesis in Regular Expressions in Perl
Substitute nth occurance in Regular Expressions in Perl
All Topics in Regular Expressions in Perl


You might also wish to read other topics on Python like :
Python Class and Object Example
Inheritance in Python
Packages in Python
Exceptions in Python
How to remove duplicate lines from a file in Perl
How to remove duplicate lines from a file in Pyhton


Formatted Print

#!F:\Perl\bin\perl -w
use strict;

printf("\n%.2f", 19.9500000000000000000);
printf("\n%.3f", 19.9500000000000000000);