Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: concatenate a number and a string

$text = "Perl version ";
$value = 6.0;
$concat =$text . $value ;
print "I use  $concat";

Perl: Bitwise and Bit Shift Operators

#!/usr/bin/perl
$bin=8;              # 1000
$number = $bin > 1; # right shift
print $number,"n";

Perl: Binary, octal, and hexadecimal conversion

#!/usr/bin/perl
$hexadecimal="0x2e"   ;
$value = hex($hexadecimal);         #47
print $value,"n";
$octal= "056";
$value = oct($octal);

Perl: String comparison

 #!/usr/bin/perl
# convert to int before comprison
$result = "64" < "128";
print $result,"n";
$result = "255" gt "128";
print $result,"n";

Perl: Generate random numbers

#!/usr/bin/perl
for $x (0..9)
{
# generate random numbers between 1 and 9
$random = int( rand(9)) + 1;
print "Random $x: # $random";
}

Perl: How to Binary number

#!/usr/bin/perl
print 0b11111111, "
";   # 255
print 0b10000000, "
";   # 128
print 0b01000000, "
";   # 64
print 0b00100000, "
";   # 32
print 0b000

Perl: String to number conversion

#!/usr/bin/perl
$value_simple=3.5;
$value_str="6";
$prod= $value_str * $value_simple;
print "$prodn";  # 21

Perl: Generate random passwords

#!/usr/bin/perl -w
use warnings;
@chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ &#038; *) );
$password = join("", @chars[ map { rand @chars

Perl: Using binary operators on a string

#!/usr/bin/perl -w
$text = 'aa' | 'bb';
print "$textn";       
$text = 'cc' &#038; 'gg';
print "$textn";     
$text = "xx" ^ "**";
print "$textn";    
[/p

Perl: Random values selection from a list

#!/usr/bin/perl
use warnings;
@tab = qw( Monday Tuesday Wednesday Thursday friday saturday );
print "@tab";
# Randomly select a value from the array

Perl: bitwise logical operators

#!/usr/bin/perl -w
$number = 42 &#038; 18;       # AND Operator
print "1:# $number";   
$number = 42 | 18;       # OR  Operator
print "2:# $number";  
$nu