[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] PERL/named parameters, prefix hyphen



donald_j_axel <sslug@sslug> writes:

> sub func {
>    my %dfl =  ( Date => 1,
>                 Month => 1,
>                 Year => 1970
>                );
>     my %args = (%dfl, @_);
>     print "Year: $args{Year}\n";
> }

Den måde at udtrykker sig på i perl er jeg godt nok aldrig stødt på
før. Hvor har du fundet på den henne?

> func(Year=>2004);
> func(-Year => 2004); # Overfører ikke Year men '-Year' som jo er en string.

Selvfølgelig. '=>' er bare et komma der sørger for at det der står før
bliver opfattet som en streng.

> Man kan stadig, fra kommandolinien, hente parametre med 
> 
> use CGI qw/:standard :netscape/
> my $value = param(-password);
> if (defined($value)) print $value."\n";

Arghh... Lad være med at brug CGI.pm hvis det ikke er et cgi-script
du skal lave.

Hvis du vil parse komandolinjen bør du se på Getopt::Long istedet.

use Getopt::Long;
my %args;

GetOptions(\%args, 'passwd=s');


> På kommandolinien -password="zeKret" bevirker at param returnerer zeKret.
> 
> Jeg kan godt leve uden at vide sandheden, men har man nogensinde
> kunnet gøre func(-Year => 2004) uden speciel kode? (som jeg har liggende
> men ikke sender med her.)

Det tror jeg ikke. Jeg har aldrig set den slags kode før.

-- 
 Peter Makholm     |      There are 10 kinds of people. Those who count in
 sslug@sslug |                            binary and those who don't
 http://hacking.dk |                                                      


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *