Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I have to ponder this for a while, and my time for perl is limited at the moment. But for the time being I will like to go into more detail about the filehandle stuff. I read CGI, and I understand the problem, because returns a variable containing both name and filehandle. I would guess that a check for reference should avoid this problem.

My assumption about the workings of $fh='INPUT'; join '',<$fh>; are based on perldoc:perlop, saying 'If the string inside the angle brackets is a reference to a scalar variable (e.g., <$foo>), then that variable contains the name of the filehandle to input from, or a reference to the same.'.

I understand the argument about the pipe and stuff, and I think a open.. "$fh" || open .. "<$fh" should do the trick here. I don't have IO::Scalar here, I'll ponder that later.

You worry about a trying open and silently failing. Well, I tried it, and the code simply returns the name if the open failed (and there is nothing to split on) as the first element. That leaves room for a check.

Furthermore, the code returns a prepared string as well, if reading as a filehandle fails. I quickly glanced at IO::Scalar, and I think the ref check should allow that as well. I think the following code should work.

sub _text{ my $fh = shift; unless (defined($fh)) { $fh = \*STDIN; } if ( (! ref $fh) && ((open INPUT, "$fh") || open INPUT, "<$fh" )) +{ $fh = join '', <INPUT>; close INPUT; } no strict 'refs'; (join '', <$fh>) || $fh; }


I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)

In reply to Re: Re (tilly) 3 (comments): Supersplit by jeroenes
in thread Supersplit by jeroenes

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-07-04 21:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found