parsing a file

From: Susan Lam (susanzlam_at_yahoo.com)
Date: 02/27/05


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/



Relevant Pages

  • [HPADM] script question
    ... Get a list of ip addresses from the file1 and call the new file as file2 ... do a nslookup on the content of file2 and create a file called file3 ... Try the all-new Yahoo! ...
    (HP-UX-Admin)
  • Re: simple ln question
    ... that makes it so the contents of file1 are the same as of file2, and if you change the contents of 1, the other ... prints the inode number for the file foobar. ...
    (Fedora)
  • RE: data conundrum
    ... in your spens you'll want to keep field names consistent. ... the specs will be the most tedious, but once theyr're done once they're done. ... in other words, you have file1, file2, file3..... ...
    (microsoft.public.access.externaldata)
  • RE: data conundrum
    ... let's say file1 looks like this: ... and let's say file2 looks like this: ... then you will probably have to create import specs for all 100 ... create from the .csv files) as opposed to using a form, ...
    (microsoft.public.access.externaldata)
  • Re: Need Help
    ... eg: file1, file2, file3 etc ... into, max 5-6, chunk files and then loading these chunk files into ...
    (comp.unix.shell)