Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: printing output on text file from file - perl

by Eily (Prior)
on Oct 15, 2013 at 16:08 UTC ( #1058315=note: print w/replies, xml ) Need Help??

in reply to printing output on text file from file - perl

What you call a hash actually seems to be at least one array of arrays. And giving us a dump of your datastructure is a good idea, but it works better if you pass a reference (by adding \ in front of your variables) rather than the hash or array directly. In your case that would probably be something like :

use Data::Dumper; my @array = somecode(); print Dumper \@array;
or if you actually have a hash: print Dumper \%hash; this will ensure that your list or hash element is transmitted whole, and not flattened into several arguments.

I'd add perldsc to mtmcc's answer, to obtain a better understanding of Perl data structures. And most of times in Perl, you don't have to use indexes to iterate through an array, you can just write

for my $element (@f) { my $key = $element->[0]; ... }

Replies are listed 'Best First'.
Re^2: printing output on text file from file - perl
by Perlseeker_1 (Acolyte) on Oct 15, 2013 at 16:24 UTC
    Hi Experts,

    The input file has data, as shown below

    File - 1 - Animals A RACK 2 2 B RACK 2 2 C RACK 2 2 D RACK 2 2 FIle - 2 - Fruits A RACK 2 2 B RACK 2 2 C RACK 2 2 D RACK 2 2 File - 3 - Vegetables E TACK 4 2 F TACK 4 2 G TACK 4 2 H TACK 4 2

    The output i am expecting shown below

    Rack A 4 4 B 4 4 C 4 4 D 4 4 Subtotal16 16 Rack E 4 2 F 4 2 G 4 2 H 4 2 Subtotal16 8 Total 32 24

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058315]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-06-18 21:43 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.