Perl Tutorial - Practical Extraction and Reporting Language (Perl)
Please leave a remark at the bottom of each page with your useful suggestion.
Table of Contents
- Perl Introduction
- Perl Program Startup
- Perl Regular Expressions
- Perl Array Program
- Perl Basic Program
- Perl Subroutine / Function Program
- Perl XML Program
- Perl String Program
- Perl Statement Program
- Perl Network Program
- Perl Hash Program
- Perl File Handling Program
- Perl Data Type Program
- Perl Database Program
- Perl Class Program
- Perl CGI Program
- Perl GUI Program
- Perl Report Program
Perl Programming Solution
Using Net::FTP to get a file on the server
use Net::FTP;
$ftp = Net::FTP-> new("ftp.cpan.org", Timeout => 30)
or die "Could not connect.\n";
$username = "anonymous";
$password = "asdf";
$ftp->login($username, $password)
or die "Could not log in.\n";
$ftp->cwd('/pub/CPAN');
$remotefile = "CPAN.html";
$localfile = "file.txt";
$ftp->get($remotefile, $localfile)
or die "Can not get file.\n";
File Read fileread.pl
call fileread.pl ../filename.xml
use strict;
use File::Basename;
my ($infile) = @ARGV;
my ($file,$dir,$ext) = fileparse($infile, qr/\..*/);
my $outfile = "$dir/$file\_out$ext";
open(IN,"<", "$infile") or die "doesn’t find $file $!";
undef $/; my $data = <IN>; close(IN);
$data=~s/a/b/sgi;
open (OUT, ">","$outfile");
print OUT $data;
close(OUT);
Functions Subroutine
# Type-1
&CleanUP($infile,$fdir,$fname);
sub CleanUP()
{
my ($infile,$fdir,$fname) = @_;
$data =~s/a/b/sgi;
}
# Type-2
$data=~s/(<p>(.*?)</p>)/&TabCol($&)/sgie;
sub TabCol()
{
my $txtdoll=shift;
$txtdoll=~s/\$/:textdoll:/sgi;
return($txtdoll);
}