Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Football formation

by Loops (Curate)
on Oct 28, 2014 at 03:38 UTC ( [id://1105246]=note: print w/replies, xml ) Need Help??


in reply to Football formation

Hi there. Seems you just want to alternate reading between files, in the order given by the formation file, printing as you go?:

use autodie qw( :all ); my %player; open $player{$_}, '<', $_.'.txt' for qw( DR DL DC ); open my $formation, '<', 'formation.txt'; for (<$formation>) { chomp; print "$_ ", readline($player{$_}) // "No Player\n"; }

Replies are listed 'Best First'.
Re^2: Football formation
by eminempark (Initiate) on Oct 28, 2014 at 04:17 UTC
    It cannot run. :)

      Darn. Why not?

      Update:

      You need a better Perl setup. Don't know what platform you're on but hopefully you can configure your machine to run Perl and install CPAN modules. And most importantly, see error messages without them flashing by. It doesn't make sense to try to do a project like this until you can comfortably run a "hello world" type application.

      If you're impatient though, you can just remove the "use autodie ..." line in the script. You wont get decent errors if one of the files can't be opened. But the error would probably just flash by anyway. ;o)

        Hi Loop,
        Nice work bro.
        If eminempark uses perl version 5.10.1 or better autodie is in the CORE.

        Simply removing qw(:all) from the line use autodie qw(:all) should do.
        More so, using perldoc autodie the documentation will make the reason for the error message obvious.

        My initial reply to eminempark is here Re^5: Football formation

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me
        Thank you so much. It works after i remove the "use autodie qw( :all );" But after i update the formation.txt to:
        SW DR DC DC DL SW DR DC DC DL
        and SW.txt:
        Varane 114.75 Pepe 65.2 Nacho 60.3
        The output is:
        SW Varane 114.75#first line of output DR Arbeloa 149#second line of output DC Ramos 169#third line of output DC Pepe 163#fourth line of output DL Marcelo 148.5#fifth line of output SW Pepe 65.2#sixth line of output DR Carvajal 146#seventh line of output DC Varane 153#eighth line of output DC Nacho 134#ninth line of output DL Coentrao 148#tenth line of output
        The sixth line of output is supposed to be Nacho because Pepe is already appear in fourth line. And same goes to 8th line and 9th line. In other words, the contents of the second column are not suppose to repeat or have the same value.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found