in reply to perlapp, die, and __DATA__

You can't use the <DATA> filehandle with perlapp.

Also couple of comments on your code:

use strict; package SAR; &get_args (@ARGV); #Ok here you're passing a copy #of @ARGV into get_args's @_. #BTW your don't need & the #trailing ()'s make strict happy sub get_args { my @help = <DATA>; #Why read this now #You don't know if you need #it yet. ($ARGV[0] eq "/?") && (die @help); #Ok you passed the contents of #@ARGV into your sub in @_ but #you ignore it and read the #global @ARGV directly. #copy @_ that way you don't have #to worry about modifing the #global @ARGV. #my @array = @_; #die @help if ($array[0] eq "/?") }
UPDATE: integral is absolutely right, and I'm in a case of do what I mean not what I say :(. Updated comment to correct.

grep
Mynd you, mønk bites Kan be pretti nasti...

Replies are listed 'Best First'.
Re: Re: perlapp, die, and __DATA__
by integral (Hermit) on Apr 25, 2003 at 06:44 UTC

    Perl passes by alias, so using @_ instead of @ARGV will not prevent worries about modifying the global @ARGV. Options are to make a lexical copy (my @args = @ARGV) or to localise (local @ARGV = @ARGV).

    use strict; use warnings; print "1: @ARGV\n"; foo(@ARGV); print "3: @ARGV\n"; sub foo { print "2a: @_\n"; $_[0] = "foobar"; print "2b: @_\n"; }

    (Note however that the elements are aliased indivualluy into @_ not the whole array, so if @ARGV is empty there will be no modification as you are then adding a new element to @_ instead of modifying an element in @ARGV through @_.)

    --
    integral, resident of freenode's #perl