CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
open filename with special char

 



orange
User

Feb 22, 2016, 12:05 PM

Post #1 of 5 (1461 views)
open filename with special char Can't Post

I'm trying to open $filename which contains '&'
but all I get is:

sh: 1: fname: not found

:(
can someone please help?
thanks.


BillKSmith
Veteran

Feb 22, 2016, 2:21 PM

Post #2 of 5 (1452 views)
Re: [orange] open filename with special char [In reply to] Can't Post

Please show a complete example which demonstrates your problem. I cannot duplicate it with perl v5.20.2 on windows 7.

Code
use strict; 
use warnings;

open my $EXAMPLE, '>', 'B&B.txt' or die "Cannot open example for output:$!";
print {$EXAMPLE} "Any old text\n";
close $EXAMPLE;
open $EXAMPLE, '<', 'B&B.txt' or die "Cannot open example for input:$!";
my $input = <$EXAMPLE>;
if ($input eq "Any old text\n") {
print "Read was successful\n";
}
else {
print "Could not read test\n";
}
close $EXAMPLE;
unlink "B&B.txt";

Good Luck,
Bill


Laurent_R
Veteran / Moderator

Feb 22, 2016, 3:17 PM

Post #3 of 5 (1446 views)
Re: [orange] open filename with special char [In reply to] Can't Post

In addition to what Bill said, I was also able to write to a 'B&B.txt' file under Unix, although checking the content of it within the bash shell required a special syntax: cat 'B$B.txt'.

Please provide details about your operating system and show your code.


FishMonger
Veteran / Moderator

Feb 22, 2016, 3:27 PM

Post #4 of 5 (1446 views)
Re: [orange] open filename with special char [In reply to] Can't Post

That's a shell error message, not perl.

Post your script and show us how you executed it.


orange
User

Feb 22, 2016, 8:12 PM

Post #5 of 5 (1439 views)
Re: [FishMonger] open filename with special char [In reply to] Can't Post

solved, you are right it was a shell error, I should have used
$cmd0=`7z l "$file"`
instead of
$cmd0=`7z l $file`
sorry.

thanks all.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives