Re: pushd and popd
"John W. Krahn" wrote: > > "Shishir K. Singh" wrote: > > > > > > I was just wondering if there is anything similar > > > in perl for unix commands pushd / popd ?? > > > > > 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 !! > > [snip] 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]; dirs; } } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: pushd and popd
On Tuesday, July 23, 2002, at 11:39 , Shishir K. Singh wrote: [..] > 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 !! 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 --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: pushd and popd
Thanks John...I appreciate it!! > > > > I was just wondering if there is anything similar > > in perl for unix commands pushd / popd ?? > > > 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; >} >} -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: pushd and popd
"Shishir K. Singh" wrote: > > > > I was just wondering if there is anything similar > > in perl for unix commands pushd / popd ?? > > > 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; } } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: pushd and popd
> > I was just wondering if there is anything similar > in perl for unix commands pushd / popd ?? > 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 !! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: pushd and popd
"Shishir K. Singh" wrote: > > I was just wondering if there is anything similar > in perl for unix commands pushd / popd ?? 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: 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!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: pushd and popd
hmmm..they are array functions...I guess I can use the cwd/push/pop to simulate the pushd and popd, just was being lazy :) and wanted to know if a direct pushd popd kind of function exists!! >how about functions like push, pop, shift, unshift ? > -Original Message- > From: Shishir K. Singh [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 23, 2002 2:15 PM > To: [EMAIL PROTECTED] > Subject: pushd and popd > > > I was just wondering if there is anything similar in perl for > unix commands pushd / popd ?? > > Thanks > Shishir > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: pushd and popd
On Jul 23, Shishir K. Singh said: >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 [EMAIL PROTECTED] 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 ** what does y/// stand for? why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: pushd and popd
how about functions like push, pop, shift, unshift ? > -Original Message- > From: Shishir K. Singh [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 23, 2002 2:15 PM > To: [EMAIL PROTECTED] > Subject: pushd and popd > > > I was just wondering if there is anything similar in perl for > unix commands pushd / popd ?? > > Thanks > Shishir > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]