Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: single quotes not allowing in perl

by vasanthgk91 (Sexton)
on May 24, 2013 at 13:30 UTC ( #1035133=note: print w/replies, xml ) Need Help??

in reply to Re: single quotes not allowing in perl
in thread single quotes not allowing in perl

thank u very much..

$title value i receiving from param array then i match perl regex condition if the condition satisfies means i will do my work..

if($title=qr(^([a-zA-Z0-9 -.()%&:;,"'/]+)$)) { print "Do my work"; }

this is works fine..great thanks

Replies are listed 'Best First'.
Re^3: single quotes not allowing in perl
by hdb (Prior) on May 24, 2013 at 13:39 UTC

    Be careful! You have lost the ~ in your match. And you need to place the - at the beginning of the character class. See this example:

    use strict; use warnings; my $title = 'have ++ fun#'; if($title=~qr(^([a-zA-Z0-9 -.()%&:;,"'/]+)$)) { print "Do my work 1\n"; } if($title=~qr(^([-a-zA-Z0-9 .()%&:;,"'/]+)$)) { print "Do my work 2\n"; }

      Update: Looked again, found the lost tilde in the  $title=qr(...) bit of code, not in the regex expression where I was looking. Nevermind...

      You have lost the ~ in your match.

      I don't see a  '~' (tilde) in the original
          if($title=~/^([a-zA-Z0-9 \.\-\(\)\%\&\:\;\,\"\']+)$/)
      match. Can you clarify how it was lost?

      why use hyphen symbol very beginning..really i don't know that's why i ask u

        If the hyphen is in the middle of a character class, it defines a range. /[a-z]/ matches any lower case character. In the same way /[ -.]/ defines the range of ASCII characters between " " and "." and these are:  !"#$%&'()*+,-.. If the hyphen is at the start of the class, it will be taken as a hyphen and not to define a range.

        Hyphen is used to match ranges like A-Z and 0-9. But sometimes you want to really match hyphen. In this case there are some fairly convoluted and difficult to remember rules specifying when hyphen means hyphen. An easy rule of thumb though is that if the hyphen is at the very beginning or very end of the range, it means hyphen.

        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
        You had used a long word "beginning" (instead of, say, "start"), yet you continue to use "u" instead of "you". Oh, find some punctuation signs & use them appropriately while there.
Re^3: single quotes not allowing in perl
by Corion (Pope) on May 24, 2013 at 13:31 UTC

    What do you mean by "receiving from param array"?

    Please show a working, short program (20 lines) that reproduces the problem.

      yeah I use CGI platform..So i receive form datas through param array..

      use CGI; my $cgi=new CGI; my $title=$cgi->param("title");

        So, remove CGI, and put the text you enter directly into your Perl script. Maybe the text is encoded UTF-8? Did you properly decode it? See Encode.

        We can keep guessing for a long, long time, but it will be much more efficient if you show us a short, self-contained program that shows the problem and does not require user input.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035133]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-01-23 20:30 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (195 votes). Check out past polls.