filehandle to variable problem

Discussion in 'Perl Misc' started by mathias, Jul 15, 2003.

  1. mathias

    mathias Guest

    mathias, Jul 15, 2003
    #1
    1. Advertising

  2. mathias

    mathias Guest

    Greg Bacon wrote:

    > : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
    >
    > It's a filehandle. Why do you care what it looks like when you print
    > its internal representation? What did you expect to happen?
    >
    > Greg

    well i was waiting for bla instead of any of the strings i had.
    can you give me a way then to get "bla" from this filehandle ?

    thank you
    Mathias
    mathias, Jul 15, 2003
    #2
    1. Advertising

  3. mathias

    Jay Tilton Guest

    mathias <> wrote:

    : Greg Bacon wrote:
    :
    : > : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
    : >
    : > It's a filehandle. Why do you care what it looks like when you print
    : > its internal representation? What did you expect to happen?
    : >
    : > Greg

    : well i was waiting for bla instead of any of the strings i had.
    : can you give me a way then to get "bla" from this filehandle ?

    Your code is short enough that including it in the article is
    preferable to making readers go out to the web to see it.

    [grabbed from http://www.tiasarea.org/perl.html]
    #!/usr/bin/perl -w
    use strict;

    sub runme {
    my $fh=shift;
    print $fh "bla\n"; }

    my $var;
    open FH, '>', \$var;
    runme(\*FH);
    $var = *FH;
    close FH;

    print "var: \n";
    print ">".$var."<\n";

    the output from this script is:
    var:
    >*main::FH<


    In Perl 5.8.0, "open FH, '>', \$var" will cause stuff printed to FH to
    go into $var. Cut out the "$var = *FH;" line and look in $var for
    your 'bla'.

    In an older Perl, that form of open() does not have the same behavior.
    It just ends up stringifying the scalar reference, creating a file
    named like "SCALAR(0x1a653b4)".
    Jay Tilton, Jul 15, 2003
    #3
  4. mathias

    mathias Guest

    Jay Tilton wrote:
    > mathias <> wrote:
    >
    > : Greg Bacon wrote:
    > :
    > : > : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
    > : >
    > : > It's a filehandle. Why do you care what it looks like when you print
    > : > its internal representation? What did you expect to happen?
    > : >
    > : > Greg
    >
    > : well i was waiting for bla instead of any of the strings i had.
    > : can you give me a way then to get "bla" from this filehandle ?
    >
    > Your code is short enough that including it in the article is
    > preferable to making readers go out to the web to see it.
    >
    > [grabbed from http://www.tiasarea.org/perl.html]
    > #!/usr/bin/perl -w
    > use strict;
    >
    > sub runme {
    > my $fh=shift;
    > print $fh "bla\n"; }
    >
    > my $var;
    > open FH, '>', \$var;
    > runme(\*FH);
    > $var = *FH;
    > close FH;
    >
    > print "var: \n";
    > print ">".$var."<\n";
    >
    > the output from this script is:
    > var:
    > >*main::FH<

    >
    > In Perl 5.8.0, "open FH, '>', \$var" will cause stuff printed to FH to
    > go into $var. Cut out the "$var = *FH;" line and look in $var for
    > your 'bla'.
    >
    > In an older Perl, that form of open() does not have the same behavior.
    > It just ends up stringifying the scalar reference, creating a file
    > named like "SCALAR(0x1a653b4)".
    >

    thank you for the help
    i finally solved it out

    Mathias
    mathias, Jul 17, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wijaya Edward
    Replies:
    1
    Views:
    237
    Marc 'BlackJack' Rintsch
    Oct 26, 2006
  2. Replies:
    2
    Views:
    84
  3. Replies:
    4
    Views:
    86
    Ted Zlatanov
    Jun 2, 2006
  4. Filehandle Pipe Problem?

    , Apr 20, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    99
  5. Sniff
    Replies:
    6
    Views:
    135
    Uri Guttman
    Dec 21, 2007
Loading...

Share This Page