in reply to Get an input file and print multiple output files after performing operations on array.

#! perl -slw use strict; my @city = split ' ', <DATA>; my @temp = split ' ', <DATA>; my @note = split ' ', <DATA>; my $i = '01'; for my $city ( @city ) { for my $temp ( @temp ) { for my $note ( @note ) { open O, '>', 'out' . $i++ or die $!; print O 'city: ', $city; print O 'weather: ', $temp; print O 'recommended: ', $note; close O; } } } __DATA__ Jakarta paris delhi singapore hot cold wet yes no cannotcomment

Output:

C:\test>type out* out01 city: Jakarta weather: hot recommended: yes out02 city: Jakarta weather: hot recommended: no out03 city: Jakarta weather: hot recommended: cannotcomment out04 city: Jakarta weather: cold recommended: yes out05 city: Jakarta weather: cold recommended: no out06 city: Jakarta weather: cold recommended: cannotcomment out07 city: Jakarta weather: wet recommended: yes out08 city: Jakarta weather: wet recommended: no out09 city: Jakarta weather: wet recommended: cannotcomment out10 city: paris weather: hot recommended: yes out11 city: paris weather: hot recommended: no out12 city: paris weather: hot recommended: cannotcomment out13 city: paris weather: cold recommended: yes out14 city: paris weather: cold recommended: no out15 city: paris weather: cold recommended: cannotcomment out16 city: paris weather: wet recommended: yes out17 city: paris weather: wet recommended: no out18 city: paris weather: wet recommended: cannotcomment out19 city: delhi weather: hot recommended: yes out20 city: delhi weather: hot recommended: no out21 city: delhi weather: hot recommended: cannotcomment out22 city: delhi weather: cold recommended: yes out23 city: delhi weather: cold recommended: no out24 city: delhi weather: cold recommended: cannotcomment out25 city: delhi weather: wet recommended: yes out26 city: delhi weather: wet recommended: no out27 city: delhi weather: wet recommended: cannotcomment out28 city: singapore weather: hot recommended: yes out29 city: singapore weather: hot recommended: no out30 city: singapore weather: hot recommended: cannotcomment out31 city: singapore weather: cold recommended: yes out32 city: singapore weather: cold recommended: no out33 city: singapore weather: cold recommended: cannotcomment out34 city: singapore weather: wet recommended: yes out35 city: singapore weather: wet recommended: no out36 city: singapore weather: wet recommended: cannotcomment

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Get an input file and print multiple output files after performing operations on array.
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Get an input file and print multiple output files after performing operations on array.
by Ganesh Bharadwaj1 (Sexton) on Dec 29, 2015 at 06:36 UTC
    thank you soo much. That works like a charm :)