Tanaka, Joe wrote, on Tuesday, January 02, 2001 13:49
: 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"?

Yes: use the meta-quoting function of regexp.

$separator = '|';
join ($separator, @fields);
split (/\Q$separator\E/, $line);

The \E isn't really necessary as the regexp ends there anyway, but
it makes me feel good to balance the \Q.

Joe

==============================================================
          Joseph P. Discenza, Sr. Programmer/Analyst
               mailto:[EMAIL PROTECTED]
 
          Carleton Inc.   http://www.carletoninc.com
          219.243.6040 ext. 300    fax: 219.243.6060
 
Providing Financial Solutions and Compliance for over 30 Years

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to