Academic Tutorials



English | French | Portugese | Dutch | Italian
Google

em linha

Home Códigos de fonte E-Livros Downloads Contatar-nos Sobre nós

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting


Manipulação da lima do Perl

Previous Next





In PERL files are given a name, also called handle. All the input and output of the file is achieved by filehandling functions. Filehandles are also a means to communicate from one program to another program.


How to assign handles

A filehandle is nothing but name given for the files which you intend to use in your PERL programs and scripts. A handle is a name which is temporarly assigned to a file. The example below shows how to use a file handle in your PERL program.

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header
$FilePath = "home/html/myhtml.html"
sysopen(HANDLE, $FilePath, O_RDWR);
printf HANDLE "Welcome to Tizag!";
close (HANDLE);


Files with the die Function

The die function also exists in several other programming languages. It is used to kill your scripts and also helps to pinpoint where/if your code is failing. We use this function as as shown below.

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header

$filepath = "htmlpage.html";

sysopen (HTML, '$filepath', O_RDWR|O_EXCL|O_CREAT, 0755) or die "$filepath cannot be opened.";
printf HTML "<html>\n";
printf HTML "<head>\n";
printf HTML "vtitle>My Home Page</title>";
printf HTML "</head>\n";
printf HTML "<body>\n";
printf HTML "<p align='center'>Here we have an HTML
page with a paragraph.</p>";
printf HTML "v/body>\n";
printf HTML "</html>\n";
close (HTML);

If due to some problem PERL is unable to open or create our file, we will be informed. It is good practice to make use of the die function and we will be using it as we go deeper into the file handling.


How to Open the File

Files can be opened using either of open and sysopen function. for either of the function can pass upto 4 arguments, the first argument is always the file handle, then the file name also known as a URL or filepath, flags, and finally any of the permissions that are to be granted to the file. The following program opens up a previously saved HTML document.

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header

$FH = "filehandle";
$FilePath = "htmlpage.html";

open(FH, $FilePath, permissions);
or
sysopen(FH, $FileName, permission);

Files which are having unusual file names or special characters are all best opened by declaring the URL first, as a variable. This method removes the confusion that might occur when PERL tries to interpret the program. However, filenames require a step for a brief character substitution before which they can be placed into the open statements.


Various File Permissions

File permissions are crucial to the file function and security. For instance, in order to function, a PERL file (.pl) must have executable file permissions in order to function on your web server. Also, you may not want all of your HTML files to be set to allow others to write to them or over them. Here's a listing of what to pass to the open function when working with file handles.

Shorthand Flags:

Entities Definition
< or r Read Only Access
> or w Creates, Writes, and Truncates
>>or a Writes, Appends, and Creates
+< or r+ Reads and Writes
+> or w+ Reads, Writes, Creates, and Truncates
+>> or a+ Reads, Writes, Appends, and Creates

O_ Flags:

Value Definition
O_RDWR Read and Write
O_RDONLY Read Only
O_WRONLY Write Only
O_CREAT Create the file
O_APPEND Append the file
O_TRUNC Truncate the file
O_EXCL Stops if file already exists
O_NONBLOCK Non-Blocking usability

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header
use Fcntl; #The Module

sysopen (HTML, '/home/html/htmlpage.html', O_RDWR|O_EXCL|O_CREAT, 0755);
sysopen (HTML, >htmlpage.html');


File Creation

Files are opened and created using the same function "sysopen". Our syntax open(FILEHANDLE, '$filename', permissions, CHMOD); or sysopen(FILEHANDLE, $filename, permissions, CHMOD);

#!/usr/bin/perl
use Fcntl; #The Module

print "content-type: text/html \n\n"; #The header
sysopen (HTML, 'myhtml.html', O_RDWR|O_EXCL|O_CREAT, 0755);
printf HTML "<html>\n";
printf HTML "<head>\n";
printf HTML "<title>My Home Page";
printf HTML "</head>\n";
printf HTML "<bodyv\n";
printf HTML "<p align='center'>Here we have an HTML
page with a paragraph.</p>";
printf HTML "</body>\n";
printf HTML "</html>\n";
close (HTML);

With sysopen you can also set hexadecimal priviledges; CHMOD values. Sysopen needs the declaration of a new module for PERL. We will now be using the Fcntl module.


Reading from a File

It is easy to read lines from files and then input them using the input operator <>. By placing the file handler inside the input operator, then your script will input that line of the file..

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header
$HTML = "htmlpage.html";
open (HTML) or die "Can't open the file!";
print <HTML>;
close (HTML);

Here we have a small PERL script to display several lines of HTML code. Each line is stored into an array and it is automatically printed to the browser in HTML format using the input operator <> .


Copy uma lima

Usando a função da cópia nós podemos duplicar a lima. O copy faz exame de dois argumentos, o URL da lima que necessidades ser copí e o URL da lima/diretório novos a que a lima deve ser copí. Se a mesma lima - o nome está ou o mesmo URL, reescrita do Perl sobre a lima se as permissões permitidas.

#!/usr/bin/perl
use File::Copy;

print "content-type: text/html \n\n"; #The header
$filetobecopied = "htmlpage.html.";
$newfile = "html/htmlpage.html.";
copy($filetobecopied, $newfile) or die "File cannot be copied.";

Aqui, nós duplicamos simplesmente a lima de “htmlpage.html” e estaremos usando-a nos exemplos futuros. Ao usar o Perl na correia fotorreceptora, é a mais melhor usar o URL completo do Internet. Nós usamos uma maneira do shorthand no exemplo, mas é melhor ao hardcode o URL cheio como: http://www.vyom.co.in/htmlpage.html.


Movendo as limas

Mover a lima requer o uso da função do “movimento”. Esta função trabalha similarmente à função da cópia de acima e nós emitimos o mesmo módulo ao Perl. A diferença é aqui está, em vez copí dos nós apenas “cortados” a lima e emite-a a uma posição nova. Este que funciona é mesmo que o corte e o texto colando do original do escritório a outro.

#!/usr/bin/perl
use File::Copy;

print "content-type: text/html \n\n"; #The header
$oldlocation = "htmlpage.html";
$newlocation = "html/htmlpage.html";
move($oldlocation, $newlocation);

Nossa lima tem sido removida agora completly de sua posição atual à posição nova.


Suprimindo as limas

Para suprimir limas específicas de seu web server usar “unlink” a função. A mais melhor maneira é frequentemente ajustar um nome variável igual ao URL da lima que você deseja suprimir.

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header
$file = "newtext.txt";
if (unlink($file) == 0) {
print "File deleted successfully.";
} else {
print "File was not deleted.";
}


Removendo as limas múltiplas em uma vez

Para remover as limas múltiplas em uma vez, nós devemos primeiramente criar uma disposição das limas que tenha que ser suprimida e então dado laços com cada. Há muitas outras maneiras ir sobre este processo.

#!/usr/bin/perl

print "content-type: text/html \n\n"; #The header
@files = ("newtext.txt","moretext.txt","yetmoretext.txt");
foreach $file (@files) {
unlink($file);
}





Previous Next

Keywords:perl tutorial, perl scripts, perl programming, active perl, perl download, blackberry perl, perl regular expressions, perl split, perl array, perl script page


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizes
Oracle Quiz
MySQL Quiz
Operating System Quizes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizes
Testing Quiz
Firewalls Quiz
SAP Module Quizes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizes
Corba Quiz
Networking Quiz
Microsoft Office Quizes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizes
Financial Accounting Quiz
Managerial Accounting Quiz

Privacy Policy
Copyright © 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.