#!/usr/bin/perl -w use strict; use Getopt::Long; my $VAR = 'PATH'; my $OFFSET = 0; my $LENGTH = 0; my $EXECUTABLE = ''; my $EVAL = 1; my @LIST; GetOptions( '-variable=s' => \$VAR, '-offset=i' => \$OFFSET, '-length=i' => \$LENGTH, '-executable=s' => \$EXECUTABLE, '-bashsource!' => \$EVAL, ); exit(1) unless $ENV{$VAR}; my @P = split ':', $ENV{$VAR}; local $" = ':'; if ($EXECUTABLE) { @LIST = `$EXECUTABLE`; chomp @LIST; } else { @LIST = @ARGV; } splice @P, $OFFSET, $LENGTH, @LIST; if ($EVAL) { print "$VAR=@P;export $VAR"; } else { print "@P"; } __END__ =head1 NAME splicepath - Returns a string with the spliced PATH =head1 SYNOPSIS $ eval `splicepath -v PERL5LIB -o 0 -l 1 ~/src/perl/Parse-Eyapp-1.11 +3/lib` =head1 DESCRIPTION Works like Perl splice but with environment variables that follow the C<:> separation convention (like C<PATH> or C<PERL5LIB>) The mening of the options are as follows: =over 2 =item * C<-variable> The environment variable (by default C<PATH>) =item * C<-offset #number> The offset. Like in Perl C<splice> =item * C<-length #number> The length. Like in Perl C<splice> =item * C<-executable scriptname> The script C<scriptname> will be executed and the lines of its output inserted in the variable =item * C<-bashsource> True by default. The output is bash source to set the environment variable =back =head1 EXAMPLES Assuming the path: $ echo $PATH .:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/ +games The command $ splicepath -o 2 -l 1 ~/bin produces the output: PATH=.:/usr/local/sbin:/home/username/bin:/usr/sbin:/usr/bin:/sbin:/ +bin:/usr/games;export PATH

In reply to splicepath by casiano

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.