CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Continously pushing variables into array

 



sparsh
Novice

Aug 21, 2015, 10:20 AM

Post #1 of 3 (1231 views)
Continously pushing variables into array Can't Post

Hi,

I am extracting some data, and it is in this form:

1 - content1
2 - content2

I need to store content1 and content2 into an array, and the numbers (1,2) keep going until a maximum of 50. I tried using regular expression to catch content1 and content2, but since they have a similar format, I am only grabbing content2.

Here is my code


Code
while ($file= <INFO>) 

{
if ($file =~ m/^\s*(\d+)\s*(-)\s*(.*)/)
{
$number_count = $1;
$violation = $3;
}

for ($number_count = $1; $number_count < 50 ; $number_count++)
{
push (@violations_array ,$violation);
}

}

im getting multiple instantiations of content1 and content2 in the array when i print it. Any ideas how to do this correctly?


(This post was edited by FishMonger on Aug 21, 2015, 10:26 AM)


FishMonger
Veteran / Moderator

Aug 21, 2015, 10:34 AM

Post #2 of 3 (1228 views)
Re: [sparsh] Continously pushing variables into array [In reply to] Can't Post

Why are you doing the push statement inside a for loop?

Doing that is the cause of the problem.


(This post was edited by FishMonger on Aug 21, 2015, 10:34 AM)


sparsh
Novice

Aug 21, 2015, 10:35 AM

Post #3 of 3 (1225 views)
Re: [FishMonger] Continously pushing variables into array [In reply to] Can't Post

Yes I removed the loop and got it working. Rookie mistake.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives