perl + split + pipeline

Posted on 2008-11-07
Last Modified: 2013-12-25
I am using the following program to get the values from the pipeline separated file

But it is not working as i expected.

input file contains :


i need a output like this :

1 : abcd
2 : efd
3 : adfa

if i replace the | (pipe symbol) with , (comma) then it works fine.

please correct the program

thanks in advance



open(LOGFILE) or die("Could not open log file.");

foreach $line (<LOGFILE>) {

    chomp($line);              # remove the newline from $line.

    # do line-by-line processing.

	 @values = split ('|',$line);

	 $count =0;

	 foreach my $val (@values) {


		 print " $count :  $val\n";



Open in new window

Question by:itkamaraj
    LVL 84

    Accepted Solution

    split ('\|',$line)
    LVL 84

    Expert Comment

    perldoc perlre

           The patterns used in Perl pattern matching evolved from the ones
           supplied in the Version 8 regex routines.  (The routines are derived
           (distantly) from Henry Spencer's freely redistributable
           reimplementation of the V8 routines.)  See "Version 8 Regular
           Expressions" for details.

           In particular the following metacharacters have their standard
           egrep-ish meanings:

               \   Quote the next metacharacter
               ^   Match the beginning of the line
               .   Match any character (except newline)
               $   Match the end of the line (or before newline at the end)
               |   Alternation
               ()  Grouping
               []  Character class
    LVL 23

    Author Closing Comment

    When i post this quesion, i think about you only (ozo). B'cos you are master in perl.

    thanks for your solution

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
    This article will show, step by step, how to integrate R code into a R Sweave document
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now