Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How can i read the lines and store them in an array like following fashion?

by reneeb (Chaplain)
on Oct 19, 2006 at 10:17 UTC ( #579318=note: print w/ replies, xml ) Need Help??


in reply to How can i read the lines and store them in an array like following fashion?

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array; { local $/ = "\nITEM"; open my $fh,'<','./item.txt' or die $!; while(my $entry = <$fh>){ chomp $entry; $entry = 'ITEM'.$entry unless $entry =~ /^ITEM/; push @array,[split /\n/,$entry]; } close $fh; } print Dumper(\@array);


Comment on Re: How can i read the lines and store them in an array like following fashion?
Download Code
Replies are listed 'Best First'.
Re^2: How can i read the lines and store them in an array like following fashion?
by sanjay nayak (Sexton) on Oct 20, 2006 at 11:21 UTC
    Hi Thanks for your suggestion. But what i need is the program while reading the config file doesn't +take the lines that is started with hash and i can store the elements + from ITEM NO:1 [aaa] 111 [bbb] 222 [ccc] 333 in an array and send that array as an argumnet during the calling of a + sub routine which present in another module and when that sub return +s 1 to the main program then it stores ITEM NO:2 [ddd] 444 [eee] 555 [fff] 666 in an array and send it as the argument during the sub routine call. W +hen that sub returns 1 it stores the ITEM NO:3 .. .. .. in an array and send it and so on. When there is no ITEM NO remains then the program exits.
      Hi Thanks for your suggestion. But what i need is the program while reading the config file doesn't +take the lines that is started with hash and i can store the elements
      1. Please use <code> tags for... ehm... code, or other preformatted text, I see a strange style of mixing actual text with code from your previous post which I can't understand and which I find to be extremely annoying. And I'm quite sure others will share this feeling;
      2. you asked this sub-question three times. Please don't! You're clearly not a native English speaker (neither am I), thus I suggest you to avoid multiple posts and cope with your lack of language skills by trying to write more carefully single ones;
      3. on to the question... (removing <code> tags!)
      in an array and send that array as an argumnet during the calling of a sub routine which present in another module and when that sub returns 1 to the main program then it stores

      If I understand correctly, people have just shown you how to parse some input file into a structure that happens to be an @array (of arrays, but that shouldn't make a difference). Now you seem to want this array to be passed to some_routine() in Some::Module. Then one may want to know what kind of arguments that sub accepts: assuming just a list, then

      my @output=Some::Module::some_routine(@array); # or my @output=some_routine(@array); if exported

      should do. Which specific kind of difficulties are you having with that?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2015-07-31 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls