Thursday, November 3, 2011

Perl - [Character class | Change | Replacement | For ]


#!/usr/bin/perl
use strict;
use warnings;

my $name = ' texto gerado automaticamente pelo sistema lattes ';
my $name1;

($name1 = $name) =~ s/o/OoO/g;

print "$name\n$name1\n";

for ($name){
    s/^\s+/+/;
    s/\s+$/++/;
    s/\s+/-/g;
}
print "$name\n";

my @names = ('comand','   ','line');

print "@names\n";

tr/ /./ for @names;

print "@names\n";

my ($num,$string,$space) = (10,'line',' ');

print "numero positive - $num \n"   if ($num =~ /\d/);
print "string positive - $string \n"    if ($string =~ /\w/);
print "space  positive - $space \n" if ($space =~ /\s/);

print "numero positive - $num \n"   if ($num =~ /\p{IsDigit}/);
print "string positive - $string \n"    if ($string =~ /\p{IsWord}/);
print "space  positive - $space \n" if ($space =~ /\p{IsSpace}/);

print "numero negation - $num \n"   if ($num =~ /\D/);
print "string negation - $string \n"    if ($string =~ /\W/);
print "space  negation - $space \n" if ($space =~ /\S/);

print "numero negation - $num \n"   if ($num =~ /\P{IsDigit}/);
print "string negation - $string \n "if ($string =~ /\P{IsWord}/);
print "space  negation - $space \n" if ($space =~ /\P{IsSpace}/);

results 

$perl  blog.pl
 texto gerado automaticamente pelo sistema lattes 
 textOoO geradOoO autOoOmaticamente pelOoO sistema lattes 
+texto-gerado-automaticamente-pelo-sistema-lattes++
comand     line
comand ... line
numero positive - 10 
string positive - line 
space  positive -   
numero positive - 10 
string positive - line 
space  positive - 

0 comentários:

Post a Comment