[Israel.pm] convert perl string to file handle

Offer Kaye oferk at oren.co.il
Sun Jun 6 07:28:43 PDT 2004

> hi
> is there a efficinet way to convert perl string to file handle?
> i used something like:
> $buffer="....."
> open IN,qq{echo $buffer|};
> print <IN>;
> but is there a better way?
> thank
> itamar

Hi Itamar,
What exactly are you trying to do?
Your above code just prints the string in $buffer to stdout. Did you perhaps
mean to open the file whose name is in $buffer and print its contents? For
that just do:

   my $buffer = "input_file_name";
   open(IN,$buffer) or die "Couldn't open $buffer for reading: $!\n";
   print <IN>;
   close(IN) or die "Couldn't close $buffer after reading: $!\n";

of course you can also you the Unix "cat" command for this:

   my $buffer = "input_file_name";
   print `cat $buffer`;

If this is not what you wanted to do please elaborate...
Offer Kaye

More information about the Perl mailing list