April T.Barrett <[EMAIL PROTECTED]> asked: > I need some tips on going about regular expression: > > parsing through a text file and printing all of the words > that - for example - Begin and end with an "G"
Sample text courtesy of Project Gutenberg: #!/usr/bin/perl -w while( my $line = <DATA> ){ while( $line =~ m/\W((g\w*?)|(\w*?g))\W/ig ){ print "Line $.: $1\n"; } } __DATA__ Puck's Song See you the dimpled track that runs, All hollow through the wheat? O that was where they hauled the guns That smote King Philip's fleet! See you our little mill that clacks, So busy by the brook? She has ground her corn and paid her tax Ever since Domesday Book. See you our stilly woods of oak, And the dread ditch beside? O that was where the Saxons broke, On the day that Harold died! See you the windy levels spread About the gates of Rye? O that was where the Northmen fled, When Alfred's ships came by! See you our pastures wide and lone, Where the red oxen browse? O there was a City thronged and known, Ere London boasted a house! And see you, after rain, the trace Of mound and ditch and wall? O that was a Legion's camping-place, When Caesar sailed from Gaul! And see you marks that show and fade, Like shadows on the Downs? O they are the lines the Flint Men made, To guard their wondrous towns! Trackway and Camp and City lost, Salt Marsh where now is corn; Old Wars, old Peace, old Arts that cease, And so was England born! She is not any common Earth, Water or Wood or Air, But Merlin's Isle of Gramarye, Where you and I will fare. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>