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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variable within system() command

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Folks,

again Perl is driving me mad ... :-(

I got the following:

Code:
#!/usr/bin/perl

$file1=`ls /path/*.txt`  # Note: There's only one file existing in the
                           directory, but the name might change.

system("echo \"Your file is called: $file1 \"");

So far everything is working fine and the output says:

Code:
Your file is called: /path/list1.txt

However if I try to do something with the file it fails:

Code:
#!/usr/bin/perl

$file1=`ls /path/*.txt`

system("mv $file1 /otherpath/oldlist.tmp");

# Note: I even tried masking the $ using \$file1 or something like '$file1' or \'$file1\' or \'\$file1\' or whatever possibility came to my mind ... No chance ...

Where's my mistake ??

Best Regards,
Thomas
 
Oh my !!!
It just hit me like a hammer ....

I forgot to chomp !!!

Code:
chomp ($file1);

And everything is working fine ...
Hate those new line issues ! ;-)
 
Watch out for multiple *.txt files under /path. Perhaps consider using the glob() function in a loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top