Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Save first n values from a file

by pvaldes (Chaplain)
on Jan 12, 2014 at 15:19 UTC ( [id://1070339]=note: print w/replies, xml ) Need Help??


in reply to Save first n values from a file

use strict; use warnings; my @foo = (); while (<DATA>){ chomp; if ($. < 4){push @foo, $_}} print "my first variable is $foo[0]"; print "my second variable is $foo[1]"; print "my third variable is $foo[2]"; __DATA__ one two a beautiful tree, maybe an oak?

no need to read after "n lines"

And you can add also a fifth line to rename your variables and that's all:

 my ($ball,$dog,$bird) = ($fo[1],$fo[2],$fo[0]);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found