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: Intermediate:
Use of uninitialized value within @columns in join or string

 



fgstat
New User

Jan 5, 2012, 11:11 PM

Post #1 of 2 (683 views)
Use of uninitialized value within @columns in join or string Can't Post

I'm trying to null the 4th column this way:


Code
while(<INFILE>) 
{
my @columns = split('0x7c', $_);
$columns[3] = "";
my $outline = join('0x7c', @columns);

print (OUTFILE $outline);
}


But I got the error:
"Use of uninitialized value within @columns in join or string" for the join function.
Instead of the desired result I got the same text file plus some extra characters after the EOF
Is there a correct way to achieve this without the warning and the unexpected result?


BillKSmith
Veteran

Jan 6, 2012, 5:38 AM

Post #2 of 2 (673 views)
Re: [fgstat] Use of uninitialized value within @columns in join or string [In reply to] Can't Post

Your problem has nothing to do with the fourth column. The first argument of split is a "PATTERN" (regular expression). In the syntax of regular expressions, the pipe (|) character has a special meaning. It must be escaped to represent itself. The first argument of join is a string. In a single quoted string almost all characters represent themselves.


Code
while(<INFILE>)  
{
my @columns = split(/\|/, $_);
$columns[3] = "";
my $outline = join('|', @columns);

print (OUTFILE $outline);
}

It is possible to represent special characters in a string and/or pattern with a hex escape sequence.This is not at all the same thing as the numeric litteral which you attempted to use. Refer to the syntax of strings and regular expressions.
Good Luck,
Bill

 
 


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

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