Adriano Allora wrote: > hi to all, Hello,
> another silly question about a pattern matching which should work but it > doesn't. > > I have a list af string similar to this one: > > parola|n.c.,0,fem,sg,0|parola > > and I need to select all the chars before the pipe and put them in a > variable. > > That substitution does'n work: > > #!/usr/bin/perl -w > use strict; > my(%gen, %act, %record, $tex, $char, @parola, $zut); > while(<>) > { > $tex =~ s/^([^|]+).*/$1/o; > print STDOUT "$i errore sulla linea: $_\n" if !$tex; > } > > The error message is (for example): > > Use of uninitialized value in substitution (s///) at > ./contalettere.pl line 6, <> line 10. > > I suppose the rror is in the expression: [^|]. > > Someone can help me? The problem is that you are using the variable $tex but it doesn't contain anything. You could do either: while ( <> ) { ( my $tex = $_ ) =~ s/^([^|]+).*/$1/s; print "$i errore sulla linea: $_\n" if !$tex; } Or: while ( <> ) { /^([^|]+)/ and my $tex = $1; print "$i errore sulla linea: $_\n" if !$tex; } Or: while ( <> ) { my ( $tex ) = /^([^|]+)/; print "$i errore sulla linea: $_\n" if !$tex; } But then you also have the problem that $i is not defined. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>