Hi,
Im hopeless at perl and desperately need some help. I need my program to take two arguments at execution. It needs to open the file named as the second argument, read it line by line splitting the each line at the colon and checking the left hand side of the split for any instances of the first argument. If it finds it, it prints it out.
This is what ive got so far:
(the name of the file it checks through is called groupinfo)
#!/usr/local/bin/perl
%groupinfo
open(IN, "groupinfo") or die "Can't open groupinfo: $!";
while (<IN>) {
chomp($line);
($name, $desc) = split /:/, $line;
if (/$line/){
$groupinfo{$name} = $desc;
}
}
print "%desc";
i cant even get it to compile and have no idea what im doing wrong.
e.g
so say if groupinfo looks like this:-
aaaa:bbbb
cccc:dddd
and you run it:-
[xxx]$ perl groupinfo.pl aaaa groupinfo
it will print:-
bbbb
Any help would be appreciated, thanks.
20040421 Edit by BazB: Changed title from 'need help with perl'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.