Perl

Stay ahead with the latest trends in custom software development. Explore how AI, automation, and cloud solutions are shaping the future of business technology.

Date/Time in a Timestamp format – Perl

Date/Time in a Timestamp format – Perl [perl] use Date::Manip; #### – Get DATE / TIME in correct format – ########## my $day= strftime “%d”, localtime; my $month= strftime “%m”, localtime; my $year = strftime “%Y”, localtime; my $now = localtime(time()); #################################################### $form_date_start = “$year/$month/$day 06:00:00”; [/perl]
Continue Reading

Flush perl‚ Äôs print buffer – $|=1

Flush perl‚Äôs print buffer – $|=1 If you put a print statement inside of a loop that runs really really quickly, you won‚Äôt see the output of your print statement until the program terminates. The solution to this problem is to ‚Äúflush‚Äù the output buffer after each print statement. Where $| is non zero, it […]
Continue Reading

GET or POST – Secure

GET or POST – Secure GET is NOT Secure GET is not a secure method of sending data. Don’t use it for forms that send password info, credit card data or other sensitive information. Since the data is passed through as part of the URL, it’ll show up in the web server’s logfile (complete with […]
Continue Reading

Perl – Trim Text, Trim String

Perl – Trim Text, Trim String Left trim- ltrim or lstrip removes white spaces from the left side of a string: [perl] $str =~ s/^\s+//; [/perl] Right trim – rtrim or rstrip removes white spaces from the right side of a string: [perl] $str =~ s/\s+$//; [/perl] Trim Both [perl] $str =~ s/^\s+|\s+$//g [/perl] [perl] […]
Continue Reading

Recursively Expand a NIS Netgroup

Recursively Expand a NIS Netgroup @results=expand_ng(); # Given a netgroup, will return a list of members. Will recurse # netgroups if the $recurse flag is set sub expand_ng { my($netgroup)=@_; my(@returnng); my($ng)=`ypmatch $netgroup netgroup`; $? != 0 and return; #Don't continue for duff netgroups my($value); $ng =~ s/\s+/ /g; #Compress whitespace $ng =~ s/\s+,/,/g; #Remove […]
Continue Reading

Add a timestamp to every STDOUT line

Add a timestamp to every STDOUT line I found this useful for debugging and just handy to have in the toolbox. Alias within your profile! Use: ./anyscript_you_choose | ./addtime [perl] #!/bin/perl -w # filename: ./addtime my($old)=select(STDOUT); $|=1; select(STDIN); $|=1; select ($old); while(<>) { my($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst)= localtime (time); printf “%02d:%02d:%4d %02d:%02d:%02d %s”,$mday,$mon+1,$year+1900,$hour,$min,$sec,$_; } [/perl]
Continue Reading