Thanks
Shishir
> --
> To unsubscribe, e-mail: beginners-...@perl.org
> For additional commands, e-mail: beginne...@perl.org
>
>
>I was just wondering if there is anything similar in perl for unix
>commands pushd / popd ??
I can't find such a thing. You (or someone else) could write one. It
doesn't seem too difficult; it's just an array.
--
Jeff "japhy" Pinyan ja...@pobox.com http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
>how about functions like push, pop, shift, unshift ?
> -----Original Message-----
> From: Shishir K. Singh [mailto:sks...@synapsistech.com]
> Sent: Tuesday, July 23, 2002 2:15 PM
> To: begi...@perl.org
> Subject: pushd and popd
>
>
> I was just wondering if there is anything similar in perl for
> unix commands pushd / popd ??
>
>I can't find such a thing. You (or someone else) could write one. It
>doesn't seem too difficult; it's just an array.
Good Idea!! might as well do that!!
pushd and popd are built-in shell commands, they aren't really "Unix"
commands. What exactly are you trying to do?
perldoc -f push
perldoc -f pop
perldoc -f shift
perldoc -f unshift
perldoc -f splice
John
--
use Perl;
program
fulfillment
> pushd and popd are built-in shell commands, they aren't really "Unix"
>commands. What exactly are you trying to do?
>perldoc -f push
>perldoc -f pop
>perldoc -f shift
>perldoc -f unshift
>perldoc -f splice
I have this awfully old shell script that used lots of pushd and popd and I need to convert it to perl. I will have to settle with push and pop and cwd for the time being. Thanks anyways !!
Here is a very simple implementation (no error checking.) Stick it at
the top of your program so that the prototypes will work.
{
use Cwd;
my @stack = cwd;
sub dirs () {
print "@stack\n";
}
sub pushd ($) {
unshift @stack, shift;
dirs;
}
sub popd () {
@stack > 1 and shift @stack;
dirs;
traditionally pushd/popd are csh/tcsh things for walking around
the directory structure - you may have multiple issues that
you will want to think about as you port over this old
csh/tcsh script....
some of the 'modern' forms of /bin/sh also use this, but
of course you do not 'inherit' that "stack" in any of the
sub processes....
So you may want to check why you are pushd/popd-ing all
over the place in the first place - and may wish to think
about re-organizing this so that a simple chain of movement
would suffice:
my @dir_run = qw( first_dir second_dir )
so that you merely pop them off that array - or reference
them by index.....
ciao
drieux
---
Sorry, I forgot to change to the directory being pushed. :-) This
should work a lot better.
{
use Cwd;
my @stack = cwd;
sub dirs () {
print "@stack\n";
}
sub pushd ($) {
unless ( chdir $_[0] ) {
warn "Error: $!";
return;
}
unshift @stack, cwd;
dirs;
}
sub popd () {
@stack > 1 and shift @stack;
chdir $stack[0];