in reply to Redoing a script
#!/bin/perl use File::Path;
Your program should start with the warnings and strict pragmas:
#!/bin/perl use warnings; use strict; use File::Path;
sub removetimestamp() { my ($line) = @_; ... sub keyValue() { my ($line) = @_; ... sub getSenderName() { my ($from_line) = @_; ... sub getRecipientName() { my ($to_line) = @_; ... sub doLog() { my ($msg, $line) = @_;
You use a prototype that says the subroutines will accept NO arguments but every subroutine DOES accept some arguments. You should not use prototypes.
The removetimestamp subroutine is exactly the same as the keyValue subroutine, and the getSenderName subroutine is exactly the same as the getRecipientName subroutine. You shouldn't duplicate code like that.
sub removetimestamp() { my ($line) = @_; my $ind = index($line, " "); if ( $ind != "-1" ) { $time = substr($line, 0, $ind); $line = substr($line, $ind + 1); return ($time, $line); } }
That could be simplified to:
sub removetimestamp { my ( $line ) = @_; ( my $time, $line ) = split / /, $line, 2; }
But then you don't really need a subroutine so:
my ($time, $data) = removetimestamp($line); my ($key, $value) = keyValue($data);
Would become:
my ($time, $data) = split / /, $line, 2; my ($key, $value) = split / /, $data, 2;
|
|---|