Códigos Útiles en Perl, creados por joshue moises

Inicio

 
Índice :
1.- Redireccionamiento.
2.- Enviar Mail con SendMail
3.- Parse Form
4.- Template
5.- Convertir Tags a &lt
6.- Open and Write A Flat File
7.- Inicio Programa (cabecera)
8.- Include a configuration File
9.- Generate Primary ID KEY
10.- Remove Bar Returns for Flat File Storage
11.- Mostrar las Enviroment Variables
12.- Date in 6 digit format
13.- Sub Write File
14.- Print Location
15.- Count Word String
16.- Count Letters string
17.- Content Type
18.- Replace car returns seed
 
Redireccionamiento de Browser.
print "Location: $destino\n\n";
 
Enviar Mail con SendMail
$maillocation = "/usr/lib/sendmail";
$email = "direccionemail\@hotmail.com"
open (MAIL, "| $maillocation -t") || die "aw, cant use $maillocation";
print MAIL "To: $email\n";
print MAIL "Reply-to: $emailcliente\n";
print MAIL "From: $emailcliente\n";
print MAIL "Subject: Envio de Recetas\n";
print MAIL "=======================================================\n";
print MAIL "Envio de Receta\n";
 
Parse Form
&parse_form;

sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}

@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}
}

 
Template
$templatepath = "c:\\portal\\cocina\\";
$template = "tmpl01.html";

open(HTMLFILE,"$templatepath" . "$template") or &ohdear("Imposible abrir : $template"); 
{ local $/; $htmlContent = <HTMLFILE> }
close(HTMLFILE);

$vitrinaText = $vitrinaText . " HTML A METER ";

############### Template Print ####################

$htmlContent =~ s/\*\*centro\*\*/$vitrinaText/;
$htmlContent = "Content-Type: text/html\n\n" . $htmlContent;
print "$htmlContent";


############### Sub For Error #####################

sub ohdear
{
print "Content-Type: text/html\n\n";
print "<font face='arial'><b>Ocurrio un error : $_[0]</b></font>\n";
exit;
}

  
Convertir Tags a &lt
$linktitle =~ s/</\&lt;/g;
$linkdescrip =~ s/</\&lt;/g;
 
Open and Write A Flat File
$file = "s2fsdfsdfds.dat"
$path = "c:\\raiz\\temp\\";
$filename = "$path" . "$file"

&open_file("FILE1",">>",$filename);

&write_file("FILE1",$linktitle . "|". $linkdescrip. "|" .$linkwords ."|" .$linkemail ."|" .$linkurl ."\n");
close(FILE1);

sub open_file {
local ($filevar, $filemode, $filename) = @_;
open ($filevar,$filemode . $filename) || die ("Can't open $filename");
}

sub write_file {
local ($filevar, $line) = @_;
print $filevar ($line);
}

 
Inicio de Programa Cabecera
#!/usr/bin/perl
 
Include a configuration File
require 'C:\portal\sdfgsdf\config.cgi';

############### in config.cgi  #####################

$fields = 5; # Number of fields in each record
$path = "/usr/local/zeus/web_roots/main/www.todacompra.com/search/"; # Path to script

 
Generate Primary ID KEY
$linkurl = &generatePassword;

sub selectRandomChar
{
local ($string) = @_;
return substr($string, (int rand(32767)) % length($string), 1);
}

sub generatePassword
{
local $consonants = "bcdfghjklmnprstvwxyz";
local $vowels = "aeiou";
local $ade = "ABCDEFG";
local $adem = "HIJKLMOPQRSTZ";
local $result;
srand(time);
$result .= selectRandomChar($consonants);
$result .= selectRandomChar($vowels);
$result .= selectRandomChar($ade);
$result .= selectRandomChar($adem);
$result .= selectRandomChar($consonants);
$result .= selectRandomChar($vowels);
$result .= int rand(10);
$result .= selectRandomChar($ade);
$result .= selectRandomChar($adem);
$result .= selectRandomChar($vowels);
$result .= selectRandomChar($consonants);
$result .= int rand(10);
return $result;
}

 
Remove Bar Returns for Flat File Storage
#Remove Bar Returns

$linkdescrip =~ tr/\n/+/;
$linkwords =~ tr/\n/+/;

#Add Bar Returns

$linkdescrip =~ s/\+/<br>/g;
$linkwords =~ s/\+/<br>/g;

 
Enviroment variables :
#!/usr/bin/perl

print "Content-type: text/html\n\n"; 
print "<tt>\n"; 
foreach $key (sort keys(%ENV)) { 
print "$key = $ENV{$key}<p>"; 


print "<hr>";
print "$ENV{'DOCUMENT_ROOT'}\n";
 
########Date in 6 digit format #########

$datestamp = sprintf "%02d%02d%02d", 
((localtime)[5]%100, (localtime)[4]+1, (localtime)[3]);
print $datestamp;
 
sub write_file
sub write_file {
local ($filevar, $line) = @_;
print $filevar ($line);
}
  
print location

print "Location: $opt2?op=izq\n\n";
 
count words string

$str = "And now to Xanthus' gliding stream they dove...";
$count = $str =~ s/((^|\s)\S)/$1/g;
print $count;

count letters string


$str = "And now to Xanthus' gliding stream they dove...";
$count = $str =~ s/([a-z])/$1/gi;
print $count;

Content-Type


print "Content-Type: text/html\n\n";

replace and move car returns


$extrahtml =~ tr/\n/+/;
$direccion =~ s/\+/<br>/g;

(C) Joshué Moisés García S.

 

Hosted by www.Geocities.ws

1