Passing Arrays to Perl Functions

   



Finding Exact Matches in Text Strings

Listing C.22 shows you how to perform various pattern matches which leverage the techniques and concepts that you've seen thus far.

Listing C.22 multiMatch1.pl

start example
my($line1) = "123"; my($line2) = "abcde"; my($line3) = "x = 3; # this is comment"; my($line4) = "123-45-6789"; my($left)  = ""; my($right) = ""; if( $line1 =~ /^\d+$/ ) {    print "$line1 contains only digits\n"; } if( $line2 =~ /^[a-zA-Z]$/ ) {    print "$line2 contains only letters\n"; } if( $line3 =~ /#/ ) {    ($left, $right) = split(/#/, $line3);    print "$line3 contains a comment:  $right\n"; } $line3 =~ s/^\s+//; if( $line3 =~ /^#/ ) {    print "$line3 is a comment line\n"; } if( $line4 =~ /^(\d\d\d)-(\d\d)-(\d\d\d\d)$/ ) {    print "$line4 has a SSN format\n"; }
end example

Remarks

You can launch the Perl script multiMatch1.pl in Listing C.22 from the command line as follows,

perl -w multiMatch1.pl

and the output is as follows:

123 contains only digits x = 3; # this is comment contains a comment:  this is comment 123-45-6789 has a SSN format



   



Fundamentals of SVG Programming. Concepts to Source Code
Fundamentals of SVG Programming: Concepts to Source Code (Graphics Series)
ISBN: 1584502983
EAN: 2147483647
Year: 2003
Pages: 362

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net