Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

perl + split + pipeline

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 :

abcd|efd|adfa|adfASF|AsfF|asfA|fasFa|afasdfA|fAF|asfASF|asfasF|asf|adfasF|adfda

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

cheers
kamaraj.s


$LOGFILE = $ARGV[0];
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) {
		 $count++;
		 print " $count :  $val\n";
		 }
}

Open in new window

0
Kamaraj Subramanian
Asked:
Kamaraj Subramanian
  • 2
1 Solution
 
ozoCommented:
split ('\|',$line)
0
 
ozoCommented:
perldoc perlre
       Metacharacters

       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
0
 
Kamaraj SubramanianApplication Support AnalystAuthor Commented:
When i post this quesion, i think about you only (ozo). B'cos you are master in perl.

thanks for your solution
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now