LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-16-2007, 11:17 AM   #1
ceha
LQ Newbie
 
Registered: Nov 2007
Posts: 1

Rep: Reputation: 0
? marks in directiory name using perl


Hi all,

I am not some perl specialist and I have following code

#!/usr/bin/perl -w


print ( "Enter the name of new directory\n");

$dir=<stdin>;

mkdir ("$dir",0777);
chdir ("$dir");

print (" New directory is created and has name $dir\n");

print (" Enter the name of new file\n");

$name=<stdin>;

open ( $name, ">$name" );

print ("The fajl is opened and has name $name\n");



and it open directory and file file inside it....but in directory name there is tailing ? mark

like this:

directory_name?

Does anybody know what cause behaviour like this.
I really do not need tailing ? in directory name

Thanks in advance...
 
Old 11-16-2007, 03:07 PM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

I am no good at all with Perl, but I think it's because when you read from stdin, the newline you press is included in the $name variable. Try adding "chomp($name)" after you have read it from stdin. This will remove the trailing \n.
 
Old 11-17-2007, 08:23 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As guttorm said, remove the trailing '\n' from the dir (and file) names.
Also, do NOT assume those operations work check the rtn status eg

mkdir($dir) or die "mkdir $dir failed: $!\n";

and so on ...
 
  


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
VI marks in Xemacs ministre Linux - Software 1 02-27-2007 10:15 AM
no quotation marks jdoe9898 Linux - Newbie 1 10-12-2005 03:07 AM
quotaion marks timainge Linux - Newbie 8 05-01-2004 11:06 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
what does you directiory look like? shanenin Linux - Software 1 09-26-2003 03:45 PM

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

All times are GMT -5. The time now is 08:30 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