CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Split function does not work with vertical bar "|"

 



kwatts59
Novice

Jan 9, 2012, 12:44 PM

Post #1 of 2 (956 views)
Split function does not work with vertical bar "|" Can't Post

The variable $tempvar1 is delimited by vertical bars "|". I am trying to split the $tempvar1 and store it into the array @var.

@var = split("\|",$tempvar1);

This does not work. It just stores each letter of $tempvar1 into each element of the @var array.

It is not practical to replace the vertical bars in $tempvar1 to another character such as a comma or tab because there are commas and tabs already in $tempvar1. Plus I am performing this on a file with 20,000 lines delimited with "|".

What do I do?


FishMonger
Veteran / Moderator

Jan 9, 2012, 2:14 PM

Post #2 of 2 (955 views)
Re: [kwatts59] Split function does not work with vertical bar "|" [In reply to] Can't Post

The first arg to split is a pattern (i.e., a regex) not a string.


Code
my @var = split(/\|/, $tempvar1);


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives