Quantcast
Channel: The Pod Blog » Perl
Browsing all 10 articles
Browse latest View live

PERL XOR 2 HEx values

Need to XOR to hex values… try this. $NEW_VAL = hex(80) ^ hex(9D);    

View Article


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 =...

View Article


Perl DBH get last id

SIMPLES with DBH Mysql   my $sth = $dbh->do(“$SQL”); my $id = $dbh->{‘mysql_insertid’};

View Article

PERL – Bitwise OR XOR an array

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...

View Article

Perl – Code Execution Time with accuracy – Time::HiRes

How long does it take to execute some code?   use Time::HiRes qw( time ); my $start = time(); // Code goes here sleep 10; my $end = time(); print “SPRINTF: “; printf(“%.6f\n”, $end – $start);      

View Article


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 =...

View Article

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) {...

View Article

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

To validate if a number is a number using regex. $number = "12.3"; if ($number =~ /\D/) { print "has nondigits\n" } if ($number =~ /^\d+$/) { print "is a whole number\n" } if ($number =~ /^-?\d+$/) {...

View Article


send: Cannot determine peer address

Looking into IO::Socket at http://search.cpan.org/src/GBARR/IO-1.2301/IO/Socket.pm reveals: sub send { @_ >= 2 && @_ <= 4 or croak 'usage: $sock->send(BUF, [FLAGS, [TO]] +)'; my $sock...

View Article


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...

View Article
Browsing all 10 articles
Browse latest View live