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

Re: How to create array from file

by Corion (Patriarch)
on Jan 20, 2017 at 12:14 UTC ( [id://1179991]=note: print w/replies, xml ) Need Help??


in reply to How to create array from file

Your intended output format makes little sense at first glance. Maybe you really want to use Text::CSV_XS to read in comma-separated files into arrays?

If you really, really want to read a file into an array of arrayrefs all of which contain only one element, see open, and readline.

You can help us give you more appropriate advice by showing us what code you have already written and what input data you give it and how your code fails to do what it should.

Replies are listed 'Best First'.
Re^2: How to create array from file
by Mjpaddy (Acolyte) on Jan 20, 2017 at 12:25 UTC

    Hi Corion, I edit my question with code please suggest out to get that output.

      If you really, really want single-element arrayrefs, don't push the string, but push an array reference containing the string:

      while(<FH>){ chomp $_; push(@data,[$_]); }

      But really, reconsider using Text::CSV_XS instead, because soon you will want to split up that string on commas whitespace using split and then you'll find that Text::CSV_XS is much better. Also see perldsc on data structures maybe.

      Upon reading chorobas reply, I see that I completely forgot about quoting the other parts on output. Oh well.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-28 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found