Hi Joshua
Joshua Scott wrote:
> Good evening,
>
> I'm having a hard time figuring out how to make a portion of my
> script work. Basically I'd like to split a specific field and use
> the names from an array as the scalar variable names for each
> field. Here is a snip of my code:
>
> # Begin Code
use strict; # always
use warnings; # usually
> $data = "A Tab Separated Data File";
> @fields = qw/field1 field2 field3 field4 field5/;
Here you're setting @fields to the list of field names,
as you probably knew.
> (@fields) = split("\t",$data);
And here you're overwriting those field names with
their values from $data.
> Print "$field2\t";
> Print "$field3\n";
> # End Code
>
> The print statements don't output "Tab" or "Separated" like I'd
> like them to do.
Not sure what you mean here. Is this something another language
does?
> What am I doing wrong here? What is the best way
> to do this type of function?
>
> Thank you very much for any assitance you can provide.
Now that you've just added 'use strict', there's a way of
doing it by disabling it again :) But since it's frowned
upon I shan't tell you about it.
What you need is a hash. Then you can assign a 'slice' of
that hash like this
use strict;
use warnings;
my $data = "A Tab Separated Data File";
my @fieldnames = qw/field1 field2 field3 field4 field5/;
my %fields;
@[EMAIL PROTECTED] = split "\t", $data;
print $fields{field2}, "\t";
print $fields{field3}, "\n";
I hope this helps.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]