473,699 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

perl--logical help needed

13 New Member
I need a help with my code...
What I want to do is:
if there exists a directory_no, and found in the directories array , want to copy the contents of that array to a new array from where the directory_no is found to till the end of that array.
In the end copy the new_directory array to the directories array;

Ex:directories array: 1 2 3 4 5
directory_no is 3.
Output :new_directory 3 4 5
in the end directories array: 3 4 5


Expand|Select|Wrap|Line Numbers
  1. if($directory_no)
  2.   {
  3. foreach $directory (@directories)
  4.       {
  5.         $count++;
  6.         print "$count";
  7.         if($directory = $directory_no)
  8.         {
  9.               for($count;$count<=@directories;$count++)
  10.               {              
  11.               $new_directory[i]=$directories[$count-1];
  12.               $i++;              
  13.               }              
  14.           exit; 
  15.         }
  16.       }
  17. }
@directories=@n ew_directory;
Oct 13 '07 #1
9 1145
eWish
971 Recognized Expert Contributor
if($directory = $directory_no)
If you are comparing numerically then you would use ==. If you are comparing a a string then use eq.

Expand|Select|Wrap|Line Numbers
  1. if($directory eq $directory_no)
perlop
Oct 13 '07 #2
KevinADC
4,059 Recognized Expert Specialist
A very common error to use the assignment operator "=" instead of a comparison operator "==":

if ($directory = $directory_no)
Oct 13 '07 #3
KevinADC
4,059 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1. @array = (1 .. 5);
  2. $n = 3;
  3. @new = grep {$_ >= $n} @array;
  4. print "@new";
Oct 13 '07 #4
bhumikas
13 New Member
Expand|Select|Wrap|Line Numbers
  1. @array = (1 .. 5);
  2. $n = 3;
  3. @new = grep {$_ >= $n} @array;
  4. print "@new";
can u xplain the third line....
Oct 13 '07 #5
Xmassey
6 New Member
@new = grep {$_ >= $n} @array;

Only values that are more than or equal to $n (which is 3) are taken from @array and placed into the new array @new
Oct 13 '07 #6
KevinADC
4,059 Recognized Expert Specialist
perldoc: grep Function
Oct 13 '07 #7
bhumikas
13 New Member
Hi,
a small clarification,e ven if i put && <=$p its gonna evaluate rite as its an expression.

Expand|Select|Wrap|Line Numbers
  1. @new = grep {$_ >= $n && <= $p} @array;
then it gonna put the values in between certain range into the new array...
Oct 16 '07 #8
KevinADC
4,059 Recognized Expert Specialist
Hi,
a small clarification,e ven if i put && <=$p its gonna evaluate rite as its an expression.

Expand|Select|Wrap|Line Numbers
  1. @new = grep {$_ >= $n && <= $p} @array;
then it gonna put the values in between certain range into the new array...
Yes, you can put any valid code into the expression thats evaluatued. Your code looks better writeen as:

Expand|Select|Wrap|Line Numbers
  1. @new = grep {$_ >= $n && $_ <= $p} @array;
of course $p needs to be defined.
Oct 16 '07 #9
bhumikas
13 New Member
Yes, you can put any valid code into the expression thats evaluatued. Your code looks better writeen as:

Expand|Select|Wrap|Line Numbers
  1. @new = grep {$_ >= $n && $_ <= $p} @array;
of course $p needs to be defined.

thnks for the suggestion.....
Oct 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2768
by: System | last post by:
Hello All, Redhat 9.0 Mysql 3.23.56 ==> Running I want to upgarde to 4.0.13 but this is the error it says: # rpm -Uvh MySQL-server-4.0.13-0.i386.rpm warning: MySQL-server-4.0.13-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5 error: Failed dependencies: libmysqlclient.so.10 is needed by (installed) mod_auth_mysql-1.11-12
8
1607
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored procedure. If there are no records returned then this would give me an indicator and I can re-direct the page somewhere more appropriate. Well this is the theory. I have never used datatables before and am not sure how to implemenet what I want so I was...
13
1747
by: Joe Feldman | last post by:
This position is located in the South Bay Area in Northern California. If you are interested please send me your resume in a word .doc so that I can review it. If this does not look like a match, we have over 100 other open positions. Senior Member of Technical Staff/ Principal Engineer- Protocols Infrastructure
0
1798
by: Cindy B | last post by:
Please send your resume and position to Cindy@AtlanticResource.com! I CAN NOT accept candidates that ARE OUTSIDE OF THE US! NO PHONE CALLS PLEASE! Email your resume to me! Position:SQL SERVER/PEOPLESOFT DBA Date: 03/07/05 Location: Richmond, VA Duration: 5 month conract to hire Salary: 65,000-80,000K Contract to Hire 5 months
3
2267
by: Wade | last post by:
I would like to install the .Net 1.1 framework on a Web Server running W2K to be able to run ASP.NET files, but I'm not sure where to find the files I need for the .Net framework. I have ".NET Framework 1.1 Service Pack 1" (NDP1.1sp1-KB867460-X86.exe) and "ASP.NET Security Update for .NET Framework 1.1 SP1" (NDP1.1sp1-KB886903-X86.exe). The SP1 will not install unless 1.1 is already installed (I thought that SP1 was the whole 1.1...
17
2344
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object)." Does that mean that in the following code, *p does not have to be evaluated since its side...
5
1708
by: Steve | last post by:
Hi, I am sitting down to design our next set of internal apps. I would like to approach this in a way that would allow me to break logical parts of the application that handle specific tasks into modules. For example, assuming we have 4 main tasks to accomplish: - Printing - Editing - Viewing - Inventory Management
0
1484
by: ultradiv | last post by:
I have a VB.NET application partly built that produces an xml output (just a file at present) I have a .NET webserver and SQLserver 2000 I need to be able to send the xml to the webserver/database (some crunching is needed before the data is stored) The database (stored proc.) will reply with several small pieces of data which need to be sent back to the client app. I am thinking that all of this could be accomplished in one call to a...
28
1939
by: Ian Davies | last post by:
Hello I would appreciate some help from someone who has knowledge of working with css, php javascript and how they interact. Ive been working on a task for the last few days and have started to hit a brick wall. I need general advice on whether I m tackling the problem the correct way and some solutions for my current problems Ive posted my project below where ive detailed the current problems im having...
37
2398
by: C_guy | last post by:
Does anyone know of a (hopefully free) tool that can traverse a project and determine which "#include"s are not needed or needed in every .C file? This would be helpful in removing header inclusions that are redundant and/or unnecessary. Thanks!
0
8697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8621
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9184
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9042
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8929
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8891
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5878
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.