[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
 

Variabler?



Jeg er netop gået igang med at lege med Perl, og synes det er fantastisk brugbart. Uheldigvis er jeg stødt på et problem, jeg ikke lige kan overskue, og jeg har ikke lige kunnet finde svaret i dokumentationen. (Hvad er for øvrigt den bedtse Perl bog at starte med?)


Det program jeg er ved at lave skal samle nogen inddatafiler fra forskellige leverandører sammen, og behandler dem ud fra fil navnet. Jeg har følgende konstruktion i programmet:

foreach (@dfiles)
	if (/t(\d\d)(\d\d)(\d\d)/i){
	    $outf="$outdir\\20$1$2$3.txt";
	    if (-e $outf){
                    ....
                    }
	    else {... }
	}

Da der er mange typer filer, og mange outputformater, vil jeg kunne gøre disse variable.
Først ændre jeg til at regexp erstattes af en variabel - det går nemt nok :

my $regexp="t(\\d\\d)(\\d\\d)(\\d\\d)";

foreach (@dfiles)
	if (/$myregexp/i){
	    $outf="$outdir\\20$1$2$3.txt";
	    if (-e $outf){
                    ....
                    }
	    else {... }
	}
men formatet for $outf vil jeg også gøre variabelt. Noget i stil med:

my $outfileformat= "20$1$2$3.txt";
my $regexp="t(\\d\\d)(\\d\\d)(\\d\\d)";

foreach (@dfiles)
	if (/$myregexp/i){
	    $outf="$outdir\\$myoutfileformat";
	    if (-e $outf){
                    ....
                    }
	    else {... }
	}

Hvilket selvfølgelig ikke virker - men hvordan gør jeg noget tilsvarende. Ideen er at jeg i en konf fil gemmer regexp, og outfil formater, så det er nemt at tilrette når leverandørerne ændrer deres formater.


med venlig hilsen

Søren




 
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] *