in reply to How to read contents of a file without opening it and print the contents

A good point was brought up in the CB... perhaps this question is being asked because the OP tried to open a file and it failed.

If that is the case, use

open my $fh, '<', $name or die "The open failed because of '$!'\n";

... then fix the problem that is reported.

  • Comment on Re: How to read contents of a file without opening it and print the contents
  • Download Code

Replies are listed 'Best First'.
Re^2: How to read contents of a file without opening it and print the contents
by Anonymous Monk on Jan 28, 2015 at 22:48 UTC
    I am attempting to fulfill an assignment that involves searching the file using regular expressions. "write a script called xxx.pl. This script should read the contents of /httpd/conf/httpd.conf without opening it and print out every line that contains /cgi-bin." So How does one "read a file without opening it?"
      It took you 4 years to return to this thread? Wow!

      Could it be that your assignment is rather HTTP than regex related?

      but even then .... a very stupid question.

      update

      maybe someone thought that using shell redirections do not open: $content=`<filename` ?

      update

      or $content=`cat filename` ?

      but even then .... a very stupid question!

      Cheers Rolf

      PS: Je suis Charlie!