Friday, November 9, 2012
3:20 AM

Perl Script: Input Line/record Separator examples

The input line/record separator ($/) is set to newline by default. Works like awk's RS variable, including treating blank lines as delimiters if set to the null string. You may set it to a multi-character string to match a multi-character delimiter, or can be set to the numeric value.

Below is simple perl script which demonstrate the usage of input record separator, feel free to copy and use this script.

Input File: cat testfile.txt
google:yahoo:microsoft:apple:oracle:hp:dell:toshiba:sun:redhat

Source: cat separator.pl
#!/usr/bin/perl

$FILE = "testfile.txt";
open (INFILE, $FILE) or die ("Not able to open the file");
$/ = ":";
while ($record = <INFILE>) {
        print "$record \n";
}

Continue Reading...

0 comments:

Post a Comment