develooper Front page | perl.beginners | Postings from April 2002

Fwd: problems with split

From:
drieux
Date:
April 25, 2002 10:37
Subject:
Fwd: problems with split
Message ID:
FBAECBF4-5872-11D6-AEFB-0030654D3CAE@wetware.com

I think Stefan provided an Elegant query - since he
had a good sample of data, and a specific test case
of code for use to look at.....

>> while ($line = <FILEONE>) {
>> 	($nodeid, $nameid, $type, $longitude, $latitude, $altitude) = split
>> ("|", $line);

that regular expression interpolates to

/''|''/

which if you had done by hand with say

	split(/''|''/, $line); # with -w and strict

would have noted the use of unitialized value in concatination....

the '|' also gets to the same logical space,
hence what you have is a

	split('',$line)

and you wind up catching the fourth and fifth characters in
the line....

>> 	print FILETWO "P|",$longitude, "|",$latitude,"||";
>> }
>
> I presume you wanted output like:
>
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
> P|7684940|47534900||
>
> hence wanted to be reminded of { drieux Gets Orthodox }
>
> 	a) use -w and strict
> 	b) "|" is a reserved token
> 	c) "foo" - allows for interpolation of foo between the quotes
>
> hence
> 	split(/\|/, $line);	# my prefered
> or
> 	split('\|', $line);
>
> depending upon your orthodoxy....
>
>
> while (my $line = <FILEONE>) {
> 	my ($nodeid, $nameid, $type, $longitude, $latitude, $altitude) = split
> ("|", $line);
> 	print FILETWO "P|",$longitude, "|",$latitude,"||";
> }

ciao
drieux

---
>




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About