473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

perl--logical help needed

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=@new_directory;
Oct 13 '07 #1
9 1137
eWish
971 Expert 512MB
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 Expert 2GB
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 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. @array = (1 .. 5);
  2. $n = 3;
  3. @new = grep {$_ >= $n} @array;
  4. print "@new";
Oct 13 '07 #4
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
@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 Expert 2GB
perldoc: grep Function
Oct 13 '07 #7
Hi,
a small clarification,even 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 Expert 2GB
Hi,
a small clarification,even 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
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
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...
8
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...
13
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,...
0
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...
3
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...
17
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...
5
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...
0
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...
28
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...
37
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.