Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: print htmlcode issue

by Zaxo (Archbishop)
on Apr 19, 2002 at 10:45 UTC ( [id://160488]=note: print w/replies, xml ) Need Help??


in reply to print htmlcode issue

You need to obtain a filehandle for wherever you wish to direct the print:

open FH, "> somefilename" or die $!; print FH <<HTMLCODE; ZXCZXC zxcZXCzx zxczxczxc zxczxczxzx HTMLCODE close FH or die $!;
The handle may also be from pipe or socket.

Update: To get STDOUT assigned somewhere else, just use that as the filehandle:

open STDOUT, "> thefilepath" or die $!;
Then the default handle for print is the file.

Update: Juerd, yes, buffered writes will fail on close if the device is full or quota exceeded.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: print htmlcode issue
by Juerd (Abbot) on Apr 19, 2002 at 10:52 UTC

    close FH or die $!;

    Does close ever fail?

    To me, it seems testing the print makes more sense:

    print FH $foo or die $!;
    Which can come in handy, because filehandles are not protected by strict.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Yes,

      they can be in 5.6.1.

      use strict; my $fh; open ( $fh, "> /tmp/out") or die $!; print $fh "hallo"; close($fh); exit 0;
      Or by using the IO modules.

      Which has the advantage of autoclosing when leaving the block.
      ---------------------------
      Dr. Mark Ceulemans
      Senior Consultant
      IT Masters, Belgium

        my $fh;

        That is a lexical, not a file handle. It can contain a reference to a glob, and can _act_ like a filehandle, but it really is not. It is a real scalar, and open doesn't change that, it only assigns a reference to it.

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://160488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-16 23:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found