Need help splitting a file in Perl?

Haley ...

New member
As a beginner in perl, I am not sure how to do this. The file I want tosplit is pwm.pl and the contents are: .4 .01 .1 .9
.1 .03 .3 .1
.49 .95 .4 .1
.01 .01 .2 .3

I want to split the numbers separately from each other. I have got a few parts that are a HOT MESS which im aware is not close to working. Tips? Help?

#! usr/bin/perl

use strict;
use warnings;

retrievingData();

sub retrievingData {
open(MYINPUTFILE, "<pwm.pl");
my(@lines) = <MYINPUTFILE>;
my($line);
foreach $line (@lines)
{
print "$line";
}
close(MYINPUTFILE);
}


observedProbability();

sub observedProbability {
my %observed;
my $line;
my $i;
my @file;
my $alllines=(<$INPUT>);

$observed{"A"}=[];
$observed{"C"}=[];
$observed{"G"}=[];
$observed{"T"}=[];
@elements=split(/\s+/,$alllines[0]);
foreach $i(@elements);
for (my $i=0; $i<@file; $i++){}
print "$i\n";
 
The top of your program is fine. Try replacing the bottom half with the following, I think it will get you closer to what you want:

...
foreach $line (@lines)
{
observeProbability($line);
}
close(MYINPUTFILE);
}

sub observedProbability {
my %observed;
my $line = shift;
my @file;

$observed{"A"}=[];
$observed{"C"}=[];
$observed{"G"}=[];
$observed{"T"}=[];
my @elements = split(/\s+/,$line);
foreach my $i (@elements)
{
print "$i\n";
} # foreach
} # observedProbability
 
Back
Top