#!/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;

In reply to Re: Redoing a script by jwkrahn
in thread Redoing a script by PhiThors

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.