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, 11: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-16-2005, 12:00 AM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
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, 05: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 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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:08 PM.

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