Perl – Sending Email with NET::SMTP using username and password

First of all double check that Authen::SASL is an installed module.. If you are not getting emails this could be why – it doesnt provide an error that is understandable! #!/usr/bin/perl ### ENSURE Authen::SASL is installed use Net::SMTP; use strict; use warnings; my $host= ‘yourhostname’; my $username= “yourpop3username”; my $password = “yourpassword”; my $from =[…]

Perl – Is a value decimal, real or a string?

To validate if a number is a number using regex. [perl] $number = “12.3”; if ($number =~ /\D/) { print “has nondigits\n” } if ($number =~ /^\d+$/) { print “is a whole number\n” } if ($number =~ /^-?\d+$/) { print “is an integer\n” } if ($number =~ /^[+-]?\d+$/) { print “is a +/- integer\n” }[…]

Perl – Basic Fork Example

#!/usr/local/bin/perl   use strict; use warnings;   print “Starting main program\n”; my @childs;   for ( my $count = 1; $count <= 10; $count++) {         my $pid = fork();         if ($pid) {         # parent         #print “pid is $pid, parent $$\n”;         push(@childs, $pid);         } elsif ($pid == 0) {                 # child                 sub1($count);                 exit 0;         } else[…]

Perl – Compare Array Contents when length is identical and order matches

Comparing arrays side by side. Do they match or dont they? @a=(1,0,1,0,0); @b=(0,0,1,0,0); NO! @arr1=(0,1,1,1,1,1,0,1); @arr2=(0,1,1,1,1,1,0,1); use Algorithm::Diff qw( LCS_length); my $arr_count1 = @arr1; my $arr_count2 = @arr2; if($arr_count1 != $arr_count2) { print “NOMATCH\n”; ## NO MATCH } else { $count = LCS_length (\@arr1,\@arr2); if ($arr_count1 eq $count) { print “MATCH\n”; ## identical arrays }[…]

PERL – Bitwise OR XOR an array

[perl] my @data= (“80″,”80″,”7B”,”30″,”32″,”30″,”38″,”31″,”46″,”30″,”39″); my $chk; foreach my $point(@data) { $chk = $chk^$point; ## XOR each array } $chk = hex($chk)|hex(“80”); ## OR the result value my $chk_hex=sprintf(“%x”,$chk); ## convert result to hex print “$chk = $chk_hex\n”; ## display both results side by side [/perl]

Perl Hex to Binary to Decimal Conversions

Dec to Hex Use function sprintf(“%x”, DECNUMBER) or sprintf(“%X”, DECNUMBER) for hexadecimal numbers with capital letters.

Dec to Oct Use sprintf(“%o”, DECNUMBER )

The program generates 317If you want a leading zero for the octal number use **sprintf(“%#o”, DECNUMBER);

The program now generates 0317 Dec to Bin Use sprintf( “%b”, DECNUMBER)