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

Re: Foreach loop

by Corion (Pope)
on Sep 27, 2013 at 10:08 UTC ( #1055954=note: print w/ replies, xml ) Need Help??


in reply to Foreach loop

With the code and data you've shown, I cannot reproduce your problem:

#!perl -w use strict; my $key="5 10 14 16 17 20 25 26 38 1 42 4 +7 54"; my $substr = " 1 "; my @newarray= $key; foreach $key ( @newarray ) { if (index($key, $substr) != -1) { print "\nExist (substr)" }; if ($key =~ /\Q$substr\E/) { print "\nExist (RE)" }; if ($key =~ /\s+1\s+/) { print "\nExist (whitespace)" }; } __END__ >perl -w tmp.pl Exist (substr) Exist (RE) Exist (whitespace)

Maybe your data in $key really has tabs in it, but you are searching for blanks?


Comment on Re: Foreach loop
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-09-19 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (145 votes), past polls