Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grouping the datas from the flat file

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hai guys!

I have a flat file

1|A|here comes the text|yes|values2|values3|values4
2|B|here comes the text|no|values2|values3|values4
3|B|here comes the text|yes|values2|values3|values4
4|A|here comes the text|no|values2|values3|values4
5|c|here comes the text|yes|values2|values3|values4
6|B|here comes the text|no|values2|values3|values4

Its a huge flat file.

I need to display all the A's and B's and C's as a separate group

Like

A results
1|A|here comes the text|yes|values2|values3|values4
4|A|here comes the text|no|values2|values3|values4

B results
2|B|here comes the text|no|values2|values3|values4
3|B|here comes the text|yes|values2|values3|values4

C results

5|c|here comes the text|yes|values2|values3|values4

If iam using a database i can use a query

like

select * from where name=A;

Is there any easy way to group the values other than putting a longer loops

Like

while(<filehandle>)
{
if($values collected from the flat file eq A)&amp;&amp;if($values collected from the flat file eq yes)
{
collecting the values in another separate array

}
}



Any help will be appriciated

Thanks



 
i don't know of any modules for flat file databases, but you might want to check cpan. if you can't find anything, you're probably gonna have to go with the loop. adam@aauser.com
 
Sure, just do exactly what you said.....

open(IPF,&quot;<yourFile&quot;) or die &quot;Failed to open input file, $!\n&quot;;
while ($line = <IPF>)
{
# catch the A-Z char in $1
$line =~ /\d\|([A-Z])/;

# put the line in an array named with that letter.
$letter = $1;
push @$letter,$line;

# you might be able to do the previous two lines in one line, like,
# push @$1,$line;

# If the letters are not used sequentially, you will need
# know which letters were used......so,
# record the occurrence of each unique letter.
$letters{$letter} = 1;

# if the letters are used in order, then this is not necessary, as you could
# assume A to Z and go until the array of interest did not exist.

}
close IPF;

# if the letters were not used sequentially,
@letters = sort(keys(%letters));
foreach $letter (@letters)
{
print &quot;$letter results\n&quot;;
print &quot;@$letter\n&quot;;
}

# or, if the letters were used sequentially,
foreach $letter (A..Z)
{
if (@$letter)
{
print &quot;$letter results\n&quot;;
print &quot;@$letter\n&quot;;
}
}



keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top