LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-15-2005, 11:25 PM   #1
randomx
Member
 
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130

Rep: Reputation: 16
PERL: concatenation of variables issue


Hi, I'm learning perl ...

Problem: concatenation not done right. Please help me out.

Objective: user enters target file and number of iterations to shred a file

Code:
#/usr/bin/perl

print "enter target: ";
$target = <STDIN>;
print "\n\n";
print "enter iterations: ";
$i = <STDIN>;
                                                                                
system("shred -fuvxz -n".$i." ".$target);
error:
shred: missing file argument
Try `shred --help' for more information.

No errors when executed without the iterations part ...that's why I think it's a concatenation problem...I just don't know better.

like this...
Code:
 system ("time shred -fuvxz -n25 ".$target);

thanks in advance,
 
Old 01-16-2005, 12:00 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,158

Rep: Reputation: 328Reputation: 328Reputation: 328Reputation: 328
A couple of points:

(1) no need to put $i and $target outside the double quotes. Only single quotes prevent expansion of variables.
(2) You need to cut the newlines off the stuff from <STDIN> ... the chomp function can do this for you (read its documentation). This is the source of your problem, the shell called up by system thinks that the command ends after -i<whatever> because $i actually has the imput plus the newline (inserted when the user presses enter).

HTH.
 
Old 01-16-2005, 05:52 PM   #3
randomx
Member
 
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130

Original Poster
Rep: Reputation: 16
got it...it's working now..thanks.

this is basically it...
Code:
chomp($target = <STDIN>);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to use session variables in perl ? taqs Programming 1 09-28-2004 07:12 PM
Environment variables and perl jrbiochem Linux - General 0 05-06-2004 10:40 AM
exporting variables in Perl nbp Programming 1 11-18-2003 09:35 AM
Perl variables nbp Programming 2 11-02-2003 10:33 AM
Environment variables Perl nbp Programming 1 10-28-2003 09:49 AM


All times are GMT -5. The time now is 04:38 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration