Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-15-2005, 10:25 PM   #1
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


print "enter target: ";
$target = <STDIN>;
print "\n\n";
print "enter iterations: ";
$i = <STDIN>;
system("shred -fuvxz -n".$i." ".$target);
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...
 system ("time shred -fuvxz -n25 ".$target);

thanks in advance,
Old 01-15-2005, 11:00 PM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,274

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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).

Old 01-16-2005, 04:52 PM   #3
Registered: Feb 2003
Location: Hawaii
Distribution: Debian
Posts: 130

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

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


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

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

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