Quick hack to fix it:
#!/usr/bin/perl -w use strict; use Data::Dumper; my %alllines; # hash: line => (arbitrary value) my @enabled_lines; # array: flat list while (<DATA>) { next if /^\s*#/; # may as well skip commented out lines chomp; # not testing with defined as '0' couldn't be a valid url. my ($data) = /([^\s#]+)/; # this $alllines{$data} = 1 if $data; # works my ($enabled) = /([^#]+)#/; # this push @enabled_lines, trim($enabled) if $enabled; # does +n't work } print Dumper(\%alllines); print Dumper(\@enabled_lines); sub trim { $_ = shift; s/^\s+//; s/\s+$//; return $_; } __DATA__ astandardline #acommentedoutline # alinewithspacesbeforeandafterthecommentcharacter therealdata # a subordinate comment, this contains whitespa +ce as it should be ignored linewherethetabsshouldbeignored alinewith # multiple # comment # characters
Basically, I skip lines that start with comments and no data. I also assume that all sharps (#) in URIs will be encoded as %23. That's the only reason why the $enable regex works. Also, rather than try to complicate that regex, I created an easy to read trim() function to deal with the excess white space.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: parsing comments in newline-delimited files as lists
by Ovid
in thread parsing comments in newline-delimited files as lists
by Amoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |