Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Substring comparisson problem

by golux (Pilgrim)
on Nov 27, 2013 at 19:16 UTC ( #1064689=note: print w/ replies, xml ) Need Help??


in reply to Substring comparisson problem

Hi ChTidio,

It's because you're looking for the substring "Hello" with the quotes. Get rid of them and try again:

my $string = "Hello World"; if ($string =~ /Hello/) { print "Basic String contains: Hello\n"; }

Update:   You could also put quotes around 'Hello' with any of the following (among other possibilities):

my $string = "\"Hello\" World"; my $string = '"Hello" World'; my $string = q{"Hello" World}; my $string = qq{"Hello" World};

Then your original regex should find the quoted substring "Hello":

if ($string =~ /"Hello"/) { print "Basic String contains: Hello\n"; }
say  substr+lc crypt(qw $i3 SI$),4,5


Comment on Re: Substring comparisson problem
Select or Download Code
Re^2: Substring comparisson problem
by ChTidio (Initiate) on Nov 27, 2013 at 19:28 UTC
    Thank you! That was it. After your reply, I went back and double-checked the book I am using for a reference (an older book on Perl 5) and it included the double quotes - exactly as I had typed the line. My trust in the rest of the material in that book has just diminished. Will have to look for a better/newer book. Thanks again for the prompt and complete reply!
      Not that having a newer, shinier book is not nice, but if $$$ count, do two things before diminution of trust is a absolute reason to buy a new one:
      1. Check in internet (publisher's site) for a listing of errata. Good books tend to have them. Reliable publishers tend to post them.
      2. Check the head section for an explanation of any formatting conventions. Granted, what you've quoted sounds pretty-non-standard and confusing, well-edited books on any programming language tend to have a set of conventions that are explained "up front" (for some somewhat variable value of "up front") and then used without further ado.

      And if/when you do go looking for a new book, I recommend that you search first, foremost, and likely last at O'Reilly and Apress. Not all publishers of texts on Perl can/do provide reference or tutorials that come even close, although you may want to search this site for some recommended sources -- in print and online.

      Jumping to conclusions is poor exercise!

        I would also definitely recommend O'Reilly, you'll be sure to have books written by some of the best experts.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-10-02 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (43 votes), past polls