© 2023 PodTECH IO
All rights reserved.

Get in Touch

Perl

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

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’; […]

Perl

send: Cannot determine peer address

Looking into IO::Socket at http://search.cpan.org/src/GBARR/IO-1.2301/IO/Socket.pm reveals: [perl] sub send { @_ >= 2 && @_ <= 4 or croak ‘usage: $sock->send(BUF, [FLAGS, [TO]] +)’; my $sock = $_[0]; my $flags = $_[2] || 0; my $peer = $_[3] || $sock->peername; croak ‘send: Cannot determine peer address’ unless($peer); [/perl] So you have to take care that […]

Perl

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

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 […]

Perl

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

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

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 […]

Perl

PERL – Bitwise OR XOR an array

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

Perl Hex to Binary to Decimal Conversions

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. $decvalue = 200; $hexvalue = sprintf(“%x”, $decvalue); ## gives c8 $hexvalue = sprintf(“%X”, $decvalue); ## gives C8 Dec to Oct Use sprintf(“%o”, DECNUMBER ) $decvalue = 200; $octval = sprintf( “%o”, $decvalue […]