[Israel.pm] convert perl string to file handle

Itamar Elem elem at compugen.co.il
Sun Jun 6 06:39:26 PDT 2004

hi ofer

i just give a simple example.
the real problem was that i use external module(not my) and one of it methode ask fro file handle as argument.
but i had the data in variable .sow  there was need to convert it

-----Original Message-----
From: Offer Kaye [mailto:oferk at oren.co.il]
Sent: Sunday, June 06, 2004 5:29 PM
To: Perl in Israel
Subject: RE: [Israel.pm] convert perl string to file handle

> 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

Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list