Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: printing output on text file from file - perl

by Eily (Vicar)
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2016-10-21 11:31 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (288 votes). Check out past polls.