On Mar 17, 7:40 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: > Hi All, > > 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); > > } > > I know it is a while loop for the file handle ($in) and it will be > executed till the end of file but not getting the meaning of if loop. > > What this if loop actually does. Please help
Does it help to see it this way? while (<$in>) { if (/,/) { # Check each line of $in for a match of , (the comma) print "before match: $`\t and after match: $'\n\n"; # Print strings captured before and after the comma $x = $'; # Assign $x whatever is in $' $y = $`; # Assign $y whatever is in $` &mysubroutine($x, $y); # Call the subroutine "mysubroutine" with $x and $y as parameters } } The variables $` $& and $' are special. They match (repectively) $` - the stuff before your match, $& - what you match, and $' - the stuff left after your match. Many people avoid them like the plague since they slow down regular expression matching. (Check perldoc perlvar.) As to what <mysubroutine> actually *does*, there's no way to know without seeing the code for that subroutine. Hope this helps, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/