Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Substring comparisson problem

by golux (Hermit)
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

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2018-06-22 13:30 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.