The quotemeta command will do the trick. For example:

$delimiter = '|';
@fields = qw(one two three);
$string = join $delimiter, @fields;
print join "\n", split quotemeta($delimiter), $string;

---------------FROM-------------------
David R. Miller
Manager, Computer-Based Testing
Medical Council of Canada
[EMAIL PROTECTED]
(613) 521-6012
(613) 521-9722 (fax)
-----------------------------------------

Original message:
Message: 4
From: "Tanaka, Joe" <[EMAIL PROTECTED]>
To: "'[EMAIL PROTECTED]'"
         <[EMAIL PROTECTED]>
Subject: Using vertical line as separator
Date: Tue, 2 Jan 2001 10:48:51 -0800 

I need to use the vertical line, | , ("pipe"?) as a field separator.
I am using a variable to store this separator; however, I'm having trouble
getting it to work consistently with "split" and "join" functions.

If I do:

$separator = '|';
join ($separator, @fields);     # Works
split (/$separator/, $line);    # Doesn't work (splits on null)

If I do:

$separator = '\|';
split (/$separator/, $line);    # Works
join ($separator, @fields);     # Doesn't work (of course)

Is there a way I can use the same $separator variable to work with both
"join" and "split"?

Joe Tanaka
Canon Information Systems
[EMAIL PROTECTED]
(949) 856-7356
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to