in reply to Re^3: Football formation
in thread Football formation

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.

Replies are listed 'Best First'.
Re^5: Football formation
by 2teez (Vicar) on Oct 28, 2014 at 05:36 UTC

    Hi eminempark,
    Loops scripts works, you need to learn to troubleshoot for yourself at some levels.
    If the error you are getting flashes on the screen, then you can simply make that stay to see which line the error occurs and what error is it. Simply use <> at the end of your script.

    Of course, the error I suppose you are pointing at I think is caused by the usage of qw(:all) in the line that uses autodie. You can take that out and see if it works for you.
    Please, check the documentation for the "autodie" pragma, the reasons were given atleast!

    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
      Hi 2teez, can u help me to solve the repeated line? thank you
Re^5: Football formation
by Loops (Curate) on Oct 28, 2014 at 06:47 UTC

    Hey eminempark,

    As GrandFather said in the first reply of this thread, you haven't shown any code or even a description of what you've tried. I made the quick change you're looking for, but am hoping to see you run the ball the rest of the way into the endzone from here:

    use autodie; my (%used, %player); open $player{$_}, '<', "$_.txt" for qw( DR DL DC SW ); open my $formation, '<', 'formation.txt'; for my $position (<$formation>) { chomp $position; while (readline $player{$position}) { my ($name) = split; next if $used{$name}; $used{$name} = 1; last; } print $position, ' ', $_ // "No Player\n"; }
      Hi Loops, Sorry if I didn't explain clearly, what I want is the comparison of the second column before comma (,). I have tried the latest code.
      use autodie; my (%used, %player); open $player{$_}, '<', "$_.txt" for qw( DR DL DC SW ); open my $formation, '<', 'formation.txt'; for my $position (<$formation>) { chomp $position; while (readline $player{$position}) { my ($name) = split; next if $used{$name}; $used{$name} = 1; last; } print $position, ' ', $_ // "NoPlayer\n"; }
      but the output is
      SW Varane,114.75 DR Arbeloa,149 DC Ramos,169 DC Pepe,163 DL Marcelo,148.5 SW Pepe,65.2 DR Carvajal,146 DC Varane,153 DC Nacho,134 DL Coentrao,148
      Pepe is still repeating(although the value (163 and 65.2) is different). It supposed to be:
      SW Varane,114.75 DR Arbeloa,149 DC Ramos,169 DC Pepe,163 DL Marcelo,148.5 SW Nacho,60.3 DR Carvajal,146 DC NoPlayer DC NoPlayer DL Coentrao,148
        Hi Loops, sorry that seems like I make u feel frustrating. u are right. my output are
        SW Varane 114.75 DR Arbeloa 149 DC Ramos 169 DC Pepe 163 DL Marcelo 148.5 SW Nacho 60.3 DR Carvajal 146 DC No Player DC No Player DL Coentrao 148
        My second last question, how to sum all the number in the third column? And my last question, how to save the output automatically to a single file based on formation name. Thank you so much, Loops