Does your file name have a '>' character in it? You should probably be using the three argument form of open instead.my $out = ">./coffee.tmp";
Using the high precedence || operator means that the dies are superfluous. You should use the low precedence or operator instead. close accepts one argument, the filehandle. You should also include the $! variable in the error messages so you know why the program failed.open OUT, $out || die "Can't open $out!\n"; open FILE, $file || die "Can't open file oldcoffee!\n"; close FILE, $file || die "Can't close file oldcoffee!\n"; close OUT, $out || die "Can't close $out!\n";
Is better written as:$mails[$#mails + 1] = $_;
If you want to split the mbox file into separate files based on the year in the /^From/ line then you probably want something like this:push @mails, $_;
#!/usr/bin/perl use warnings; use strict; my $file = 'oldcoffee.tmp'; my $out = 'coffee.tmp'; open FILE, '<', $file or die "Can't open file $file! $!\n"; while ( <FILE> ) { if ( /^From / && /(\d{4})$/ ) { # Update: changed 'readonly' to 'append' open OUT, '>>', "$1$out" or die "Can't open $1$out! $!\n"; } fileno OUT and print OUT; } close FILE or die "Can't close file $file! $!\n"; __END__
In reply to Re: Spliting an mbox file
by jwkrahn
in thread Spliting an mbox file
by monger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |