Re: writing get_script as an external routine callable by C



"BM" == Ben Morrow <ben@xxxxxxxxxxxx> writes:

>> my $filename = 'book1.txt';
>> open(my $fh, '<', $filename) or
>> die "cannot open $filename for reading: $!";
>> my @books;

BM> chomp( my @books = <$fh> );

BM> If you prefer, you can expand that to three statements:

BM> my @books;
BM> @books = <$fh>;
BM> chomp @books;

BM> You can also use File::Slurp::read_file, which will handle opening the
BM> file, chomping the lines and closing the file for you.

read_file doesn't (yet) chomp lines. that option is in the todo
list. but it does make it easier to read in a file as lines. this should
work fine:

use File::Slurp ;
chomp( my @books = read_file( $file_name ) ) ;

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
.



Relevant Pages

  • Re: writing get_script as an external routine callable by C
    ... the Grave Hand of Uri Guttman Did Inscribe: ... you can expand that to three statements: ... BM> my @books; ... read_file doesn't chomp lines. ...
    (comp.lang.perl.misc)
  • where have all the flowers gone ...
    ... closing as of the end of the month according to other sources ... ... "And here's hoping CWLPFB finds an angel who wants to keep it in business." ... I found that not only is CWLPFB closing, but also our local Black Oak Books branch on Broadway closed a couple weeks ago while we were gallivanting in the Venice and the Veneto, the owner of Acorn Books on Polk is going to retire and the owner of Booksmith on Haight would love to find a buyer. ...
    (misc.writing)
  • Re: Guardian 23,646 (was Re: Hard at explanation)
    ... opening lines of books we don't care so much about the closing lines! ... Not only closing lines of novels but short stories are often ...
    (rec.puzzles.crosswords)
  • Re: www set of six popular science books - closing date Friday and Saturday!
    ... They've just updated the page again - closing date 6pm Saturday for the ... next batch of books... ... > Richard Dawkins, Critical Mass by Philip Ball, Why Life Speeds Up As ... > It has just appeared, as I type, on the website - it says the closing ...
    (uk.rec.competitions)
  • Re: Guardian 23,646 (was Re: Hard at explanation)
    ... opening lines of books we don't care so much about the closing lines! ... Is it because we don't have the patience to read till the end of the book? ... Not only closing lines of novels but short stories are often unforgettable. ...
    (rec.puzzles.crosswords)