Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Clanpot Shake
Aug 10, 2006
shake shake!

The directories I'm copying to are monitored by various processes which consume the files I move. They're expecting a file to be there - I have no idea how they'd perform given a link. I don't expect it to go well.

Adbot
ADBOT LOVES YOU

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Clanpot Shake posted:

The directories I'm copying to are monitored by various processes which consume the files I move. They're expecting a file to be there - I have no idea how they'd perform given a link. I don't expect it to go well.

A hard link is a file, for all intents and purposes.

Clanpot Shake
Aug 10, 2006
shake shake!

I didn't write these listeners, so I have no idea how they'll work given a link. Given all the weird poo poo I've seen them do, I'm not counting on a link working in this case.

How do I move a file and set it to no read permissions in the destination?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Clanpot Shake posted:

I didn't write these listeners, so I have no idea how they'll work given a link. Given all the weird poo poo I've seen them do, I'm not counting on a link working in this case.

On unix-like systems, there is literally no difference between a link and a file. Every file is a link.

Clanpot Shake posted:

How do I move a file and set it to no read permissions in the destination?

Just set the file to no have read permissions, then move it. You don't need any permissions whatsoever on a file to move it.

Clanpot Shake
Aug 10, 2006
shake shake!

ShoulderDaemon posted:

On unix-like systems, there is literally no difference between a link and a file. Every file is a link.

Just set the file to no have read permissions, then move it. You don't need any permissions whatsoever on a file to move it.
Is there a way to do it without changing the source permissions? I've already written the thing and changing it to do links instead of copy sounds like more trouble than it's worth.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Clanpot Shake posted:

Is there a way to do it without changing the source permissions? I've already written the thing and changing it to do links instead of copy sounds like more trouble than it's worth.

To be honest, your entire problem doesn't make much sense to me. Moving files is just a rename operation; it's instantaneous, and there's no way for another process to read a file that's been "half-way moved".

It really sounds like you're copying a file, not moving it. If that's the case, you could perhaps copy to a temporary location, then move from that temporary location to the final location in order to avoid your race condition.

het
Nov 14, 2002

A dark black past
is my most valued
possession

Clanpot Shake posted:

Is there a way to do it without changing the source permissions? I've already written the thing and changing it to do links instead of copy sounds like more trouble than it's worth.
Judging by your original post you don't need to change permissions at all since it appears the permissions only ome into play because you're avoiding this application reading an incomplete file.. If you use rename (you should), the rename will be atomic (i.e., no worries about incomplete files being read and the like).

Note that if the source and destination directories are on different filesystems, you will not be able to hard link across them.

edit:

ShoulderDaemon posted:

To be honest, your entire problem doesn't make much sense to me. Moving files is just a rename operation; it's instantaneous, and there's no way for another process to read a file that's been "half-way moved".
If the CPAN module he's using to "move" the file is copying its contents rather than using rename, it can though

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
Well, yes, moving across file systems is a typical situation that I hadn't thought about. Anyway, Perl's sysopen function lets you specify the exact file mode (you'll probably want 0200, write-only) and IO::File::open does too. If you're using some other module I can't say what its equivalent would be.

Gazpacho fucked around with this message at 02:23 on Sep 6, 2012

Clanpot Shake
Aug 10, 2006
shake shake!

Sorry if I wasn't clear: I'm copying the file, not moving it. The source and destination are on the same mount point, which is shared by multiple servers.

I'll look into sysopen and rename tomorrow; those sound like what I need. Thanks guys.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

ShoulderDaemon posted:

Moving files is just a rename operation; it's instantaneous, and there's no way for another process to read a file that's been "half-way moved".

Historically, there have been some lovely "weirdnix" Unix implementations where rename(2) either didn't exist, wasn't ever atomic, or wasn't atomic under some circumstances. The most recent of these is OS X through Snow Leopard (I think Lion fixed it).

het
Nov 14, 2002

A dark black past
is my most valued
possession

Otto Skorzeny posted:

Historically, there have been some lovely "weirdnix" Unix implementations where rename(2) either didn't exist, wasn't ever atomic, or wasn't atomic under some circumstances. The most recent of these is OS X through Snow Leopard (I think Lion fixed it).
Yikes, I had no idea that occurred in such a recent OS.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Clanpot Shake posted:

I've got a problem that requires some deeper knowledge of of Unix file permissions than I have. I have a script that moves files from one directory to another (really a map of several dozen source->dest directories but that isn't important).

One of the destination directories (call it Inbound) is watched by another process I have no control over. What it does is look for the files that I'm moving, and when it sees them moves them to another folder for processing. The trouble is, it doesn't appear to wait for the file to be completely written - it will just grab whatever portion of the file is there when it checks. This is causing some errors.

I've been using the CPAN File module to move files from A to B, but that isn't going to work for this. I need to move the files to this particular directory with no read permissions (000, ideally), then chmod them to another value (I've been given this value).

How can I move files with no read permissions?

Permissions are going to throw up all kinds of errors in the other service. Does it recheck permissions or only watch the folder for new files? Cause if it only watched, that's going to break. Does the service picking up files pick up only specific extensions, or all files?

The correct way to do this would be like suggested earlier -- having a temporary, unwatched folder. Copy the file to there, then move the file from the holding folder to the target directory.

uG
Apr 23, 2003

by Ralp
I've been trying to use Web::Scraper more, but basic html always pushes me to resort to regex. An example of a repeating chunk that is easy to do with regex, but I can't figure out with Web::Scraper

code:
<A NAME="Application"></A><H2>Application - Application</H2>
<TABLE BORDER=1>
<TR bgcolor="lightblue"><TD WIDTH="50%">Description</TD><TD>Version</TD><TD>Released</TD><TD>Supported OS</TD><TD>Download</TD></TR>
<TR><TD>DELL,PTR,LS,DAO,110V,1355CNW,,A03</TD><TD>A03</TD><TD>6/1/2012</TD><TD>
Windows 7 32-bit<BR>
Windows 7 64-bit<BR>
Windows Vista 32-bit<BR>
Windows XP x64<BR>
Windows Vista 64-bit<BR>
Windows XP<BR>
<TD><A HREF="/FOLDER00548069M/1/1355_SSW_01-00-03-03.exe">Download</A><BR>
</TD></TR>
<TR><TD>DELL,PTR,LS,DAO,110V,1355CNW,MR4,A02</TD><TD>A02</TD><TD>4/26/2012</TD><TD>
Windows XP<BR>
Windows Server 2008 x64<BR>
Windows Server 2008 R2<BR>
Windows Vista 32-bit<BR>
Windows 7 64-bit<BR>
Windows Vista 64-bit<BR>
Windows 7 32-bit<BR>
Windows XP x64<BR>
Windows Server 2003<BR>
<TD><A HREF="/FOLDER00270250M/1/1355_SSW_01-00-02-06.exe">Download</A><BR>
</TD></TR>
</TABLE>
Mainly its the first line that trips me up (because I need to capture the TEXT from those to go with the data in the table), followed up the the OS listing where its just <BR>\r\n delimited.

Here is the script I wrote that uses a mix of Web::Scraper and regex. You'll want to turn off word wrap :smith:
http://pastebin.com/F6G6zwaH

SaxMaverick
Jun 9, 2005

The stuff of nightmares
I cannot for the life of me get the tr/// function to work. Here's a snippet of my code (although I've repeated trying to use it in various other places, and still doesn't work):

code:
sub primer_design{
	
	my @sequence_array = split(//,$_[0]);
	my @first21nt = @sequence_array[0..20];  # .. signifies a range
	my $primer_f = join("",@first21nt);
	my @last21nt = @sequence_array[-21..-1];
	my $primer_r = join("",@last21nt);

	if ($sequence =~ /^ATG/i){
		$primer_f='tga'.$_[1].$primer_f;
		}
	else{
		@sequence_array = split (//,$primer_f);
		@first21nt = @sequence_array[0..17];
		$primer_f = join("",@first21nt);
		$primer_f='tga'.$_[1].'ATG'.$primer_f; #need to take 3 off the end of the primerf
		}	

		$primer_r = reverse($primer_r);
		$primer_r =~ tr/ATGC/TACG/i;

	if ($sequence=~/TAG$/i || $sequence=~/TAA$/i || $sequence=~/TGA$/i){
		$primer_r='TAT'.$_[2].$primer_r;
		
		}	
	else{
		@sequence_array = split (//,$primer_r);
		@last21nt = @sequence_array[0..17];
		$primer_r = join("",@last21nt);
		$primer_r='TAT'.$_[2].'TAA'.$primer_r;
		}

	print OUT ">".$_[3]."-F-".$_[1]."\n";
	print OUT $primer_f;
	print OUT ">".$_[3]."-R-".$_[2]."\n";
	print OUT $primer_r;
	return;
	}
I'm learning perl, so excuse the ugliness of the code itself. But I'm getting: Bareword found where operator expected at Test.pl line 71, near "tr/ATGC/TACG/i"
syntax error at Test.pl line 71, near "tr/ATGC/TACG/i"
Execution of Test.pl aborted due to compilation errors.

And geany is highlighting "tr/ATGC/TACG/i" as if it's not even a function available to me. After several hours of searching, the most I can come up with is that using perl -v, gives me 5.14, but that shouldn't be an issue, right?

het
Nov 14, 2002

A dark black past
is my most valued
possession
i isn't a flag to tr; honestly if it's possible I would recommend normalizing case before doing any of this and then you won't have to worry about it

edit: this is admittedly a really cruddy way of erroring out

uG
Apr 23, 2003

by Ralp
tr/// is not a regex, so the 'i' doesn't actually do case insensitivity like you might think it does (tr/// has c,d,s).

You want s///

het
Nov 14, 2002

A dark black past
is my most valued
possession

uG posted:

tr/// is not a regex, so the 'i' doesn't actually do case insensitivity like you might think it does (tr/// has c,d,s).

You want s///
s///i won't preserve case though, I was assuming if he was using tr that was necessary. You could also just do two tr lines I guess.

The Gripper
Sep 14, 2004
i am winner

het posted:

s///i won't preserve case though, I was assuming if he was using tr that was necessary. You could also just do two tr lines I guess.
Would tr/ABC/DEF/i preserve case though, if it was an actual thing? I'd think it'd just replace all search characters (upper and lower) with uppercase replace characters.

If it's just the GATC you want transliterated and you want to preserve their case, you'd want tr/ATGC/TACG/ and then tr/atgc/tagc/

If you want just the sequencing data uppercased then tr/atgc/ATGC/ tr/ATGC/TACG/

It depends on what you actually want to do with your source data, and what your source data contains (whether or not your data is just a file full of GATGAACTGCGATCGATGCAT or other information/headers, and whether case is sensitive on the sequence).

het
Nov 14, 2002

A dark black past
is my most valued
possession

The Gripper posted:

Would tr/ABC/DEF/i preserve case though, if it was an actual thing? I'd think it'd just replace all search characters (upper and lower) with uppercase replace characters.
I think this is a common enough operation that it would be reasonable that /i (if it existed) would match A or A and if the matching character were alphabetic would match case. but it doesn't exist so it's kind of a moot point.

quote:

If it's just the GATC you want transliterated and you want to preserve their case, you'd want tr/ATGC/TACG/ and then tr/atgc/tagc/
yeah.

edit: to be clear, I think the best option is to make sure the output is fine with a normalized case and to just do that first off before you do anything else.

qntm
Jun 17, 2009
Or, indeed,

code:
tr/AaTtGgCc/TtAaCcGg/

SaxMaverick
Jun 9, 2005

The stuff of nightmares
In this case the output doesn't matter much. This is for a class of sorts, so I'm doing my best to refrain from getting answers - I'm trying to troubleshoot and the PhD student teaching it (bioinformatics) is teaching this for the first time. I sent him the error, and have yet to receive an answer.

Anyways, all we're attempting to design primers for two strands of DNA. For the reverse primer, we're taking a strand (lets say AAATTTCGC), reversing it (hence reverse($primer_r) to CGCTTTAAA, then translating it to it's complement so it can anneal (GCGAAATTT).

Taking the /i flag off seems to work. It was my understanding using s/// would substitute whole strings, say if I wanted every AAT in the sequence to be translated to TTA; whereas tr/// would replace each individual character (which is what I want to do). Am I on base here?

The Gripper
Sep 14, 2004
i am winner

SaxMaverick posted:

Taking the /i flag off seems to work. It was my understanding using s/// would substitute whole strings, say if I wanted every AAT in the sequence to be translated to TTA; whereas tr/// would replace each individual character (which is what I want to do). Am I on base here?
That's right.

s/// will match an entire pattern and replace it with the replacement string/pattern e.g. s/hello/hi/ will turn "hello everyone!" into "hi everyone!".

tr/// replaces individual characters with their counterparts e.g. tr/ABC/DEF/ will replace all A's with D's, B's with E's, C's with F's, but those characters don't need to be consecutive. It'll turn something like "A Big Cat" into "D Eig Fat", for example.

uG
Apr 23, 2003

by Ralp
I'm sure there is a reason its not a good idea, but why can't I use system/exec calls to run code inside a thread (to avoid running out of memory)?

Ninja Rope
Oct 22, 2005

Wee.

uG posted:

I'm sure there is a reason its not a good idea, but why can't I use system/exec calls to run code inside a thread (to avoid running out of memory)?

Threads share address space, so any memory they allocate is counted against you too. But from the way you formed that question I'm guessing that if you give a better description of what you're trying to do we can come up with a better solution.

SaxMaverick
Jun 9, 2005

The stuff of nightmares
This is a shortened piece of code that I'm using to test a subroutine.

code:
#!/usr/bin/perl
use warnings;
use strict;

# Variable Declarations
my $filein = $ARGV[0]; 													
my $key;																
my %fasta_database;


open (FASTA, "<", $filein) || die $!;
open (OUT, ">", "output.txt") || die $!;

while (my $line = <FASTA>){
	chomp $line;
	if ($line =~/^>/){
		$key = $line;
	}
	else{
		$fasta_database{$key} = $fasta_database{$key}.$line;		
	}
}
(my $forward_restriction, my $reverse_restriction) = check_for_cuts_in_sequence($fasta_database{$key});
print OUT $forward_restriction , " and " , $reverse_restriction , "\n";

close (FASTA);
exit;
sub check_for_cuts_in_sequence{
		my $sequence_in = $_[0]; 										
		my %recognition_hash = ('ClaI'=>'ATCGAT','SmaI'=>'CCCGGG','SalI'=>'GTCGAC');	
		my $num_good_res = 0 ; 										
		my @restriction_enzymes = (); 									
		foreach my $restriction_enzyme ('ClaI','SmaI','SalI'){								
			if ($num_good_res < 2){										
				if($recognition_hash{$restriction_enzyme}=~ /$sequence_in/ig){				
					next;											
				}	
				else{
					$num_good_res ++;
					push(@restriction_enzymes, $restriction_enzyme);
					}
				}
			}
		my $fr = $restriction_enzymes[0];
		my $rr = $restriction_enzymes[1];
		return $fr, $rr;
	}
My problem is that the recognition hash is not recognizing the target sequence unless it is the only thing within $sequence_in. I'm using an input file that contains the ClaI sequence, but not the others. However it won't pick it out within the entirety of the sequence, so it's returning ClaI when it should not. What am I missing?

(here is the input file for reference)

code:
>jgi|Phyca11|13487|fgenesh1_pg.PHYCAscaffold_4_#_10
ATGAGCAGCTCTGCGGACTCAGCGCAGGCTCCTGCCAGCAGCTACTCGACCCGATCAGGTCTGTCCAAGA
CCTGGCGCACCGTCAAGACACATGCGGCCATCATCGATGCCGAGACTGGAGAGCTCCAGCGCACGTTGCA
GCAGGACATAGAGGACGAAGAGGCCAAGGAATCCTTCGTGGTGTTTGCTGTGCGTCCGGGCAAGAAGAAT
CAACTTGTAACAGCCGGACGCAACTTGCTGCTGCGTGTGTGGGACCTGGACACATTCAAGTGTGTCCGCA
CTATTAAGGCCCACGAGACGCCCGTACTGGCCATGGGTTTCGACCCGTCAGGCACGCTATTGGCCACGGG
AGGCAGTGACCGAGCCGTCAAGGTCTTCGACGTGGACAAGGGCTTCTGTACGCACAATTTCCGCGGACAC
GCGGGTATCGTGACGCTTGTTCAATTCCATCCGGATGCAACACGTCTCCAGCTTGTGTCAGCTAGTGATG
ACTCCACTGTACGTGTTTGGGACCTGTACACGCAGAAGCAAGTGGCGTGCATCCAGGACCACATGAGTTT
GGTCACCAGTGTGGCTTTTTCGGAAGATGGCTACACTATGTTGTCCGCTGGACGTGATAAGGTGGTCAAC
TTCTGGGACTTGAGGGATCAGAAACTCAGCAAGACTGTGCTGGTCCATGAAGCAGTGGAAGGGCTCGTGG
TTGTACCGTCGAGTTTCAAGTGTGTCAAAGCGAACAAGACTCAGGACGATAAGGCTATTTACTTCATTAC
GGCTGGAGAGAAGGGACTGCTGCGTCTGTGGCAGAGCAGCGGAAGCTCGTGCGAAACGCTGTACACGCAA
AAGTCGGATGCGTCATCTGCTCTCACTTACATGGATCTACTATTGAGCACTTCCCGTCGCGAAATTGTGG
TGATTTCTTCCGAGCAGAACTTCCTCGTGTTCGATGAGAAGTTAGCGCGTCGTACACAGATCATTGGCTA
CAACGACGATATCCTCAACCTCAAATACATTCCGAAGGCTGATGCCAGCGGAGAACCCTCAGATATGCTG
GCTGTAGCCACAAACAGTGAACAGATCCGACTTCTGAACCGTGAAACCCTGTCTTGCGAGCTTCTTTCGG
GTCACACGGACATTGTCATGGCACTGGCTGTGTCTCCTGATGGACGCTGGCTGGATAAGCTCATTAAGGT
GTGGCACTCGCAGCAGGCTGGCGCTGGTCGTCTCTTGACGCTGGCAGGTGTTTGCCGCGGCCACAAACGT
GGCGTCTGGGCTGTGGAGTTTTCTCCTGTTGACCAGTGTCTTGCGTCTGCCAGTGGTGACAAGACCGTCA
AGGTGTGGTCTGCCAAGGACTTTTCGTGTCTCAAGACGTTTGAGGGCCACACTGCCTCAGTGCTGAACGT
GCAGTTCGCTTGCGCCGGTATGCAACTTCTCTCTGCTGGAGCTGACGGACTCGTGAAGCTCTGGACCATC
AAGAGCAACGAGTGCGAGGCGACGCTGGACAACCACGAGGACAAGATCTGGGCTCTTGCTGTGGCCAAGG
ACAGCTCCGAGATGGTCAGCGGTGGTGCAGACTCAGCTATTAACCTCTGGAAGGACTTCACAGAAGAGGA
AGAGCGGGCCCAGCAAGACGACCGCGACGCCAAGCTATTGAAGGAACAGGAGCTGTTCAACTGTCTCCGC
AATAACAAGCTGCTGGATGCTGTCCAGCTCGCATTCGAGCTCAACCACCCGAACCGCATGCTTCAGATCT
TCCGCGACTTGCTTGAAGGCCCGCGACACAAGGACCAGCCCACGCTCCCTGGCGGCAAACCTATTGACCC
GGACAACTTCGCTCCTGAGGACATTTTTGCTCCCGTGGTGCTGAGCTTGGAGGACGAACAGCTGACGACG
CTGATGGAGTGGCTGCGTGACTGGAACACGAATGCCCGCAACACTGGTGTCTGCCAAGTGCTGGTGAGCA
CAATCTTGCGTGAACTGCCTCCGAGTCGAATCAAGGCGTTGGAAGGCGCGGCCAAGACTGTGGAGGCTCT
GATTGCCTACAGCGAGCGTCACTTCCAGCGCATTGACCGTATGTTGCAGAAGTCGTACCTCGTGGACTTT
AGTATTGTGACCATGAAGAGTTTGCTGCCCGTTGGTGAAAGTCTGTCGGCCGTCGAGAAAACGGACAGCG
ATAGCGAAGTCGAGGAACCGAAACCAGTGGAAACCAAGCAACAGGTCAAGGAACCGAAACCAGTGAAAGC
CAAGCAGCAGCGGAAGCGTGGCAAAGTTGCTGCCACCGGAAAGGCCAAGAAACAGCGAGTGTAA

SaxMaverick fucked around with this message at 03:42 on Oct 8, 2012

SaxMaverick
Jun 9, 2005

The stuff of nightmares
Well, I'll leave the last post up in case there's a huge mistake, but I seemed to have fixed my problem by using:
code:
if($sequence_in =~ /$recognition_hash{$restriction_enzyme}/ig){		
Instead of the other way around.

The Gripper
Sep 14, 2004
i am winner

SaxMaverick posted:

Well, I'll leave the last post up in case there's a huge mistake, but I seemed to have fixed my problem by using:
Perl code:
if($sequence_in =~ /$recognition_hash{$restriction_enzyme}/ig){		
Instead of the other way around.
Yeah, your original code was just doing the test backwards, checking if $sequence_in (all of your source data) was contained in $recognition_hash{$restriction_enzyme}. Your fixed way is doing it properly.

Also that code doesn't work for me outright because of line 20 with use warnings; enabled (Perl 5.14), since it tries to get the value of $fasta_database{key} before setting it for the first line after a key line. Changing it to:
Perl code:
$fasta_database{$key} = defined $fasta_database{$key} ? $fasta_database{$key}.$line : $line;
solves that but it's possible it's a non-issue in your full-length code anyway.

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul
It's kind of cool to see that PERL (sorry, Perl... looks like it isn't all caps, these days) is still alive and kicking. I don't care what anyone says, I like Perl, and I loved coding in it. It's been ten years since I logged into my PerlMonks account, but I've still probably written more lines of PERL than any other single language I've used.

Who can tell what this does without cheating via Google or executing it?

s>>sp>;s>..|>\u$&ace>g;print;

uG
Apr 23, 2003

by Ralp

Ninja Rope posted:

Threads share address space, so any memory they allocate is counted against you too. But from the way you formed that question I'm guessing that if you give a better description of what you're trying to do we can come up with a better solution.
I mainly want memory released to the OS to prevent running out of memory because of an unknown data leak (and I really only need to run this once). I assumed a system call inside a thread will run the script outside the scope of the program, and when the script from the system call exits, the script would exit and release its memory (this is how I am imagining it might work). Although it seems like forks is a drop in, and while having more overhead, should help a little to counter act memory leaks growing on stop in threads (maybe this doesn't happen)?

There isn't actual sharing between threads, it was just scripted this way for some reason. It can get about 90% done before I run out of memory and get a segfault, so i'm trying to pinch as much overall memory as possible even if it ruins readability. For the record I am scraping drivers from a different manufacturer's website, so for every product I start a new thread to scrape each language/OS combination (the web site is EXTREMELY slow).

Another question though. i have a module that creats the dameru levenshetin edit distance between 2 strings. If I wanted to create an automaton to take a list and find all matches under a certain distance, should I relase it as Module::Name::automaton? or build it as an additional method in the original module? The reason I am using separate namespaces as an option is because i'd like to release XS versions of these (which I know absolutely nothing about).

uG fucked around with this message at 04:03 on Oct 9, 2012

The Gripper
Sep 14, 2004
i am winner

uG posted:

Although it seems like forks is a drop in, and while having more overhead, should help a little to counter act memory leaks growing on stop in threads (maybe this doesn't happen)?
Well fork/forks will run code in a child process with it's own memory space, and free memory when the child returns so unless your problem is concurrent active threads chewing up memory that should work fine.

The code I generally use for fork/exec on syscalls that I don't give a poo poo about the return value of is:
Perl code:
#somewhere at the top of your file
$SIG{CHLD} = 'IGNORE';

#elsewhere
my $pid = fork();
if (defined $pid && $pid == 0) {
  # child
  exec("./updatedb.pm > /dev/null 2>&1 &");
  exit 0;
}
Note: that code will just spin up processes and continue on it's merry way with no indication they completed. If you're using the forks drop-in replacement things should work the same as threads (including whatever code you're using to signal the thread completed), with all the benefits of forks.

The Gripper fucked around with this message at 07:09 on Oct 9, 2012

Rohaq
Aug 11, 2006

Centripetal Horse posted:

It's kind of cool to see that PERL (sorry, Perl... looks like it isn't all caps, these days) is still alive and kicking. I don't care what anyone says, I like Perl, and I loved coding in it. It's been ten years since I logged into my PerlMonks account, but I've still probably written more lines of PERL than any other single language I've used.

Who can tell what this does without cheating via Google or executing it?

s>>sp>;s>..|>\u$&ace>g;print;
  • Search and replace one instance of an empty string in $_ with 'sp'.
  • Append every occurrence any two characters or nothing in $_with 'ace', titlecasing the first character in each replacement.
  • Print the new value of $_

SpaceAce

qntm
Jun 17, 2009
Today I learned that Perl regular expressions have a \u escape sequence which can be used to upper-case the next character.

Whyyyyyyyyy :psyduck:

Rohaq
Aug 11, 2006

qntm posted:

Today I learned that Perl regular expressions have a \u escape sequence which can be used to upper-case the next character.

Whyyyyyyyyy :psyduck:
It's useful when you've transposed data, or used capture groups, and don't want to do some messy coding just to convert your output to Title Case.

You can do some seriously loving magical poo poo to data using regular expressions. I really suggest reading through the Perl Regular Expressions Reference page properly and doing some experimenting. Regex (generally) carries across languages too, so it's useful in other places, and it also makes you look like a goddamned wizard when it comes to transforming data.

Rohaq fucked around with this message at 13:29 on Oct 9, 2012

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Rohaq posted:

It's useful when you've transposed data, or used capture groups, and don't want to do some messy coding just to convert your output to Title Case.

You can do some seriously loving magical poo poo to data using regular expressions. I really suggest reading through the Perl Regular Expressions Reference page properly and doing some experimenting. Regex (generally) carries across languages too, so it's useful in other places, and it also makes you look like a goddamned wizard when it comes to transforming data.

Also, if you can find a first edition of "Mastering Regular Expressions", you grab that motherfucker with both hands. It's one of the few tech books I've genuinely enjoyed reading, and it will expand your regex understanding by a degree you can't imagine. (It got revised in later editions to be suckier.)

Rohaq
Aug 11, 2006

prefect posted:

Also, if you can find a first edition of "Mastering Regular Expressions", you grab that motherfucker with both hands. It's one of the few tech books I've genuinely enjoyed reading, and it will expand your regex understanding by a degree you can't imagine. (It got revised in later editions to be suckier.)
I used to use it for reference back at my old job, but it was my boss's copy. Just ordered it now - thanks for the reminder!

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

Rohaq posted:

  • Search and replace one instance of an empty string in $_ with 'sp'.
  • Append every occurrence any two characters or nothing in $_with 'ace', titlecasing the first character in each replacement.
  • Print the new value of $_

SpaceAce

You worked that out without running it or Googling? Very nicely done! The "..|" stumped many people, including some experienced Perl Monks, when I used it as my Perl signature (back when such a thing was common... is it still?) Mostly, it was the capitalizing of the "A" in Ace that they couldn't get a grip on without running the code.

I love Perl. I especially love regular expressions in Perl.

qntm posted:

Today I learned that Perl regular expressions have a \u escape sequence which can be used to upper-case the next character.

Knowing is half the battle.

Centripetal Horse fucked around with this message at 17:41 on Oct 9, 2012

tef
May 30, 2004

-> some l-system crap ->

Centripetal Horse posted:

It's kind of cool to see that PERL (sorry, Perl... looks like it isn't all caps, these days) is still alive and kicking. I don't care what anyone says, I like Perl, and I loved coding in it. It's been ten years since I logged into my PerlMonks account, but I've still probably written more lines of PERL than any other single language I've used.

Who can tell what this does without cheating via Google or executing it?

s>>sp>;s>..|>\u$&ace>g;print;

the perl shibboleths I use are less :pwn:

code:
%foo = {};
code:
%bar = reverse %bar;
code:
sort {print $a+=$b} @butts;

het
Nov 14, 2002

A dark black past
is my most valued
possession

tef posted:

code:
sort {print $a+=$b} @butts;
What does this do? I tried running it and nothing printed and @butts wasn't modified; is the point just that if you pass sort something that always returns 1, it won't do anything?

Anaconda Rifle
Mar 23, 2007

Yam Slacker

het posted:

What does this do? I tried running it and nothing printed and @butts wasn't modified; is the point just that if you pass sort something that always returns 1, it won't do anything?

Did you try loading @butts with numbers? If you didn't, I bet you weren't using warnings.

Adbot
ADBOT LOVES YOU

het
Nov 14, 2002

A dark black past
is my most valued
possession

Anaconda Rifle posted:

Did you try loading @butts with numbers? If you didn't, I bet you weren't using warnings.
Oh, I did but I was just doing one-liners on the command line, that's funny

  • Locked thread