Help on Perl Split Function

V

Vishal

Her is a simple PERL file: spl.pl

$arg=shift ;
@in_arr= split /,/, $arg ;
print("\n in_arr 0 is $in_arr[0]");
print("\n in_arr 1 is $in_arr[1]");
print("\n in_arr 2 is $in_arr[2]");
print("\n in_arr 3 is $in_arr[3]");
print("\n in_arr 4 is $in_arr[4] \n");

When I execute the above perl file; it's give the following output :

perl spl.pl a,abc,"def,ijhk",lmn

in_arr 0 is a
in_arr 1 is abc
in_arr 2 is def
in_arr 3 is ijhk
in_arr 4 is lmn



But I want the output as:

in_arr 0 is a
in_arr 1 is abc
in_arr 2 is def,ijhk
in_arr 3 is lmn
in_arr 4 is

That is: the split function should not search in the Pattern which are
present in the quotes ("").

If any of your friends knows well about this "PERL/split"; pl pass on
this junk code to him for immediate help. Or if you know any Perl guy
then pass me his/her mail ID.


Please reply ASAP.

Thanks & Regards,
Vishal Anand
 
A

A. Sinan Unur

By the time perl sees the command line argument, the shell has already
removed the double quote marks.

Thank you for catching that. While this is shell-specific, it is important
to note that without this precaution the FAQ answer would not do one any
good.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with code plsss 0
Please help 2
Python battle game help 2
Minimum Total Difficulty 0
Need help with this script 4
Code help please 4
Function is not worked in C 2
Help in this program. 2

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top