The presence of an unshift on line 9 is a syntax error as unshift requires a destination array which is not present in your example - I can only assume this is an artifact from a previous attempt involving a file slurp.
Why do you not want to insert "Date" on the first line of the file (unless clause of line 9, $.)? Particularly considering that it is a date, I would think that would be a desirable result.
Based on this code and the contents of insert label into file, perhaps you want something like this?
use strict;
use warnings;
my $text;
while(<DATA>) {
chomp($_);
if($_ =~ /\d{1,2}\/\d{1,2}\/\d{4}/) {
$text .= "\nDate," unless $. == 1;
$text .= $_;
} else {
$text .= ",\n".$_;
}
}
print $text;
__DATA__
1/3/2007 12:20:01 AM
Login,12.588309
SearchLoad,9.432586
SearchCount,20:0.196329
SearchResults,7.418672
SearchSave,3.616305
SearchDelete,2.066482
SearchDetails,6.873061
ClientAdd,0.784989
CMALoad,1.859894
CMASave,3.249620
CMADelete,0.450952
ClientDelete,0.305768
Logout,0.823402
1/3/2007 12:49:22 AM
Login,10.958312
SearchLoad,13.644527
SearchCount,41:0.483233
SearchResults,7.027840
SearchSave,4.222601
SearchDelete,0.305821
SearchDetails,7.443877
ClientAdd,1.552915
CMALoad,1.202711
CMASave,5.285398
CMADelete,0.233119
ClientDelete,0.425521
Logout,0.560862
with output
1/3/2007 12:20:01 AM,
Login,12.588309,
SearchLoad,9.432586,
SearchCount,20:0.196329,
SearchResults,7.418672,
SearchSave,3.616305,
SearchDelete,2.066482,
SearchDetails,6.873061,
ClientAdd,0.784989,
CMALoad,1.859894,
CMASave,3.249620,
CMADelete,0.450952,
ClientDelete,0.305768,
Logout,0.823402
Date,1/3/2007 12:49:22 AM,
Login,10.958312,
SearchLoad,13.644527,
SearchCount,41:0.483233,
SearchResults,7.027840,
SearchSave,4.222601,
SearchDelete,0.305821,
SearchDetails,7.443877,
ClientAdd,1.552915,
CMALoad,1.202711,
CMASave,5.285398,
CMADelete,0.233119,
ClientDelete,0.425521,
Logout,0.560862
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.