473,561 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to match string inside of array?

If I have an array like:

@arr = ('one', 'two', 'three');

And the varaible $myvar = 'two';
How do I check if $myvar matches 'two' in @arr?

I know I could iterate through the array with
a foreach statement, but was wondering if there
was a more efficient method.

-Thanks
Dec 16 '05 #1
4 16410
somebody wrote:
How do I check if $myvar matches 'two' in @arr?

I know I could iterate through the array with
a foreach statement, but was wondering if there
was a more efficient method.


perldoc -q contains

jue
Dec 16 '05 #2
On Fri, 16 Dec 2005 23:19:28 +0000, Jürgen Exner wrote:
somebody wrote:
How do I check if $myvar matches 'two' in @arr?

I know I could iterate through the array with
a foreach statement, but was wondering if there
was a more efficient method.


perldoc -q contains

jue

I don't seem to have that. Is it a separate module?

mybox:> perldoc -q contains
No documentation for perl FAQ keyword `contains' found
Dec 16 '05 #3
In article <4YHof.11993$fY 5.2618@trnddc02 >, Jürgen Exner
<ju******@hotma il.com> wrote:
somebody wrote:
How do I check if $myvar matches 'two' in @arr?

I know I could iterate through the array with
a foreach statement, but was wondering if there
was a more efficient method.


perldoc -q contains


In my version (5.8.6) you have to search for "contained"

FYI to OP: this newsgroup is defunct; try comp.lang.perl. misc in the
future.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Dec 16 '05 #4
somebody wrote:
On Fri, 16 Dec 2005 23:19:28 +0000, Jürgen Exner wrote:
somebody wrote:
How do I check if $myvar matches 'two' in @arr?


perldoc -q contains


I don't seem to have that. Is it a separate module?

mybox:> perldoc -q contains
No documentation for perl FAQ keyword `contains' found


Strange. I get

E:\>perldoc -q contains
Found in E:\[...]\perlfaq4.pod
How can I tell whether a list or array contains a certain element?
jue
Dec 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
17523
by: wonil kim | last post by:
Hello all, I am new guy on C#. So, my question will be very simple to you guys here. I want to use string constants array from C# like C++ like below. in C++ : char const * const attr_strings = { "NORMAL", "EDGE",
2
8696
by: bluebeta | last post by:
Hi, I am using embedded visual C++ 4.0 and I want to use function strtok to split string into array. my sample code is as below: ---------------------------------------------------------------- void CNEWSERIALNO::OnBInsert() { // TODO: Add your control notification handler code here
10
11901
by: pantagruel | last post by:
Hi, I'm looking for an optimal javascript function to split a camelcase string and return an array. I suppose one could loop through the string, check if character is uppercase and start building a new word to add to the array but that seems incredibly wasteful. must be some easy way to do it.
1
5599
by: lejason | last post by:
Hello, I am looking for a way to do a string search inside an xml. Basically, I work for a company that wants to export an XML file from and excel sheet and then have that data be presented on the web. Part of the presentation is that they want to be able to "search" for their favorite dealers. So, this will be a string search. The...
4
12724
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or double-quotes or not inside any quotes? If so how? Thanks in advance: Michael Yanowitz
1
1232
by: sunil68 | last post by:
I am able to pass the string to array of string please help me out with this problem string s ="This is a hat"; and the output should be like this This is a hat
5
2090
by: jc | last post by:
It would appear I cannot do this unless it's a richtextbox... but is there any way I can change the color of a given string inside a textbox control? Maybe with javascript? Postrender? CSS? If not, does anybody have any javascript code where I can atleast select (hilite) the given text?
5
4835
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. Dim Array() As Char Dim strwork As String = "76A3kj9d6" Array = strwork.ToCharArray OR
6
3435
by: ekailan | last post by:
I am reading a file line by line I need to copy the line which is string to array of chars named packet. what function could help me do that. this is my code: char *packet; packet=new char ; ifstream inFile2; string t, line; cout<<"Enter a file name.\n";
0
7558
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8072
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7924
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6195
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5177
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3609
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
884
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.