#!/usr/bin/perl use strict; use warnings; use feature 'say'; # Enable autoflush $| = 1; # Configuration my $board_file = '/var/nex/board'; my $max_line_length = 255; # Maximum length of line my $max_lines = 99; # Maximum number of lines # Initialize board file open my $fh, '>>', $board_file or die "Could not open $board_file: $!"; print $fh "\n----------------------------------------------------------------------\n"; my $date = localtime(); print $fh "NEXT ONE $date CET\n"; # Read input line by line my $line_count = 0; while (my $line = ) { chomp $line; # Remove newline characters # Remove any lingering carriage return (from Windows) $line =~ s/\r//g; if (length($line) > $max_line_length) { say "Line length limit exceeded. Not sent. Continue with shorter line."; say "Please keep lines under $max_line_length characters."; next; } if ($line eq '.') { last; } $line_count++; print $fh "$line\n"; # Add newline when writing to the board file if ($line_count >= $max_lines) { say "Line count limit reached. No more lines will be accepted. End of your story."; last; } } close $fh; # Farewell message say "Thank you hero! We are done here. Text should be at the board now.";