Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Football formation

by crashtest (Curate)
on Oct 28, 2014 at 03:50 UTC ( #1105249=note: print w/replies, xml ) Need Help??


in reply to Football formation

Is this homework? If so that's fine but you should indicate it, and get started on the problem yourself. The monks will be happy to help you if you get stuck. Loops just gave you a nice terse solution but how would you explain it to a teacher or professor if she asked?

As a starting point, this is a pretty standard way in Perl to open a file for reading and iterate over its contents line by line:

open (my $file, '<', 'formation.txt') || die "Error opening file: $!"; while (<$file>) { chomp; # removes trailing newline character print "Line contents: $_\n"; }
If you want to store the lines of a file in an array, you can use push (actually, there are much shorter ways to "slurp" the contents of a file into an array, but this works fine):
my @lines; open (my $file, '<', 'formation.txt') || die "Error opening file: $!"; while (<$file>) { chomp; # removes trailing newline character push @lines, $_; }

Replies are listed 'Best First'.
Re^2: Football formation
by eminempark (Initiate) on Oct 28, 2014 at 04:16 UTC
    Hi, for sure it is not home work

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2020-05-27 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (154 votes). Check out past polls.

    Notices?