summaryrefslogtreecommitdiffstats
path: root/Bachelor/Systemprogrammierung in Perl/NoteBox.pl
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Systemprogrammierung in Perl/NoteBox.pl
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Systemprogrammierung in Perl/NoteBox.pl')
-rwxr-xr-xBachelor/Systemprogrammierung in Perl/NoteBox.pl219
1 files changed, 219 insertions, 0 deletions
diff --git a/Bachelor/Systemprogrammierung in Perl/NoteBox.pl b/Bachelor/Systemprogrammierung in Perl/NoteBox.pl
new file mode 100755
index 0000000..778bafe
--- /dev/null
+++ b/Bachelor/Systemprogrammierung in Perl/NoteBox.pl
@@ -0,0 +1,219 @@
+#!/usr/bin/perl
+#
+# Filename: NoteBox.pl
+# Author: Sven Eisenhauer
+# Systemprogrammierung in Perl Wintersemester 2006 / 2007 fbi, h_da
+# Praktikum
+#################################################
+# changelog:
+# - 2006-10-30 Sven Eisenhauer
+# Initial coding
+#################################################
+#
+# Includes
+#
+use warnings;
+use strict;
+#################################################
+#
+# Defines
+#
+#################################################
+#
+# Globals
+#
+my @notes;
+#################################################
+#
+# Subroutines
+#
+# print the main menu
+sub print_menu {
+ my $menu = qq{NoteBox
+-----------------------------------
+e - New Note
+a <nr> - Append text to Note nr
+d <nr> - Delete Note nr
+l <nr> - Show note nr
+l - Show all notes
+h - Help
+s <text> - Search text in all Notes
+q - Quit
+-----------------------------------
+Your selection:
+};
+ #clear console
+ print chr(27)."[2J";
+ print $menu;
+ return 1;
+}
+# new_note
+sub new_note{
+ my $act_line;
+ my $note;
+ #clear console
+ print chr(27)."[2J";
+ print "Please enter your note (single line starting with'.' is end of note):\n";
+ until ( (($act_line = <STDIN>) =~/^\./) )
+ {
+ $note.=$act_line;
+ }
+ push @notes,$note;
+ return 1;
+}
+# append_note
+sub append_note{
+ if (defined $_[0] && $_[0] < scalar @notes)
+ {
+ my ( $nr ) = @_;
+ my $act_line;
+ my $note;
+ #clear console
+ print chr(27)."[2J";
+ print "Please enter your note (single line starting with'.' is end of note):\n";
+ chomp ($act_line = <STDIN>);
+ while ( ! ($act_line =~/^\./) )
+ {
+ $note.=$act_line."\n";
+ chomp ($act_line = <STDIN>);
+ }
+ $notes[$nr].=$note;
+ }
+ else
+ {
+ print "No Note appended\n";
+ }
+ print "Press ENTER to continue\n";
+ my $dummy = <STDIN>;
+ return 1;
+}
+
+# delete_note
+sub delete_note{
+ if (defined $_[0] && $_[0] < scalar @notes)
+ {
+ my ( $nr ) = @_;
+ splice @notes,$nr,1;
+ print "Note $nr deleted\n";
+
+ }
+ else
+ {
+ print "No Note deleted\n";
+ }
+ print "Press ENTER to continue\n";
+ my $dummy = <STDIN>;
+ return 1;
+}
+
+# list_note
+sub list_note{
+ my $show_break=1;
+ if (defined $_[0] && $_[0] < scalar @notes)
+ {
+ if (defined $_[1])
+ {
+ $show_break=0;
+ }
+ my ( $nr ) = @_;
+ print "Note $nr:\n";
+ print $notes[$nr];
+ print "---------------------------------\n";
+ }
+ else
+ {
+ my $i=0;
+ print "All Notes\n";
+ print "===============================\n";
+ foreach(@notes)
+ {
+ print "Note $i:\n";
+ print $_;
+ print "---------------------------------\n";
+ $i++;
+ }
+ $show_break=1;
+ }
+ if ( $show_break != 0)
+ {
+ print "Press ENTER to continue\n";
+ my $dummy = <STDIN>;
+ }
+ return 1;
+}
+
+# help_message
+sub help_message{
+ print "Help Message\n";
+ print "Press ENTER to continue\n";
+ my $dummy = <STDIN>;
+}
+
+# search
+sub search{
+ if (defined $_[0])
+ {
+ my $i=0;
+ my ( $searchstring ) = @_;
+ foreach(@notes)
+ {
+ if ($_ =~/$searchstring/)
+ {
+ list_note($i,1);
+ }
+ $i++;
+ }
+ }
+ else
+ {
+ print "No search string specified\n";
+ }
+ print "Press ENTER to continue\n";
+ my $dummy = <STDIN>;
+ return 1;
+}
+
+# quit
+sub quit {
+ exit;
+}
+#################################################
+#
+# main routine
+#
+#################################################
+my $menu_selection;
+my $continue=1;
+
+my %menu_switch=(
+ 'e' =>\&new_note,
+ 'a' => \&append_note,
+ 'd' => \&delete_note,
+ 'l' => \&list_note,
+ 'h' => \&help_message,
+ 's' => \&search,
+ 'q' => \&quit
+);
+
+do {
+ print_menu;
+ $menu_selection = <STDIN>;
+ chomp ($menu_selection);
+ my @input = split /\s+/,$menu_selection;
+ if (length $menu_selection > 0)
+ {
+ if (exists $menu_switch{$input[0]})
+ {
+ if (exists $input[1])
+ {
+ &{ $menu_switch{$input[0]}} ($input[1]);
+ }
+ else
+ {
+ &{ $menu_switch{$input[0]}};
+ }
+ }
+ }
+} while ($continue!=0);
+
+exit 0; \ No newline at end of file