Perl Split Command usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Split Command usage
# 1  
Old 12-17-2006
Perl Split Command usage

Hi,

I am trying to use the split commad to seperate string reading from file. but it dosent give me a correct result. can some body tell me what is the wrong in following scritp.

Code:
#!/usr/bin/perl -w                                         
#use CGI qw(:standard);                                    
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);      
use strict;                                                
                                                           
open(FH,"bh_file.txt");                                    
                                                           
while (my $line = <FH>) {                                  
my @hash_array = split(/|/, $line);                        
print $hash_array[1] ;                                     
}         

close(FH);

Input file format as follows,

Code:
Banikoara_A1|0|2006-12-14 19:00|duration: 120 minute(s)| 0.24 0.13
Banikoara_B1|1|2006-12-14 19:00|duration: 120 minute(s)| 0.08 0.08


my expected output should be,

Banikoara_A1
Banikoara_B1

(print the 1st column)

current out put as follows,

aa
# 2  
Old 12-17-2006
you can try

Code:
...
split(/\|/,$line);
...

# 3  
Old 12-17-2006
... and the index of the first element of an array is 0, not 1.

Unless you have

Code:
$[ = 1;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl qr function usage

I'm not sure why I'm having so much trouble with this. I think I'm really not understanding how this works. I'm trying to store a regex in a variable for use later in a script. Can someone tell me why this doesn't match??? #!/usr/bin/perl # # # $ticket=1212; my $rx_ticket =... (1 Reply)
Discussion started by: timj123
1 Replies

2. Shell Programming and Scripting

Usage of shell variable in perl command

Hi, I have a shell script, In which i have variable "var1" and some perl command inside shell script. export var1='coep -n rst-a2p-hinje.vci.all.com -c' perl -pi -e 's/^/coep -n rst-a2p-hinje.vci.all.com -c /' command.txt currently I am adding value of var1 in command.txt file by... (2 Replies)
Discussion started by: rakeshtomar82
2 Replies

3. Shell Programming and Scripting

Usage of $$ and @_ in perl

Hi I have some doubts with below perl script sub program . In the below code what are below lines do ? 1. ($user, $server, $os, $version, $ref_path, $ref_line, $ref_ftp) = @_; 2. if ( -e "/usr/kerberos/bin/krsh" ) 3. $$ref_path = "/usr/kerberos/bin" unless ($$ref_path);why we are... (1 Reply)
Discussion started by: ptappeta
1 Replies

4. Shell Programming and Scripting

using awk in perl with split command

Hi, I have an array with following data. First field shows the owner and second is unique name. Now i have to pic the latest value with respect to the date in case of duplicate. like "def" is from two owners "rahul/vineet", now i want the latest from the two and the owner name also for all the... (9 Replies)
Discussion started by: vineet.dhingra
9 Replies

5. Shell Programming and Scripting

usage of AWK command under perl script

i have two files as shown below t1.txt: argument1 argu2 argu37 t2.txt: 22 33 44 i want o/p as argument1 22 argu2 33 argu37 44 i am trying to merge two file under perl script using following system("paste t1.txt t2.txt | awk... (3 Replies)
Discussion started by: roopa
3 Replies

6. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

9. Shell Programming and Scripting

Use split function in perl

Hello, if i have file like this: 010000890306932455804 05306977653873 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC30693599000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011302942311 010000890306946317387 05306977313623 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000... (5 Replies)
Discussion started by: chriss_58
5 Replies

10. UNIX for Advanced & Expert Users

Split Command in Perl

Hi, I have to split a line of the form 1232423#asdf#124324#54534#dcfg#wert#rrftt#4567 into an array in perl. I am using @fields; @fields=split('#',$line); if($fields eq "1") But this is not working. By using the syntax, the statements in "if" are never executed. Please help.... (9 Replies)
Discussion started by: rochitsharma
9 Replies
Login or Register to Ask a Question