Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:23:44+00:00 2026-05-26T11:23:44+00:00

In trying to answer an old question in a clever way, I was going

  • 0

In trying to answer an old question in a clever way, I was going to attempt this, not knowing if it would succeed:

#!/usr/bin/env perl

use strict;
use warnings;

use Tie::File;
tie( my @data, 'Tie::File', \*DATA ) or die "Cannot tie DATA";

foreach ( @data ) {
    print;
}

foreach ( @data ) {
    print scalar reverse;
}


__DATA__
one
two
three
four
five
six

I expected it to either work, or die; what I got was unexpected:

#!/usr/bin/env perluse strict;use warnings;use Tie::File;tie( my @data, 'Tie::File', \*DATA ) or die "Cannot tie DATA";foreach ( @data ) {    print;}foreach ( @data ) {    print scalar reverse;}__DATA__onetwothreefourfivesixlrep vne/nib/rsu/!#;tcirts esu;sgninraw esu;eliF::eiT esu;"ATAD eit tonnaC" eid ro ) ATAD*\ ,'eliF::eiT' ,atad@ ym (eit{ ) atad@ ( hcaerof;tnirp    }{ ) atad@ ( hcaerof;esrever ralacs tnirp    }__ATAD__enoowteerhtruofevifxis

How on earth did attempting to tie __DATA__ into Tie::File did it tie the script, and chomp it too?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:23:44+00:00Added an answer on May 26, 2026 at 11:23 am

    The DATA filehandle is just an open filehandle to the file that refers to it. It has some additional magic that the first time it is read from, it seeks to the first byte after the __DATA__ or __END__ token in your program, giving you the behavior you expect.

    When you tie *DATA, you are getting in the way of the first-read magic, and getting a handle to your source file positioned at the top of the file.

    I suspect that if you call tell DATA first (or maybe seek DATA,0,1) before you tie it, it will be in the correct position and “work” like you expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to answer this question I found that the code int* p =
I have looked around on the Internet trying to answer this question. It seems
This question is a result of what i noticed while trying to answer another
(Came up with this question in the course of trying to answer this other
I feel stupid asking this question, but I can not find a clear answer
I tried to find a question that would answer to this question but wasn't
While trying to answer a question in the vicinity ' Unit Testing WPF Bindings
I was trying to answer the question mentioned here by passing the reference to
I'm trying to answer the following question out of personal interest: What is the
I am trying to get a definitive answer regarding the way COM behaves on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.