On Wed, 28 Aug 2002, David Samuelsson (PAC) wrote:
I don't think you have enabled warnings or use strict, add them and save
on your debugging time.
> I have gotten 2 values, they "belong" to eachother but i want to use them later. So
>i pushed em into an array for use later like this:
>
> $text = "$first $second\n";
> push (@array,$text);
You are joining $first and $second then pushing them into an array only to
split them later. Any problems pushing them individually into the array.
>
> the array works and if i do an foreach loop inside the array later i get the 2
>values.
>
> saying "$first $second"
>
> ok, now i want to split this value so i get the first value separeted from the
>second again, and into separet variables.
> All this due to i had to sort stuff first.
>
> foreach $line (@array)
> {
> print "$line\n"; # prints "$first $second";
> $line =~ split(/\w/,$line);
1) '=~' binds a scalar expression to a pattern match, this is not needed here
If you had enabled warnings this would have given you a message
2) When you say $line = split (...), $line will contain the number of
elements in the array returned by split.
3) I guess you should be splitting on \s+ not \w. \w matches a word
character, for ascii it is [a-zA-Z0-9_] (varies depending on the locale).
This line should be written as
($first, $second) = split (/\s+/, $line);
> print "seperated got $1 and $2\n";
$1 and $2 are used to capture parts of a pattern match, you are splitting
here. With warnings enabled this too might have given you a message, i.e.
if $1 and $2 do not contain values from a previous capture in a pattern
match.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]