Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: reading scalars from text file

by mrbbking (Hermit)
on May 16, 2002 at 16:38 UTC ( #167047=note: print w/ replies, xml ) Need Help??


in reply to reading scalars from text file

Your @Variables is an array, each element of which is a line in the file. That's what the diamond operator gives you in list context.

So, $Variables[3] is the whole fourth line from the file called 'variables.dat'. That's not what you want. You're looking for the fourth *field* in whichever line. (I'm assuming those are tab-separated valued, BTW...)

Without resorting to DBD::CSV or Text::CSV_XS (which may or may not be the best idea in your case), you can do it like this, after the code you posted in the root node:

foreach ( @Variables ){ my $user_id = ''; my @elements = split /\t/; my $user_name = $elements[3]; # do something wonderful with $user_name; }


Comment on Re: reading scalars from text file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-07-03 00:18 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 (47 votes), past polls