Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-2007, 09:24 AM
smith smith is offline
Programmer
 
Join Date: Jun 2006
Posts: 108
Rep Power: 9
smith is on a distinguished road
Default Is string in array?

I'm not good with perl but I've been told that I have to make this project in perl. Sorry for all of the questions.

Here is my question: Is there a way in PERL to determine if a string is in an array? Basically search an array for a string?

Code:
@array1 = ("Bnn","Cnn","Dnn");
$string = "Cnn";
Is $string in @array1?
__________________
Code:
for (int i;;) {
   cout << "Smith";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-14-2007, 12:21 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,277
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

I don't know perl, but in most languages you can loop through the index range of the array and compare each string in the array.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-14-2007, 02:30 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 91
Rep Power: 7
KevinADC is on a distinguished road
Default

one way:

Code:
@array1 = ("Bnn","Cnn","Dnn");
$string = "Cnn";

if (grep {$_ eq $string} @array1) {
   print "Found $string\n";
}
else {
   print "Nope, no $string\n";
}
but if @array1 is big, tens of thouands or more of elements, you might use a loop and "last" to break out early on the first true match. But if its just a few hundred/thousand strings, this way will be fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
fread into array position kenna C and C++ 0 08-17-2007 09:03 AM
need help in counting a specify character in a string. lichy Perl 2 06-27-2007 11:03 PM
[Help] String manipulation. afiser Visual Basic Programming 1 05-31-2007 04:24 PM
Python 2D array question annannienann Python 3 04-23-2007 05:36 PM
Accessing a string by array Saint C# Programming 3 10-03-2006 08:33 PM


All times are GMT -5. The time now is 05:16 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads