Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New perl script

Status
Not open for further replies.

COTLG

Technical User
Apr 15, 2003
107
US
Hi All,
I am new to perl. I wrote this simple script but on running it ./xxx it does not bring out any output on the stdout.

Please what's wrong?

#!/usr/bin/perl
$shadow_file="local/scripts/test_shadow";
open(SHADOW, $shadow_file);
@array_data=<SHADOW>;
print @array_data;
close (SHADOW);
foreach $column (@array_data)
{chop ($column);
($column1, $column2)=split(/:/, $column);
print "$column1, $column2";
}

Regards,
Chike.
 
try

Code:
#!/usr/bin/perl
$shadow_file="local/scripts/test_shadow";
if (open(SHADOW, $shadow_file)) {
@array_data=<SHADOW>;
print @array_data;
close (SHADOW);
foreach $column (@array_data)
{chop ($column);
($column1, $column2)=split(/:/, $column);
print "$column1, $column2";
}
} else {
print "Could not open file\n";
}
 
Or just change your open statement:
open(SHADOW, $shadow_file) || die qq(Can't open "$shadow_file"!\n);
 
Thanks All,

It actually could not open the file. So what do I do now? I have changed the file permissions to 777, still the same result. The file is owned by root and the group is root as well.

Regards,
Chike.
 
Your $shadow_file does not have a fully-qualified path, so the place it looks for the file will change relative to your current directory when you run the script.

Steve
 
I just discovered the error. Insetad of typing /local/... I typed local/...

Thanks for your contributions.

Regards,
Chike.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top