Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Football formation

by crashtest (Curate)
on Oct 28, 2014 at 03:50 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105249]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-24 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found