I just started using the program Pal its a unix terminal emulator. I wanted to wrap it 
with a perl script so that I could sort events based on A1 codes. So A1 A2 A3 C3 D4 C2 
would get sorted in order of priority. So i wrote a quick little perl script to pipe 
the output of pal to have it resort it and then display it. I have cron email me and 
print a copy 3 times a day. To help keep me on track. Its easy in IT to get stuck on 
the web or in email all day :)

At any rate the wrapper works great but it seems that depeneding on the size of the 
terminal window that pal is actually inserting line breaks rather then letting the 
line wrap. This makes my wrapper not work for print jobs and for smaller terminal 
windows. Granted I could just keep my pal files at a certain width and avoid the 
problem but that wouldn't be very perlish. Below is my code. Below that is the output. 
Now this is hard to show because when I redirect output to a file it doesn't break it 
up. So below the redirected out put is just a copy paste of the terminal window.

TIA,

Paul D. Kraus
~=~=~=~=~=~=~=~=~=~=~=~=~
~ Network Administrator ~
~ PEL Supply Company    ~
~ 216.267.5775 Voice    ~
~ 216.267.6176 Fax      ~
~=~=~=~=~=~=~=~=~=~=~=~=~
~   www.pelsupply.com   ~
~=~=~=~=~=~=~=~=~=~=~=~=~


Code
-----
#!/usr/bin/perl
use strict;

my ( @cal, %events );
getdata ( [EMAIL PROTECTED], \%events );
printcal ( [EMAIL PROTECTED] );
printevents ( \%events );


sub getdata { # Capture Data
  my ( $cal, $events ) = ( shift, shift );
  my $key;
  my %weekname = ( "Mon" => 1, "Tue" => 2, "Wed" => 3,
                   "Thu" => 4, "Fri" => 5, "Sat" => 6,
                   "Sun" => 7 );
  while ( <> ) {
    chomp;
    unless ( ( /Mon|Tue|Wed|Thu|Fri|Sat|Sun|\*/ ) or ( $key ) )  {
      next unless ( $_ );
      push ( @$cal, $_ );
    } else {
      $key = $weekname{ $1 } if ( /\e\[1m(Mon)/ );
      $key = $weekname{ $1 } if ( /\e\[1m(Tue)/ );
      $key = $weekname{ $1 } if ( /\e\[1m(Wed)/ );
      $key = $weekname{ $1 } if ( /\e\[1m(Thu)/ );
      $key = $weekname{ $1 } if ( /\e\[1m(Fri)/ );
      $key = $weekname{ $1 } if ( /\e\[1m(Sat)/ );
      $key = $weekname{ $1 } if ( /\e\[1m(Sun)/ );
      push ( @{$$events{$key}}, $_ );
    }
  }
}

sub printcal { # Print Calendars
  my $cal = shift;
  print "$_\n" foreach ( @{ $cal } ) ;
  print "\n";
}

sub printevents { # Print Events
  my $events = shift;
  my %weeknum  = ( 1 => "Mon", 2 => "Tue", 3 => "Wed",
                   4 => "Thu", 5 => "Fri", 6 => "Sat",
                   7 => "Sun" );
  foreach my $key ( sort keys %{ $events } ) {
    next unless ( $key );
    print "$$events{$key}[0]";
    foreach my $event (sort @{ $$events{ $key} } [EMAIL PROTECTED]) {
      print "$event\n";
    }
    print "\n";
  }
}



Output of pal
-------------
     Su   Mo   Tu   We   Th   Fr   Sa |     Su   Mo   Tu  
 We   Th   Fr   Sa
May  25   26   27   28   29   30   01 |Jun 
C30C U31S  01   02   03   04   05 
     02   03   04  P05E  06  [1;[EMAIL PROTECTED];[EMAIL 
PROTECTED]  08 |    C06C  07   08   09  
C10C  11   12 
    U09S  10  P11E  12  
P13E  14  U15S|     13  
U14S  15   16   17   18   19 
    C16C  17   18   19  C20C  21   22 
|    U20S  21   22   23   24   25   26 
     23   24   25   26   27   28   29 |Jul  27   28   29   30   
01   02   03 

Fri  7 May 2004 - Today
* PK Events: Meeting - Record Retention ( 9:00AM ) Seminar Room
* History: Germany surrenders after WWII, 1945
* PK ToDoList: D1: Advertising - Pel E-Gram Sales Analysis (Waiting Kelly & 
Ronelle)
* PK ToDoList: D1: Kelly Luiere - Who is not buying liners (Waiting Kelly)
* PK ToDoList: D1: Viv Walsh - Add Credit Card Banner to Pick Tickets 
(Waiting Viv)
* PK ToDoList: D1: Paulette Vaughn - Copier will not work  (Waiting parts)
* PK ToDoList: D1: Add Attention Field to PEL E-Gram Fax's (Waiting PAV)
* PK ToDoList: C4: Bev - Give Money to Bev for Danniele - House Warming Gift
* PK ToDoList: A1: Paulette Vaughn - Add Children Customers to new Cust 
Class Code
* PK ToDoList: A1: Bob Boff - Buy Laptop

Sat  8 May 2004 - Tomorrow
* History: US institutes mining of Haiphong Harbor, 1972

Sun  9 May 2004 - 2 days away
* USA: Mother's Day
* History: 94 degrees, New York, 1979

Mon 10 May 2004 - 3 days away
* History: Germany invades Low Countries, 1940
* History: Nazi bookburning, 1933




Output (Cust Paste Term Window piped through script)
----------------------------------------------------

     Su   Mo   Tu   We   Th   Fr   Sa
May  25   26   27   28   29   30   01
     02   03   04  P05E  06  @07@  08
    U09S  10  P11E  12  P13E  14  U15S
    C16C  17   18   19  C20C  21   22
     23   24   25   26   27   28   29

Mon 10 May 2004 - 3 days away

* History: Germany invades Low Countries, 1940
* History: Nazi bookburning, 1933

Fri  7 May 2004 - Today

* PK Events: Meeting - Record Retention ( 9:00AM ) Seminar Room
* PK ToDoList: A1: Bob Boff - Buy Laptop
* PK ToDoList: A1: Paulette Vaughn - Add Children Customers to new Cust
* PK ToDoList: C4: Bev - Give Money to Bev for Danniele - House Warming
* PK ToDoList: D1: Add Attention Field to PEL E-Gram Fax's (Waiting PAV)
* PK ToDoList: D1: Advertising - Pel E-Gram Sales Analysis (Waiting Kelly &
* PK ToDoList: D1: Kelly Luiere - Who is not buying liners (Waiting Kelly)
* PK ToDoList: D1: Paulette Vaughn - Copier will not work  (Waiting parts)
* PK ToDoList: D1: Viv Walsh - Add Credit Card Banner to Pick Tickets
* History: Germany surrenders after WWII, 1945
  (Waiting Viv)
  Class Code
  Gift
  Ronelle)

Sat  8 May 2004 - Tomorrow

* History: US institutes mining of Haiphong Harbor, 1972

Sun  9 May 2004 - 2 days away

* USA: Mother's Day
* History: 94 degrees, New York, 1979

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to