Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: printing output on text file from file - perl

by Eily (Deacon)
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]; ... }
.


Comment on Re: printing output on text file from file - perl
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058315]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-12-26 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls