parsing a file
From: Susan Lam (susanzlam_at_yahoo.com)
Date: 02/27/05
- Next message: Jon Lapham: "Re: parsing a file"
- Previous message: Steven Lembark: "Re: elegent way to handle "pluggable" backend servers?"
- Next in thread: Jon Lapham: "Re: parsing a file"
- Reply: Jon Lapham: "Re: parsing a file"
- Maybe reply: Laurie Vien: "RE: parsing a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Feb 2005 05:24:11 -0800 (PST) To: dbi-users@perl.org
Hi,
The subroutine below reads a file and assigns values
to variables. It ran fine with the following input
file, file1. However, if I add '#' to the file in the
first couple of lines (file2), it errored.
How can I modify my subroutine to parse file2 by
skipping those '#'?
file1:
userid=apps
userpwd=appspwd
database=mydb
file2:
#
# Usage: <variable>=<value>
#
userid=apps
userpwd=appspwd
database=mydb
sub mysub {
open(PFILE,$ARGV[0]) || die ("Could not open
file");
@pf=<PFILE>;
foreach $param (@pf) {
chop($param);
my ($pname,$pval)=split(/=/,$param);
$ary{$pname}=$pval;
}
close(PFILE);
}
thanks.
susan
__________________________________
Do you Yahoo!?
Yahoo! Sports - Sign up for Fantasy Baseball.
http://baseball.fantasysports.yahoo.com/
- Next message: Jon Lapham: "Re: parsing a file"
- Previous message: Steven Lembark: "Re: elegent way to handle "pluggable" backend servers?"
- Next in thread: Jon Lapham: "Re: parsing a file"
- Reply: Jon Lapham: "Re: parsing a file"
- Maybe reply: Laurie Vien: "RE: parsing a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|