Re: Fixed Length Text Extract, Write to Excel
From: Rob Dixon (rob_at_dixon.port995.com)
Date: 01/07/04
- Next message: Drieux: "Re: What is the source of my input, file or STDIN?"
- Previous message: William Martell: "Re: Fixed Length Text Extract, Write to Excel"
- In reply to: William Martell: "Fixed Length Text Extract, Write to Excel"
- Next in thread: Wiggins D Anconia: "Re: Fixed Length Text Extract, Write to Excel"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Wed, 7 Jan 2004 17:55:16 -0000
William Martell wrote:
>
> I am trying to work with the code I have to extract fields from a text file
> report, and write the values into excel.
>
> I am having trouble.
>
> When I get to push @order_detail, %item
Looking at your code, you mean
push @order_detail, \%item
> I understand that this is pushing an associative array onto a list. (array
> of hashes)
>
> I am trying to write code that will open a new work*** in excel and print
> the values of %item onto a row. When Perl encounters a certain key
> (cust_number), I would like it to start a new row.
>
> I have tried keys(), values(), pop() but I can't get it right. I think some
> of my trouble is b/c of the reference \%item. When I remove the reference
> backslash operator like this %item and type print. Perl returns with the
> contents in scalar.
>
> So. My main question is how do I access the values and keys of %item in
> @order_detail???
Hi William.
You're building an array of hash references. To access a hash values
from a given array element, write
my $cust_number = $order_detail[0]{cust_number}
To do the same for each detail record, do this
foreach my $detail (@order_detail) {
my $cust_number = $detail->{cust_number};
}
The value returned will be 'undef' if there is no such element for a given
order detail record.
I hope this helps.
Rob
- Next message: Drieux: "Re: What is the source of my input, file or STDIN?"
- Previous message: William Martell: "Re: Fixed Length Text Extract, Write to Excel"
- In reply to: William Martell: "Fixed Length Text Extract, Write to Excel"
- Next in thread: Wiggins D Anconia: "Re: Fixed Length Text Extract, Write to Excel"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]