user966588
user966588

Reputation:

divide array contents on newline in perl

I want to use contents stored in array line by line.

But I am unable to split it on '\n'. can you guide me on this.

Note that the array contents is coming from select query on Text column of SQL table.

@somearray="SELECT column from table where condition=something" (column type is "Text")
foreach $line(@somearray)
{
   if($line=~/match-anything-here/) 
   {
       //The match is done on whole array contents and not line by line  
       print $line;
   }
}

Upvotes: 0

Views: 278

Answers (1)

dma_k
dma_k

Reputation: 10639

The code might look like:

@somearray = <"SELECT column from table where condition=something">

foreach $line (@somearray)
{
   next unless $line =~ /match-anything-here/;

   foreach (split(/\n/, $line))
   {
       print "line: $_; ";
   }
}

Upvotes: 1

Related Questions