Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to input variable value from a file?

by wind (Priest)
on Jun 09, 2011 at 18:54 UTC ( [id://908982]=note: print w/replies, xml ) Need Help??


in reply to How to input variable value from a file?

Assuming the data file is delimited with spaces like so:
servername-001 imm-servername-001.companyname.com servername-002 imm-servername-002.companyname.com
Then the following would work:
open my $fh, $serverfile or die "Can't open $serverfile: $!"; my @services = map {chomp; [split]} <$fh>; close $fh;

Replies are listed 'Best First'.
Re^2: How to input variable value from a file?
by perl_newbie99 (Initiate) on Jun 09, 2011 at 20:19 UTC
    Hi Wind, Thanks.. it worked (except for a minor fix). Thanks again! :)
    #open my $fh, $serverfile or die "Can't open $serverfile: $!"; open my $fh, "serverfile" or die "Can't open $serverfile: $!"; my @services = map {chomp; [split]} <$fh>; close $fh;

      You just need to initialize the variable.

      Don't forget use strict; and use warnings at the top of every script.

      use strict; use warnings; my $serverfile = 'foo.bar';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-24 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found