求perl中类似pushd和popd的功能

求perl中类似pushd和popd的功能

求perl中类似pushd和popd的功能,在shell中这两个功能非常有用,在perl里有没有类似的东东?


[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/perl
use strict;
use warnings;
my @array = qw (1 2 3 4 5 6);
print "The original \@array = @array\n";

my $first = shift @array;
print "After shift \@array = @array\n";
print "first element of \@array is $first\n";

unshift @array,$first;

print "Shift back the first element\n";
print "Now \@array = @array\n";

my $last =pop @array;
print "After pop \@array = @array\n";
print "The last element of \@array is $last\n";

push @array,$last;
print "After push \@array = @array\n"

运行结果
The original @array = 1 2 3 4 5 6
After shift @array = 2 3 4 5 6
first element of @array is 1
Shift back the first element
Now @array = 1 2 3 4 5 6
After pop @array = 1 2 3 4 5
The last element of @array is 6
After push @array = 1 2 3 4 5 6


具体可以看shift unshift pop push