CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [AndrewF] Need help printing out only certain items in a file: Edit Log



Laurent_R
Veteran / Moderator

Jul 7, 2013, 2:09 AM


Views: 500
Re: [AndrewF] Need help printing out only certain items in a file

This session under the Perl debugger shows another possible way to do what you need:


Code
  DB<1>  $c = "Microsoft|MSFT|UN|85 " 

DB<2> push @d, [(split /\|/, $c)[1,2]]

DB<3> $c = "Oracle|ORCL|UN|10.0"

DB<4> push @d, [(split /\|/, $c)[1,2]]

DB<5> x @d
0 ARRAY(0x80359bd0)
0 'MSFT'
1 'UN'
1 ARRAY(0x80356018)
0 'ORCL'
1 'UN'
DB<6> print "$_->[0]\n" for @d
MSFT
ORCL

DB<7> print "$_->[1]\n" for @d
UN
UN


Looking back at your original requirement, this solution does not really create the two arrays (it will create an array of n arrays if the file has n lines). So, if you really need to create these arrays you can add one line to create it and then print the newly created array:

Code
  DB<8> @f = map {$_->[0]} @d 

DB<9> x @f
0 'MSFT'
1 'ORCL'
DB<10> print join "\n", @f
MSFT
ORCL



(This post was edited by Laurent_R on Jul 7, 2013, 2:10 AM)


Edit Log:
Post edited by Laurent_R (Veteran) on Jul 7, 2013, 2:10 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives