__DATA__ - Data section

What is written below __DATA__ is called the data section. The data section allows you to write the contents of the input file in your program.


# Program

__DATA__
kimoto, 39
tanaka, 29

DATA file handle

The content described in the data section can be read using a special file handle called DATA .


while (my $line = <DATA>) {
  print "$line";
}

__DATA__
kimoto, 39
tanaka, 29

while statement is used to get the content described in the data section line by line.

Copy and paste the text data you want to edit into the data section, read it with the DATA file handle, and edit it.

__DATA__ and DATA file handle example

This is an example example of __DATA__ and DATA file handles.

use strict;
use warnings;

# Change comma to tab
while (my $line = <DATA>) {
  chomp $line;
  my @items = split(/,/, $line);
  
  print join("\t", @items) . "\n";
}

__DATA__
kimoto, 39
tanaka, 29

Related Informatrion