Timothy Johnson wrote:
> 
> If you wanted to use shift to make an equivalent routine to Ex #1, you could
> do it like this:
> 
> sub makeArray{
>    while(shift @_){
>       print $_."\n";
>    }
> }
> 
> That way if you called the sub like this...
> 
>    &makeArray('hello','world','!');
> 
> You should get this...
> 
>    hello
>    world
>    !
> 
> as your output.

$ perl -e'
sub makeArray {
    while ( shift @_ ) {
        print $_ . "\n"
        }
    }
makeArray( "hello", "world", "!" )
'



$ perl -e'
sub makeArray {
    while ( $_ = shift @_ ) {
        print $_ . "\n"
        }
    }
makeArray( "hello", "world", "!" )
'
hello
world
!


> 'shift' removes the first element in an array and returns the value.
> If no variable is specified, the value is stored in the $_ variable.

No, it isn't.

$ perl -le'
@array = qw(9 8 7 6 5);
shift @array;
print;
$_ = shift @array;
print;
'

8


> I have lately been converting some of my code to use this format
> instead of foreach() loops because it is shorter and easier to read.

Good luck.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to