PerlIO omission

Discussion in 'Perl Misc' started by Bo Lindbergh, Jun 8, 2006.

  1. Bo Lindbergh

    Bo Lindbergh Guest

    Why is there no truncate operation in PerlIO?

    /Bo Lindbergh
    Bo Lindbergh, Jun 8, 2006
    #1
    1. Advertising

  2. Bo Lindbergh

    Ben Morrow Guest

    Quoth Bo Lindbergh <>:
    > Why is there no truncate operation in PerlIO?


    Err...cos PerlIO's broken? :)
    There seems to be some sort of abstraction of the operation, but systems
    with ftruncate(2) always end up calling it on fileno($FH). :(

    Ben

    --
    If you put all the prophets, | You'd have so much more reason
    Mystics and saints | Than ever was born
    In one room together, | Out of all of the conflicts of time.
    The Levellers, 'Believers'
    Ben Morrow, Jun 8, 2006
    #2
    1. Advertising

  3. Bo Lindbergh wrote:
    > Why is there no truncate operation in PerlIO?
    >


    There is though: perldoc -f truncate

    --
    Charles DeRykus
    Charles DeRykus, Jun 8, 2006
    #3
  4. Charles DeRykus wrote:
    > Bo Lindbergh wrote:
    >> Why is there no truncate operation in PerlIO?
    >>

    >
    > There is though: perldoc -f truncate
    >


    I think there is an emulation even on OS's
    which don't have ftruncate(2).

    On Win32 for instance, truncate still succeeds:

    C:\temp>perl -V:d_truncate
    d_truncate='undef';

    C:\temp>perl
    open my $fh, "+<", "foo" or die "open: $!";
    truncate $fh,0 or die "truncate failed";
    ^D


    --
    Charles DeRykus
    Charles DeRykus, Jun 8, 2006
    #4
  5. Bo Lindbergh

    Bo Lindbergh Guest

    In article <>,
    Charles DeRykus <> wrote:

    > Bo Lindbergh wrote:
    > > Why is there no truncate operation in PerlIO?
    > >

    >
    > There is though: perldoc -f truncate


    "PerlIO", not "Perl I/O". There's a difference.


    /Bo Lindbergh
    Bo Lindbergh, Jun 8, 2006
    #5
  6. Bo Lindbergh

    Bo Lindbergh Guest

    In article <>,
    Ben Morrow <> wrote:

    > Quoth Bo Lindbergh <>:
    > > Why is there no truncate operation in PerlIO?

    >
    > Err...cos PerlIO's broken? :)
    > There seems to be some sort of abstraction of the operation, but systems
    > with ftruncate(2) always end up calling it on fileno($FH). :(


    And so truncate fails with EBADF in the example below.

    {
    open(my $fh,">",\my $buffer)
    or die "open: $!";
    print $fh "Hello, World!\n"
    or die "print: $!";
    truncate($fh,5)
    or die "truncate: $!";
    }

    This is sad, because truncating a Perl scalar is a perfectly
    reasonable thing to want to do.


    /Bo Lindbergh
    Bo Lindbergh, Jun 8, 2006
    #6
  7. Bo Lindbergh wrote:
    > In article <>,
    > Charles DeRykus <> wrote:
    >
    >> Bo Lindbergh wrote:
    >>> Why is there no truncate operation in PerlIO?
    >>>

    >> There is though: perldoc -f truncate

    >
    > "PerlIO", not "Perl I/O". There's a difference.
    >


    Oops, yes. That's "big boy" stuff...

    --
    Charles DeRykus
    Charles DeRykus, Jun 8, 2006
    #7
    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. Ray Gardener
    Replies:
    5
    Views:
    310
    Jeff Schwab
    Dec 27, 2003
  2. Shoban Jeyaraj

    STL: malloc_alloc - omission of types

    Shoban Jeyaraj, Feb 17, 2004, in forum: C++
    Replies:
    2
    Views:
    2,316
    Alberto Barbati
    Feb 17, 2004
  3. Champak Ch
    Replies:
    11
    Views:
    289
    Champak Ch
    Mar 9, 2010
  4. gordon

    perlio problem? redhat 9, perl 5.8.0

    gordon, Jun 24, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    124
    gordon
    Jun 27, 2003
  5. Dave
    Replies:
    0
    Views:
    140
Loading...

Share This Page