[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: [PERL] variable / automatisk



On Thu, 24 Jan 2002, Henning Hansen wrote:

> Jeg kunne godt bruge lidt hjælp da jeg er sikker på at en "perlhaj" kan få
> dette til at fylde een linie.

Den magiske funktion er eval.

Du laver en streng med det, du vil have udført

$a= q[
 if ($status1 eq "I GANG"){$h1 = sprintf("%.2f", $h1);$u1 = sprintf("%.2f",
 $u1);}
];

Også eval'er du $a:

eval $a;

Mon ikke du nu selv kan finde ud af at lave en version, der løber fra 1 -
11?

Umiddelbart vil jeg dog tro, at din opbygning af scriptet er forkert.
Overvej, om du ikke istedet skal bruge hashes:

for $n (1..11) {
 if ($status{$n} eq "I GANG"){$h{$n} = sprintf("%.2f", $h{$n});$u{$n} =
sprintf("%.2f", $u{$n});}
}

Det er væsentligt pænere end eval-løsningen og vil i de fleste tilfælde
være hurtigere, idet eval laver en compile-on-the-fly.


/Ole
-- 
Søges: 2-3 vær. lejlighed i Kbh K N Ø V. Eje, andel eller leje. Pris < 55/m2
Så hvis du kender nogen, der kender nogen, så drop en mail.



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 19:54 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] *