Hello
mrityunjaynath,
Welcome to the monastery. It's good that you have posted code but it's currently unreadable. Can you enclose them between <CODE></CODE> tags?
There are several problems with your code:
- You're creating variables that are not used anywhere - this is perfectly fine if you're debugging things, but it doesn't look logically structured in production code (or code used by someone other than you)
- I see this convention of if(open($filehandle, "filename") || die $!) - this is really odd style. This means that whatever happens, straight or exceptional flow, go ahead an process this file. So you can see that it'll lead you down into errors. The general convention here is:
open(my $fh, "filename.txt") or die "Couldn't open file:", $!;. See open - use 3-arg open form.
- In the above point, note that I have used lexical filehandles rather than barewords. It's good form to use lexical filehandles.
- File handles are scarce resources in some operating systems. Windows itself imposes a rather low limit on the number of open file handles. You should close file handles as soon as you're done processing them
- Don't do $var ne "". Perl recognises non-defined values as false - so you can do: if(defined($var)) if you really need to check definedness (see defined) or just if($var), for a negative check: unless($var)
Broadly speaking, you should logically structure your code - writing code is also a form of expression. You're expressing your thoughts to a dumb servant and it's very finicky about instructions. Otherwise, it's a lot of fun. It's also a good thing that perl itself comes with a lot of documentation. Keep referring to it, start from perlintro and continue on your path. Post here if you get stuck. Good luck!
Enjoy.
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.