From: Thomas Andersson on
As the topic says. I ahve a settings file where each line contains 2 numbers
of varying length and I want to extract each number and assign to a
variable, how would I go about that?


From: Thomas Andersson on
Thomas Andersson wrote:
> As the topic says. I ahve a settings file where each line contains 2
> numbers of varying length and I want to extract each number and
> assign to a variable, how would I go about that?

would this be a valid way to do it and would I need to chomp the second
value?

open my $settings, qq<, $settings or die qqCould not open $settings: $!\n;
my $line = <$settings>;
my $cpid = =~/+\t/;
my $lproc = =~\t+\s;

So any number 1-inf up to first tabe is variable 1 and any number 1-inf
between tab and endline is variable 2?


From: Sherm Pendley on
"Thomas Andersson" <thomas(a)tifozi.net> writes:

> As the topic says

Please write your message in your message. Have you read the posting
guidelines that appear here frequently?

> I ahve a [tab delimited] settings file where each line contains 2
> numbers of varying length and I want to extract each number and
> assign to a variable, how would I go about that?

Have a look at the split() function. Quick example:

#!/usr/bin/perl
use warnings;
use strict;

while(<>) {
chomp;
my ($foo, $bar) = split /\t/;
}

sherm--

--
Sherm Pendley <www.shermpendley.com>
<www.camelbones.org>
Cocoa Developer
From: Justin C on
On 2010-08-03, Thomas Andersson <thomas(a)tifozi.net> wrote:
> As the topic says. I ahve a settings file where each line contains 2 numbers
> of varying length and I want to extract each number and assign to a
> variable, how would I go about that?

TMTOWTDI, here's one, it may not be a good one.

#!/usr/bin/perl

use strict;
use warnings;

while (<DATA>) {
chomp;
my ($x, $y) = split /\t/, $_;
printf("%s + %s = %s\n", $x, $y, $x + $y);
}

__DATA__
1 9999999999
20 999999999
300 99999999
4004 99999999999
50505 9
660066 0.00000001
7070707 999999.999
88088088 .99999999
999999999 1
9999999991 9999999999

How long are you numbers? Are they formatted?

Justin.

--
Justin C, by the sea.
From: Tad McClellan on
Thomas Andersson <thomas(a)tifozi.net> wrote:

> would this be a valid way to do it


> open my $settings, qq<, $settings or die qqCould not open $settings: $!\n;


That is not a valid way because it is not even a valid Perl program.

You cannot just make stuff up and expect the program to work, you
must understand what everything you write does.

If you are getting syntax errors and do not know how to fix the
syntax errors, then ask a question about the syntax errors.

If you hope to use the qq operator, then you should perhaps consider
reading the docs for the qq operator. See the "Quote and Quote-like
Operators" section in:

perldoc perlop


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.