[Linux-Biella] Perl e espressioni regolari in array
vallini.daniele a bilug.linux.it
vallini.daniele a bilug.linux.it
Ven 23 Apr 2010 14:17:58 CEST
Fri, Apr 23, 2010 at 11:18:39AM +0200 Claudio M. ha scritto:
> Ho un problema con un piccolo codice perl
>
> Ho un array con una serie di espressioni regolari e ho un file che devi
> elaborare
> Come faccio ad esaminare riga per riga il file in input e avere in output
> tutte le righe che soddisfano anche una sola delle espressioni regolari?
>
> Es.
> @trova = ();
> push @trova, "\\spippo\\s";
> push @trova, "\\spluto\\s";
>
> while (<WALTDISNEY>) {
> chomp;
> my $riga = $_;
> foreach $personaggio (@trova) {
> if ($riga =~ /$personaggio/) {
> print $_;
> }
> }
> }
>
> questo ovviamente non funziona in quanto mi da un errore di sintassi nella
> riga dell'if
>
> Avete idee?
Non ne ho mai fatto uso e ne so ben poco, forse pero' potrebbe fare al caso
tuo perche' prevede chiaramente il confronto con espressioni regolari:
Params::Check is a generic input parsing/checking mechanism.
It allows you to validate input via a template. The only requirement is that the arguments must be named.
Params::Check can do the following things for you:
* Convert all keys to lowercase
* Check if all required arguments have been provided
* Set arguments that have not been provided to the default
* Weed out arguments that are not supported and warn about them to the user
* Validate the arguments given by the user based on strings, regexes, lists or even subroutines
^^^^^^^
* Enforce type integrity if required
la documentazione e' in perldoc-html-5.10.1
Maggiori informazioni sulla lista
Linux