[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Single vs. Double Quotes
From: |
Rik |
Subject: |
Re: Single vs. Double Quotes |
Date: |
Sat, 15 Oct 2011 10:36:16 -0700 |
On 10/15/2011 04:01 AM, address@hidden wrote:
> Date: Sat, 15 Oct 2011 11:01:11 +0100
> From: Michael Goffioul <address@hidden>
> To: Octave Maintainers List <address@hidden>
> Subject: Compatibility problem with strread and \n delimiter
> Message-ID:
> <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> While testing mirone with QtHandles, I found an issue with strread and
> \n delimiter,
> when the delimiter is double-quoted or single-quoted. It boils down to
> the following:
>
> octave-qt.exe:5> strread(sprintf('1\n2\n3'), '%d', 'delimiter', '\n')
> ans = 123
> octave-qt.exe:6> strread(sprintf('1\n2\n3'), '%d', 'delimiter', "\n")
> ans =
>
> 1
> 2
> 3
>
> As ML doesn't have double-quoted strings, only the first form is valid, but
> from
> what I can see from mirone code, it looks like in ML, the first form
> actually gives
> the second result. Can anybody confirm? Do we want to change this in octave?
Ugh. No. Every other reasonable lexical interpreter (Bourne shell, C
shell, Perl, Python, etc.) makes a distinction between single and double
quotes. A double quoted string is interpreted such that special escape
sequences like "\n" are translated into the actual character(s) the
sequence represents. In this case, "\n" becomes newline which may be a
carriage return, CR, line feed, LF, or CRLF depending on platform. On the
other hand, sometimes you don't want such interpretation if you are
actually looking for the '\' character. The single quotes turn off
interpretation and makes this possible. For example, a directory on a
Windows machine is much easier to type as
dir = 'C:\home\joe\octave\src';
rather than
dir = "c:\\home\\joe\\octave\\src";
It appears that Matlab always uses interpreting quotes even though they
have used the character that every other interpreter has chosen to mean
non-interpreting quote.
Maybe this could be programmed into Octave as an option, to switch on the
fly between treating single quotes as double quotes, but I have my doubts.
Many .m files within Octave are already programmed assuming this
distinction exists. I suppose it could be possible to have Octave do the
equivalent of regexptranslate() for each single quoted string and then pass
that result through the ordinary string interpreter.
At least in this instance why not convert the Matlab script over to Octave
quoting syntax by changing the single quotes into double quotes. The
command below will have Perl do the conversion and leave you a backup named
filename.bak.
<At the shell command line>
perl -i.bak -pe 's/'/"/g' filename
Cheers,
Rik
- Re: Single vs. Double Quotes,
Rik <=
- Re: Single vs. Double Quotes, Michael Goffioul, 2011/10/15
- Re: Single vs. Double Quotes, John W. Eaton, 2011/10/15
- Re: Single vs. Double Quotes, Michael Goffioul, 2011/10/15
- Re: Single vs. Double Quotes, John W. Eaton, 2011/10/15
- Re: Single vs. Double Quotes, Ben Abbott, 2011/10/16
- Re: Single vs. Double Quotes, Rik, 2011/10/16
- Re: Single vs. Double Quotes, Ben Abbott, 2011/10/16
- Re: Single vs. Double Quotes, John W. Eaton, 2011/10/17
- Re: Single vs. Double Quotes, Ben Abbott, 2011/10/17
- Re: Single vs. Double Quotes, John W. Eaton, 2011/10/17