LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2008, 10:26 AM   #1
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Rep: Reputation: 15
Exclamation weird error with perl in Linux


This seems to be an weird error to me although it could be a problem where I am just missing something. Below I have the error and the piece of code it is talking about. Can someone see what I did wrong?



The error is:

Can't modify subtraction (-) in scalar assignment at ./<script name> line 32, near "};"
Execution of ./<script name> aborted due to compilation errors.





The code is :
$f = "PCOUNTER_" . $yr . "_$mo.LOG";
$h = "Print Charges for $mon[$mo], $yr";

print "$h\nFilename: $f\n";

cp $home/smb/testing/DATA/$f /logs-testing-Staff/

********************* area where the error seems to appear **********
$home = $ENV{"HOME"};
unless ($home) {
$home = "/home/print";
}
**************** end area ***************
 
Old 04-10-2008, 10:31 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well that's a bash cp command, not a perl one. try to stick to one language at a time!

use File::Copy cp;
cp("file1","file2");
 
Old 04-10-2008, 10:51 AM   #3
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
got it however when I type:

copy("$home/smb/testing/DATA/$f", "$home/logs-testing-Staff/") or die "File cannot be copied.";

I get:

File cannot be copied. at ./<script name> line 27.

I also had to put in "use File::Copy;"

any idea?
 
Old 04-10-2008, 11:00 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well no, i've no idea if that's meant to work or not, i know nothing about your filesystem. if that's *ALL* the code you have then $home hasn't been initialized yet maybe?
 
Old 04-10-2008, 12:41 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by HyperTrey View Post
got it however when I type:

copy("$home/smb/testing/DATA/$f", "$home/logs-testing-Staff/") or die "File cannot be copied.";

I get:

File cannot be copied. at ./<script name> line 27.

I also had to put in "use File::Copy;"

any idea?
The $HOME variable is defined within your shell. You'll either have to use environment variables within your Perl code, define it on the command line, or hard-code it.

Export (or make sure it's set), whatever environment variable you want. Then, your Perl script can use the %ENV hash to read these in. If you've exported FOO="/tmp/test", $ENV{FOO} will have the value "/tmp/test" for your program later on down.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird Perl error with "Inappropriate ioctl for device" bnutting Programming 9 03-12-2012 07:25 AM
Weird error when installing Linux...HELP! rknetsch Linux - Laptop and Netbook 2 06-10-2005 11:09 AM
weird behaviour with hashes in perl weird_guy Programming 0 06-22-2004 09:51 PM
Weird Linux error wolfe bane Linux - Newbie 8 03-08-2004 08:04 AM
Weird Perl Error HappyDude Programming 3 08-04-2003 12:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration