[EMAIL PROTECTED] asked > Can somebody please let me know the meaning of this line. > > > > while (<$in>) > > { > if(/,/) {print "before match: $`\t and after match: > $'\n\n";}; $x=$'; $y=$`; &mysubroutine($x,$y); > }
The loop iterates over a filehandle, setting $_ to each line in turn. If that line contains a comma, then the line is split at the comma and mysubroutine() is being called with the parts before and after the comma as arguments. My first try at tidying this up would be: while( my $line = <$in> ) { if( my( $pre, $post ) = ( $line =~ m/^(.*?),(.*)/ ) ){ print "before match: $pre\t and after match: $post\n\n"; mysubroutine($pre,$post) } } I'm assuming that mysubroutine is only being called if there actually was a match. Your code above would erroneously call it for each line. Using the pre/postmatch captures $' and $` is expensive if you don't need it all the time (cf. perldoc perlre): WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Using &mysubroutine with arguments would only make sense if mysubroutine was defined with prototypes and you were trying to disable that. I'm assuming that in this case it's rather cargo cult programming. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/