csorrentini has asked for the wisdom of the Perl Monks concerning the following question:
I am working on an assignment that requires me to edit a module that will be called from another file. This module has subroutines to return the size in bytes of file, amount of lines in file, name of file, extension, last modified, type of file, contents of file and directory file is in.
While writing the subroutine to return the contents of the file (as an array) it just gives me a number for the output. Here is the subroutine code I made:
What am I missing to make this return the actual contents vs a number? Also this is the code that is calling it:sub contents { open (FH, "< $FileInfoName") or die "Can't open $FileInfoName for re +ad: $!"; my @lines = <FH>; return @lines; close FH or die "Cannot close $FileInfoName: $!"; }
Lastly, I am also trying to create a subroutine to return the directory the file is in. I have only found information on how to return contents of a directory but no how to actually return the directory itself. Thank you Monks!!use strict; use TYPFileInfo; $FileInfoName = "FakeText.txt"; print "\nFilename: " . name(); print "\nExtension: " . extension(); print "\nModified: " . localtime( modified() ); print "\nBytes: " . bytes(); print "\nLines: " . lines(); print "\nType: " . type(); print "\nContents: " . contents();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subroutines....return directory file is in and return contents in array
by toolic (Bishop) on Jun 26, 2014 at 19:24 UTC | |
by csorrentini (Acolyte) on Jun 26, 2014 at 19:31 UTC | |
|
Re: Subroutines....return directory file is in and return contents in array
by Perlbotics (Archbishop) on Jun 26, 2014 at 19:20 UTC | |
|
Re: Subroutines....return directory file is in and return contents in array
by poj (Abbot) on Jun 26, 2014 at 20:56 UTC |