Here is what I came up with after a quick run through at your request:

#!/usr/bin/perl -w =head Changes Be more consistant with your spacing. I don't see the use for which() since you are just duplicating code th +at the kernel will do but less portably (under Win32, you need to spl +it on ';', not on ':'). Used a more "standard" method for picking an editor. Since you only have one enclosing loop, you don't need the STUDY: labe +l, but I don't mind you keeping it since it makes it easy to find tha +t loop. On non-Unix systems, $ENV{HOME} may not be set. Declaring subs in the middle of code just makes them hard to find. Added a default for $ENV{SANDBOX} s/[A-Za-z]/0/g more efficient as tr/A-Za-z/0/ Allow easy highlight with a color other than 'GREEN' Replace repeated highlighting code with a subroutine Treat $hide_help and $clear as Booleans instead of integers Your first "next" doesn't do anything (I just commented it out) Your first "redo" doesn't do anything (commented out) Don't have a [my] variable with the same name as a global, STUDYPATH close SCRIPT when you are done with it =cut use strict; use Term::ANSIColor 'color'; my $EDITOR = $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT} or $^O =~ /^MSWin/ ? 'notepad' : 'vi'; my $index = @ARGV ? shift(@ARGV) :0; my $clear = 1; my $hide_help = 0; my $highlight = $ENV{STUDYCOLOR} || 'GREEN'; my $homedir = $ENV{HOME} || '.'; my $sandbox = $ENV{SANDBOX} || 'sandbox'; my $STUDYPATH = "$homedir/$sandbox"; sub change_snippet_dir{ my $sandbox= shift; my $path= "$homedir/$sandbox"; if( -d $path ) { $STUDYPATH= $path; } } sub highlight { return color($highlight), @_, color('reset'); } STUDY: while (1) { my @files= glob "$STUDYPATH/*"; if( $clear ) { system ('clear'); } else { $clear++; } $index =~ tr/A-Za-z/0/; $index= 0 if $index < (0-$#files)-1 || $index > $#files; printf( "%50s <- (%5s)\n", $files[$index], $index ); print " ",highlight("[C]"),"HANGE editor. Currently $EDITOR ",highlight("[E]"),"DIT to open the snippet in an editor ",highlight("[G]"),"oTo to select file index: -", ($#files+1)," to + $#files ",highlight("[H]"),"ELP to (un)hide this menu ",highlight("[N]"),"EXT to skip this snippet ",highlight("[R]"),"EDO to revisit the previous snippet ",highlight("[Q]"),"UIT to exit e",highlight("[X]"),"ecute Any other key +",highlight(" [ENTER] "),"to print out the snippet -> " unless $hide_help; my $input = <>; if ($input =~ /^N/i){ ++$index; # next; This doesn't do anything }elsif($input =~ /^G/i){ print "enter a number from -",$#files+1," to $#files -> "; $index = <>; chomp $index; }elsif($input =~ /^H/i){ $hide_help= ! $hide_help; }elsif($input =~ /^C/i){ $EDITOR = <>; chomp $EDITOR; # redo STUDY; }elsif($input =~ /^R/i){ --$index; }elsif($input =~ /^(SANDBOX)/i){ print "$homedir/"; my $sandbox=<>; chomp $sandbox; change_snippet_dir($sandbox); }elsif($input =~ /^E/i){ system( $EDITOR, $files[$index] ); }elsif($input =~ /^X/i){ do $files[$index]; print "\n"; $clear= 0; }elsif($input =~ /^Q/i){ last; }else{ $clear= 0; open (SCRIPT,"< $files[$index]") or warn "can't open file: $!"; print while <SCRIPT>; close SCRIPT; } }
        - tye (but my friends call me "Tye")

In reply to (tye)Re: newer snippet browser by tye
in thread newer snippet browser by mkmcconn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.