473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to cut fields with pipe separator in a file

Dear friends,


Inside the perl script i will opening the file which is having three columns with pipe separated.

a|1|abc
b|2|bcd
c|3|one

Now i want to read the first record (a|1|abc), split the record and assign the each column values to some variable.
Can anybody help me in this ?

Thanks in advance
Jayakumar
Jun 22 '07 #1
3 2489
prn
254 Expert 100+
Hi jayakumarrt,

See the documentation on the split function for how to do this.

Best Regards,
Paul
Jun 22 '07 #2
miller
1,089 Expert 1GB
Greetings jayakumarrt,

As Paul said, simply use the split function. Just note that the pipe | is a regex meta character and therefore must be escaped to use properly.

Expand|Select|Wrap|Line Numbers
  1. my $s = 'a|1|abc';
  2. my @a = split '\|', $s;
  3. print join ',', @a; # Outputs a,1,abc
  4.  
- Miller
Jun 22 '07 #3
Thanks Miller and Paul
Jun 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jenny | last post by:
Hi, I have a java socket program running on AIX 4.3.3.0 platform. It opens a socket and sends data to our customer over a leased fractional T1 line. The line is always connected. However,...
1
by: Brad Murdoch | last post by:
im trying to run the select.selct() on a unix pipe, my expectation is that it will block untill there is something there to read, then continue. It seems to do this untill the pipe is written to...
5
by: richard | last post by:
I have a simple test to pass information from a client to a server using named pipe. what I really want is: when I type a line on the client, the server will output the line immediately. but to my...
7
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in...
4
by: bill | last post by:
I am confused by the behavior of the following code. The function copy() takes two FILE *'s and copies the data from one to the other. In the main routine, I create a pipe and copy stdin to the...
1
by: Sanchita Chatterjee | last post by:
I want a script which should have a filepicker as an input,from which a file has to be selected. the file contains text(fields) delimited by pipe symbol. After the file is selected, each of the...
11
by: 7stud | last post by:
Hi, Can someone explain what a broken pipe is? The following produces a broken pipe error: ---------- import subprocess as sub p = sub.Popen(, stdin=sub.PIPE, stdout=sub.PIPE)
3
by: Jeremy Sanders | last post by:
Hi - I have some code which works under linux. It starts a remote python process using subprocess and communicates to it via a pipe created by os.pipe. As far as I understand, child processes...
0
by: ndedhia1 | last post by:
I am having trouble loading a property file and keep getting this error when running my shell script that loads and runs my jar files, etc: no property file loaded, using defaults......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.