in reply to File Handling problem

"when i do perl1.pl filename.txt i get the error ...."

What exactly are you "do"ing... and what it your current working directory when you do it?

Assuming from what you've provided that you're using some version of Windows, we still don't know for sure where and how you're executing the script:

  1. C:\Users\Girish\Desktop>perl1.pl filename.txt
  2. C:\>perl1.pl filename.txt
  3. C:\Documents and Settings\>perl perl1.pl filename.txt
  4. or, perhaps even from your file manager or somesuch?

In that last case, $ARGV[0] will almost certainly be undef and might, therefore, account for something somewhat similar to the error message you've cited.

The error you quote in your narrative appears to be inexact (or the script you posted is incomplete). There is no line 10 in the script you posted and unless you saved your script and the router file to the desktop (BAAAAD idea), the error message bears no obvious relationship to the rest of the information you've provided.

IOW, we'll be better able to offer reasonable help if you tell us what's really in the code and what's really happening.

As to what you did to solve " the problem by using"

open (FH_SECOND,"<",\$second_file) or die $!;

...yes, that should solve at least one problem. The less_than sign tells your program to open $second_file for READING; your previous iteration (inside the code block, using a greater_than sign tells the script to open it for WRITING.

Update: Fixed my errors in the pseudo-CLI list.