Extracting column value from perl

Hello

Kindly help me to find out the first column from first line of a flat file in perl

I/P

 
9869912|20110830|00000000000013009|130|09|10/15/2010 12:36:22|W860944|N|00
9869912|20110830|00000000000013013|130|13|10/15/2010 12:36:22|W860944|N|00
9869912|20110830|00000000000029207|292|07|05/29/2001 10:35:32|DADS_JAMESA|N|00

O/P

 
9869912

The file is pipe (|) delimeted

Thanks a lot!!

perl -e '
my $a = (split /\|/, scalar <>)[0]; 
print "$a\n"
' INPUTFILE
1 Like

--delete--

THANKS a lot Yazu

Can you please kindly let me know how to include the same in perl script

when I use the below code in perl script

 
$a = (split /\|/, scalar <>)[0] $file;

I am having the below error

 
Scalar found where operator expected at Balancing.pl line 101, near "] $file"
        (Missing operator before  $file?)
syntax error at Balancing.pl line 101, near "] $file"
Execution of Balancing.pl aborted due to compilation errors.

Thanks again

open my $fd, "<", $file;
my $a = (split /\|/, scalar <$fd>)[0];
close $fd;

Hmm... Why do you need a perl solution if you know nothing about perl? :confused:

1 Like

Thanks again

Yes rite now I know almost nothing in perl but I was asked to do it in perl only .The same I did in unix but I had to do it in perl.:wall: