Kangry.com [insert cool graphic here]
home | Topics | Logout | Search | Contact | ?? Kangry ?? | Bandwitdh
Topics:
DVR
nvrec
Mplayer
Links
Misc
Commands
Humor

Name

Password

New user

uploaded files
(links)-> (Parent)->Perl code samples and links submited by Russell Fri 27 Jan 06
Edited Sat 05 May 12
Web kangry.com
Random File I/O with Perl

binary direct read from file
read FILEHANDLE, $VAR, LENGTH [ , OFFSET ]
Reads LENGTH binary bytes from the file into the variable at OFFSET. Returns number of bytes actually read.
Perl Array Functions This is part of a larger Online Lecture on perl Contains lots of good and simple examples.

Perl fork without waiting on child process: waitpid PID,FLAGS

use POSIX ":sys_wait_h";


do {
$x=fork();
if ($x==0)
  {  ## this is the child
    ## do something that could take a long time or never end
    exit(0); ## exits the child 
  }

$PIDS{$x}=$x;


foreach (keys %PIDS )
 {
   print "waiting for $PIDS{$_} ";
   $retval=waitpid($_,&WNOHANG);
     if ($retval > -1) {delete $PIDS{$retval};print "($retval exited)"};    
 } ## end foreach
print "\n";

sleep 30;
}until (1==2);
This code sample will start the child every 30 seconds, no matter what. (even if the child takes a long time to complete) The script can be left running continiously. if it didn't call wait() , or in this case waitpid(), you will end up fork() bombing your system. this solves that problem and solves the problem where some instances of the child take a long time to complete. ( slow/bad network conections etc.. see my issues with optium oinline )

BTW, &WNOHANG has a value of 1. So if the 'use' command doesn't work for you, just do "waitpid($PID,1);" that's bad form, and perhaps it's not 1 on all systems, but perl code isn't really about good form, it's about getting the job done with the least time spent coding possible.


perl get current username
($my_user_name, $pass, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire) = getpwuid($<);
gets current username using the numeric user-id and the password file contents. ( on modern systems, that use a shadow password file, $pass will be "x" which is only a placeholder )
Remove HTML tags leaving only text
$htmlCode =~ s|<.+?>||g;
Check out the discussion on stack overflow about how that is probably not a good idea, and you should use a more powerful tool.


Add comment or question...:
Subject:
Submited by: NOT email address. Leave blank for anonymous    (Spam Policy)

Enter Text: (text must match image for posting)




This file (the script that presented the data, not the data itself) , last modified Tuesday 06th of March 2018 11:41:12 PM
your client: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
current time: Thursday 25th of April 2024 07:29:39 AM