James Poni wrote:
> 
> Hello again
> 
> I slightly changed the input but icant seem to get the output like this
> below:
> bbb beta sun 1,1
> aaa aplha mon 2,2
> ddd delta tue 3,3
> ccc gamma wed 4,4
> 
> How would i modify this program in order to do so ?
> 
> THIS I THE PROGRAM

use warnings;
use strict;

> $line1 = "aaa alpha\nbbb beta\nccc gamma\nddd  delta\n";
> $line2 = "mon\nwed\nsun\ntue\n";
> $line3 = "1, 1\n2, 2\n3, 3\n4, 4\n";

my $line1 = "aaa alpha\nbbb beta\nccc gamma\nddd  delta\n";
my $line2 = "mon\nwed\nsun\ntue\n";
my $line3 = "1, 1\n2, 2\n3, 3\n4, 4\n";


> open ( ALPH, ">pl.txt" ) || die "Cant open\n";

You should include the file name and the reason in your error message.

open( ALPH, ">pl.txt" ) || die "Cant open pl.txt: $!";

> print ALPH $line1;
> close ALPH;
> 
> open (AP, "<pl.txt" )  || die "Cant open\n";
> $info1 = <AP>;

$info1 should be an array and you should be removing the newlines.

chomp( my @info1 = <AP> );

> close AP;
> 
> open ( DAY, ">da.txt" ) || die "Cant open\n";

open( DAY, ">da.txt" ) || die "Cant open da.txt: $!";

> print DAY $line2;
> close DAY;
> 
> open (DA, "<da.txt" )  || die "Cant open\n";
> @info2 = <DA>;

chomp( my @info2 = <DA> );

> close DA;
> 
> open ( NUM, ">numb.txt" ) || die "Cant open\n";

open( NUM, ">numb.txt" ) || die "Cant open numb.txt: $!";

> print NUM $line3;
> close NUM;
> 
> open ( NU, "<numb.txt" ) || die "Cant open\n";
> @info3 = <NU>;

chomp( my @info3 = <NU> );

> close NU;
> 
> my @info;
> my %days = (
>         sun => 0,
>         mon => 1,
>         tue => 2,
>         wed => 3,
>         thu => 4,
>         fri => 5,
>         sat => 6,
>         );
> 
> my $count;
> chomp, push @{$info[$count++]}, $_ for <@info1>;
                                         ^^^^^^^^
> $count = 0;
> chomp, push @{$info[$count++]}, $_ for <@info2>;
                                         ^^^^^^^^
> $count = 0;
> chomp, push @{$info[$count++]}, $_ for <@info3>;
                                         ^^^^^^^^

You don't want to use a file glob here, just an array.

my $count;
chomp, push @{$info[$count++]}, $_ for @info1;
$count = 0;
chomp, push @{$info[$count++]}, $_ for @info2;
$count = 0;
chomp, push @{$info[$count++]}, $_ for @info3;


> @info = sort { $days{$a->[1]} <=> $days{$b->[0]}  } @info;
                           ^^^                ^^^
You are trying to sort on two different fields here

@info = sort { $days{$a->[1]} <=> $days{$b->[1]}  } @info;


> for my $row ( @info ) {
>     print "@$row\n";
> }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to