Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

RE: pattern-matching examples

by Anonymous Monk
on Mar 23, 2000 at 01:22 UTC ( #5920=note: print w/ replies, xml ) Need Help??


in reply to pattern-matching examples

It would be really nice if you would have expamples use the /g option at the end of the reg. expr. A lot of people I know avoid using the $_ character and instead like to use a variable assignment with the =~ explicitly. Thanks P.S. Good site otherwise, but your Reg Exp. section could use more expamples.


Comment on RE: pattern-matching examples
RE: RE: pattern-matching examples
by Aighearach on Apr 22, 2000 at 13:53 UTC
    #!/usr/bin/perl -w # # Here is a CGI example of using a regexp to parse a query string, # when you're not sure exactly what will be in the query string # Put it in you web space, and call it with # http://host/script?param_1=this&param_2=that&the_other=doesntmatchth +emask # or call it with ?error=HelloWebMaster if you want to fill the error +log with garbage # use CGI qw( :standard :HTML ); # set slay typos use strict; # read in the CGI params my $object = new CGI(); # print our HTML header print header(),h1( "params: " ); my $key; # set our variable mask. This part gets thrown out. # At makeyourbanner.com, I use more than one pattern, # so that I can determine the number of text areas and style settings +dynamically. # in CGI programming, this is very handy if you are designing a backen +d, # and don't have advanced knowledge of how the front end will call it. my $mask = "param_"; foreach $key ( $object->param() ) { if ( $key =~ /^($mask)(.+)/ ) { #found a parameter, print it out print "<P>param $2=", $object->param( $key ), "</P>"; } elsif ( $key =~ /error/i ) { #found error flag, print error to the appache logs (you ARE us +ing apache, right?!) print STDERR "error: found $key=", $object->param( $ke +y ), " in $0\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://5920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-07-03 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls