Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Unexpected deletion of data using > operator

by davidrw (Prior)
on Dec 07, 2008 at 17:19 UTC ( #728747=note: print w/ replies, xml ) Need Help??


in reply to Unexpected deletion of data using > operator

hmm .. it also looks like you're keeping track of the array indexes that you want to whack, then setting those array values to undef, then skipping over the undefs when you ouptut it. This can all be done natively w/ a simple grep.

my @customerarray = ( ... ); my $now = time; my @keep = grep { my ($timestamp) = (split '::', $_)[2]; $now - $timestamp <= 15*24*60*60 # items less than 15 days old } @customerarray; open FH, '>', "$cuslist.tmp" or die "Can't open $cuslist.tmp: $!"; print FH "$_\n" for @keep; close FH;

And can even collapse it further:
open FH, '>', "$cuslist.tmp" or die "Can't open $cuslist.tmp: $!"; print FH "$_\n" for grep { time - split '::', $_)[2] <= 15*24*60*60 } +@customerarray; close FH;


Comment on Re: Unexpected deletion of data using > operator
Select or Download Code
Re^2: Unexpected deletion of data using > operator
by jonnyfolk (Vicar) on Dec 07, 2008 at 19:41 UTC
    Thanks very much for showing me how to compress my code - that's really interesting. Not only that but it seems to have resolved the problem!! I don't know why - I shall have to go through it with a fine-tooth comb to find the original problem. It obviously pays to be more direct. Thanks once again...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-12-26 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls