Masters of Perl, I seek your wisdom yet again. I have a sniplet that successfully takes the last line of file and puts it an array, but now I need to be able to test the last line with the second to the last and so on. I've read up on using seek, File::Backwards, and other methods. I would like to use File::Backwards as it appears to do everything that I need, but I'm not sure how to implement it, and I'm having problems. Thanks in advance!
# $last_current_schedule is the last line of schedule.txt
open (CURRENTSCHEDULE, "calendars/$calendar/schedule.txt");
my $last_current_schedule;
local $_;
$last_current_schedule = $_ while <CURRENTSCHEDULE>;
@last_current_schedule = split(/\t/, $last_current_schedule);
close CURRENTSCHEDULE;
if($last_current_schedule[1] != $second_last_current_schedule[
+1]) { $last_current_schedule[0] = $new_default_id; }
else {
# test second, third to last until equal.
$bw = File::ReadBackwards->new( 'logfile.txt' ) or
die "can't read 'log_file' $!" ;
while( defined( $log_line = $bw->readline ) ) {
print LOGFILE $log_line ;
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.